Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for finalizers in application resource #159

Merged
merged 1 commit into from
Jun 12, 2024
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
3 changes: 3 additions & 0 deletions apis/applications/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ type ApplicationParameters struct {

// Annotations that will be applied to the ArgoCD Application
Annotations map[string]string `json:"annotations,omitempty" protobuf:"bytes,12,opt,name=annotations"`

// Finalizers added to the ArgoCD Application
Finalizers []string `json:"finalizers,omitempty" protobuf:"bytes,13,opt,name=finalizers"`
}

// ResourceIgnoreDifferences contains resource filter and list of json paths which should be ignored during comparison with live state.
Expand Down
5 changes: 5 additions & 0 deletions apis/applications/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions examples/application/application-with-finalizers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
# Example using finalizers
apiVersion: applications.argocd.crossplane.io/v1alpha1
kind: Application
metadata:
name: example-application-finalizers
spec:
providerConfigRef:
name: argocd-provider
forProvider:
finalizers:
- resources-finalizer.argocd.argoproj.io
destination:
namespace: default
server: https://kubernetes.default.svc
project: default
source:
repoURL: https://github.com/bonilla-cesar/argocd
path: resources/cm
targetRevision: HEAD



Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ spec:
type: object
type: object
type: object
finalizers:
description: Finalizers added to the ArgoCD Application
items:
type: string
type: array
ignoreDifferences:
description: IgnoreDifferences is a list of resources and their
fields which should be ignored during comparison
Expand Down
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...)

// 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: 2 additions & 0 deletions pkg/controller/applications/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ func generateCreateApplicationRequest(cr *v1alpha1.Application) *application.App
ObjectMeta: metav1.ObjectMeta{
Name: meta.GetExternalName(cr),
Annotations: cr.Spec.ForProvider.Annotations,
Finalizers: cr.Spec.ForProvider.Finalizers,
},
Spec: *spec,
}
Expand All @@ -238,6 +239,7 @@ func generateUpdateRepositoryOptions(cr *v1alpha1.Application) *application.Appl
ObjectMeta: metav1.ObjectMeta{
Name: meta.GetExternalName(cr),
Annotations: cr.Spec.ForProvider.Annotations,
Finalizers: cr.Spec.ForProvider.Finalizers,
},
Spec: *spec,
}
Expand Down
13 changes: 12 additions & 1 deletion pkg/controller/applications/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ 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"}
)

type args struct {
Expand Down Expand Up @@ -126,6 +127,7 @@ func TestObserve(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: testApplicationExternalName,
Annotations: testApplicationAnnotations,
Finalizers: testApplicationFinalizers,
},
Spec: argocdv1alpha1.ApplicationSpec{
Project: testProjectName,
Expand Down Expand Up @@ -165,6 +167,7 @@ func TestObserve(t *testing.T) {
},
},
Annotations: testApplicationAnnotations,
Finalizers: testApplicationFinalizers,
}),
),
},
Expand All @@ -187,6 +190,7 @@ func TestObserve(t *testing.T) {
},
},
Annotations: testApplicationAnnotations,
Finalizers: testApplicationFinalizers,
}),
withConditions(xpv1.Available()),
withObservation(initializedArgoAppStatus()),
Expand Down Expand Up @@ -216,6 +220,7 @@ func TestObserve(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: testApplicationExternalName,
Annotations: testApplicationAnnotations,
Finalizers: testApplicationFinalizers,
},
Spec: argocdv1alpha1.ApplicationSpec{
Project: testProjectName,
Expand Down Expand Up @@ -250,6 +255,7 @@ func TestObserve(t *testing.T) {
},
},
Annotations: testApplicationAnnotations,
Finalizers: testApplicationFinalizers,
}),
),
},
Expand All @@ -272,6 +278,7 @@ func TestObserve(t *testing.T) {
},
},
Annotations: testApplicationAnnotations,
Finalizers: testApplicationFinalizers,
}),
withConditions(xpv1.Available()),
withObservation(initializedArgoAppStatus()),
Expand Down Expand Up @@ -505,6 +512,7 @@ func TestUpdate(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: testApplicationExternalName,
Annotations: testApplicationAnnotations,
Finalizers: testApplicationFinalizers,
},
Spec: argocdv1alpha1.ApplicationSpec{
Project: testProjectName,
Expand All @@ -518,6 +526,7 @@ func TestUpdate(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: testApplicationExternalName,
Annotations: testApplicationAnnotations,
Finalizers: testApplicationFinalizers,
},
}, nil)
}),
Expand All @@ -529,6 +538,7 @@ func TestUpdate(t *testing.T) {
Namespace: &testDestinationNamespace,
},
Annotations: testApplicationAnnotations,
Finalizers: testApplicationFinalizers,
}),
withExternalName(testApplicationExternalName),
),
Expand All @@ -542,6 +552,7 @@ func TestUpdate(t *testing.T) {
Namespace: &testDestinationNamespace,
},
Annotations: testApplicationAnnotations,
Finalizers: testApplicationFinalizers,
}),
withExternalName(testApplicationExternalName),
),
Expand Down
Loading