Skip to content

Commit

Permalink
Fixed repeated names on dashboard (#586)
Browse files Browse the repository at this point in the history
* Fixed repeated names on dashboard

* Fixed unit test
  • Loading branch information
jdesouza authored Jul 14, 2021
1 parent cd47487 commit 01cc5fa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
14 changes: 6 additions & 8 deletions pkg/kube/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -61,7 +60,6 @@ func NewGenericResourceFromUnstructured(unst *unstructured.Unstructured) (Generi
}
workload.PodSpec = &podSpec
}

return workload, nil
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/kube/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/validator/arbitrary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 01cc5fa

Please sign in to comment.