Repository: FairwindsOps/polaris
Pull request #586 (2021-07-13 21:43:22)

Fixed repeated names on dashboard

CLAassistant: [![CLA assistant check](https://cla-assistant.io/pull/badge/not_signed)](https://cla-assistant.io/FairwindsOps/polaris?pullRequest=586) <br/>Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our [Contributor License Agreement](https://cla-assistant.io/FairwindsOps/polaris?pullRequest=586) before we can accept your contribution.<br/><sub>You have signed the CLA already but the status is still pending? Let us [recheck](https://cla-assistant.io/check/FairwindsOps/polaris?pullRequest=586) it.</sub>

Patch:
diff --git a/pkg/kube/resource.go b/pkg/kube/resource.go
index 427c6265..a0aee41c 100644
--- a/pkg/kube/resource.go
+++ b/pkg/kube/resource.go
@@ -25,24 +25,23 @@ type GenericResource struct {
 }
 
 // NewGenericResourceFromUnstructured creates a workload from an unstructured.Unstructured
-func NewGenericResourceFromUnstructured(unst *unstructured.Unstructured) (GenericResource, error) {
+func NewGenericResourceFromUnstructured(unst unstructured.Unstructured) (GenericResource, error) {
 	workload := GenericResource{
 		Kind:     unst.GetKind(),
-		Resource: *unst,
+		Resource: unst,
 	}
 
-	objMeta, err := meta.Accessor(unst)
+	objMeta, err := meta.Accessor(&unst)
 	if err != nil {
 		return workload, err
 	}
 	workload.ObjectMeta = objMeta
 
-	b, err := json.Marshal(unst)
+	b, err := json.Marshal(&unst)
 	if err != nil {
 		return workload, err
 	}
 	workload.OriginalObjectJSON = b
-
 	m := make(map[string]interface{})
 	err = json.Unmarshal(b, &m)
 	if err != nil {
@@ -61,7 +60,6 @@ func NewGenericResourceFromUnstructured(unst *unstructured.Unstructured) (Generi
 		}
 		workload.PodSpec = &podSpec
 	}
-
 	return workload, nil
 }
 
@@ -101,7 +99,7 @@ func NewGenericResourceFromBytes(contentBytes []byte) (GenericResource, error) {
 	if err != nil {
 		return GenericResource{}, err
 	}
-	return NewGenericResourceFromUnstructured(&unst)
+	return NewGenericResourceFromUnstructured(unst)
 }
 
 // ResolveControllerFromPod builds a new workload for a given Pod
@@ -161,7 +159,7 @@ func resolveControllerFromPod(ctx context.Context, podResource kubeAPICoreV1.Pod
 
 	if lastKey != "" {
 		unst := objectCache[lastKey]
-		return NewGenericResourceFromUnstructured(&unst)
+		return NewGenericResourceFromUnstructured(unst)
 	}
 	workload, err := NewGenericResourceFromPod(podResource, podResource)
 	if err != nil {
diff --git a/pkg/kube/resources.go b/pkg/kube/resources.go
index 5c86ba4c..97903cab 100644
--- a/pkg/kube/resources.go
+++ b/pkg/kube/resources.go
@@ -168,7 +168,7 @@ func CreateResourceProviderFromResource(ctx context.Context, workload string) (*
 		logrus.Errorf("Could not find workload %s: %v", workload, err)
 		return nil, err
 	}
-	workloadObj, err := NewGenericResourceFromUnstructured(obj)
+	workloadObj, err := NewGenericResourceFromUnstructured(*obj)
 	if err != nil {
 		logrus.Errorf("Could not parse workload %s: %v", workload, err)
 		return nil, err
@@ -298,7 +298,7 @@ func CreateResourceProviderFromAPI(ctx context.Context, kube kubernetes.Interfac
 			return nil, err
 		}
 		for _, obj := range objects.Items {
-			res, err := NewGenericResourceFromUnstructured(&obj)
+			res, err := NewGenericResourceFromUnstructured(obj)
 			if err != nil {
 				return nil, err
 			}


Test patch:
diff --git a/pkg/validator/arbitrary_test.go b/pkg/validator/arbitrary_test.go
index e0b321f3..2724fb09 100644
--- a/pkg/validator/arbitrary_test.go
+++ b/pkg/validator/arbitrary_test.go
@@ -33,7 +33,7 @@ func TestValidatePDB(t *testing.T) {
 		},
 	}
 	pdb := unstructured.Unstructured{}
-	res, err := kube.NewGenericResourceFromUnstructured(&pdb)
+	res, err := kube.NewGenericResourceFromUnstructured(pdb)
 	res.Kind = "PodDisruptionBudget"
 
 	actualResult, err := applyNonControllerSchemaChecks(&c, nil, res)
@@ -70,7 +70,7 @@ func TestValidateIngress(t *testing.T) {
 	if err != nil {
 		panic(err)
 	}
-	res, err := kube.NewGenericResourceFromUnstructured(&unst)
+	res, err := kube.NewGenericResourceFromUnstructured(unst)
 	if err != nil {
 		panic(err)
 	}