Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions util/argo/resource_tracking.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"regexp"
"strings"

kubeutil "github.com/argoproj/gitops-engine/pkg/utils/kube"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"

"github.com/argoproj/argo-cd/v3/common"
Expand Down Expand Up @@ -232,6 +233,11 @@ func (rt *resourceTracking) Normalize(config, live *unstructured.Unstructured, l
return nil
}

if kubeutil.IsCRD(live) {
// CRDs don't get tracking annotations.
return nil
}

annotation, err := kube.GetAppInstanceAnnotation(config, common.AnnotationKeyAppInstance)
if err != nil {
return err
Expand Down
44 changes: 44 additions & 0 deletions util/argo/resource_tracking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,50 @@ func TestResourceIdNormalizer_Normalize(t *testing.T) {
assert.False(t, hasOldLabel)
}

func TestResourceIdNormalizer_NormalizeCRD(t *testing.T) {
rt := NewResourceTracking()

// live object is a CRD resource
liveObj := &unstructured.Unstructured{
Object: map[string]any{
"apiVersion": "apiextensions.k8s.io/v1",
"kind": "CustomResourceDefinition",
"metadata": map[string]any{
"name": "crontabs.stable.example.com",
"labels": map[string]any{
common.LabelKeyAppInstance: "my-app",
},
},
"spec": map[string]any{
"group": "stable.example.com",
"scope": "Namespaced",
},
},
}

// config object is a CRD resource
configObj := &unstructured.Unstructured{
Object: map[string]any{
"apiVersion": "apiextensions.k8s.io/v1",
"kind": "CustomResourceDefinition",
"metadata": map[string]any{
"name": "crontabs.stable.example.com",
"labels": map[string]any{
common.LabelKeyAppInstance: "my-app",
},
},
"spec": map[string]any{
"group": "stable.example.com",
"scope": "Namespaced",
},
},
}

require.NoError(t, rt.Normalize(configObj, liveObj, common.LabelKeyAppInstance, string(TrackingMethodAnnotation)))
// the normalization should not apply any changes to the live object
require.NotContains(t, liveObj.GetAnnotations(), common.AnnotationKeyAppInstance)
}

func TestResourceIdNormalizer_Normalize_ConfigHasOldLabel(t *testing.T) {
rt := NewResourceTracking()

Expand Down
Loading