-
Notifications
You must be signed in to change notification settings - Fork 33
/
comp.go
31 lines (24 loc) · 1.19 KB
/
comp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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"
"github.com/crossplane-contrib/provider-argocd/apis/applications/v1alpha1"
"github.com/crossplane-contrib/provider-argocd/pkg/clients/applications"
)
// IsApplicationUpToDate converts ApplicationParameters to its ArgoCD Counterpart and returns if they equal
func IsApplicationUpToDate(cr *v1alpha1.ApplicationParameters, remote *argocdv1alpha1.Application) bool { // nolint:gocyclo
converter := applications.ConverterImpl{}
cluster := converter.ToArgoApplicationSpec(cr)
opts := []cmp.Option{
// explicitly ignore the unexported in this type instead of adding a generic allow on all type.
// the unexported fields should not bother here, since we don't copy them or write them
cmpopts.IgnoreUnexported(argocdv1alpha1.ApplicationDestination{}),
}
// 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)
}