diff --git a/pkg/resource/res.go b/pkg/resource/res.go index 425edc9..69000b6 100644 --- a/pkg/resource/res.go +++ b/pkg/resource/res.go @@ -163,8 +163,7 @@ func MatchResources(desired map[resource.Name]*resource.DesiredComposed, data [] // otherwise we lost something somewhere for _, d := range data { // PatchDesired - name := getName(&d) - if found, ok := desired[resource.Name(name)]; ok { + if found, ok := desired[resource.Name(d.GetName())]; ok { if _, ok := matches[found]; !ok { matches[found] = []map[string]interface{}{d.Object} } else { @@ -250,7 +249,7 @@ func AddResourcesTo(o any, opts *AddResourcesOptions) error { // Resources desired := val for _, d := range opts.Data { - name := resource.Name(getName(&d)) + name := resource.Name(d.GetName()) // If the value exists, merge its existing value with the patches if v, ok := desired[name]; ok { mergedData := merged(d.Object, v) @@ -474,7 +473,10 @@ func ProcessResources(dxr *resource.Composite, oxr *resource.Composite, desired meta.RemoveAnnotations(cd.Resource, AnnotationKeyReady) } // Patch desired with custom name from annotation or default to resource meta name. - name := getName(&cd.Resource.Unstructured) + name, found := cd.Resource.GetAnnotations()[AnnotationKeyCompositionResourceName] + if !found { + name = cd.Resource.GetName() + } meta.RemoveAnnotations(cd.Resource, AnnotationKeyCompositionResourceName) desired[resource.Name(name)] = cd } @@ -486,11 +488,3 @@ func ProcessResources(dxr *resource.Composite, oxr *resource.Composite, desired result.setSuccessMsgs() return result, nil } - -func getName(o *unstructured.Unstructured) string { - name, found := o.GetAnnotations()[AnnotationKeyCompositionResourceName] - if !found { - name = o.GetAPIVersion() + "-" + o.GetKind() + "-" + o.GetNamespace() + "-" + o.GetName() - } - return name -}