Skip to content

Commit

Permalink
use generic slices and map to compare finalizers and annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
amotolani committed Jun 6, 2024
1 parent 1e1b799 commit 0e2c8e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion pkg/controller/applications/comp.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package applications

import (
"maps"
"slices"

argocdv1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
Expand All @@ -19,5 +22,10 @@ func IsApplicationUpToDate(cr *v1alpha1.ApplicationParameters, remote *argocdv1a
// the unexported fields should not bother here, since we don't copy them or write them
cmpopts.IgnoreUnexported(argocdv1alpha1.ApplicationDestination{}),
}
return cmp.Equal(*cluster, remote.Spec, opts...) && cmp.Equal(cr.Annotations, remote.Annotations, opts...) && cmp.Equal(cr.Finalizers, remote.Finalizers, opts...)

// Sort finalizer slices for comparison
slices.Sort(cr.Finalizers)
slices.Sort(remote.Finalizers)

return cmp.Equal(*cluster, remote.Spec, opts...) && maps.Equal(cr.Annotations, remote.Annotations) && slices.Equal(cr.Finalizers, remote.Finalizers)
}
2 changes: 1 addition & 1 deletion pkg/controller/applications/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var (
chartPath = "charts/podinfo"
revision = "HEAD"
selfHealEnabled = true
testApplicationAnnotations = map[string]string{"annotation1": "value1"}
testApplicationAnnotations = map[string]string{"annotation1": "value1", "annotation2": "value2"}
testApplicationFinalizers = []string{"resources-finalizer.argocd.argoproj.io"}
)

Expand Down

0 comments on commit 0e2c8e2

Please sign in to comment.