Skip to content

Commit

Permalink
Merge pull request #150 from bonilla-cesar/feat/add-annotations-to-apps
Browse files Browse the repository at this point in the history
feat: add support for annotations in application resource
  • Loading branch information
MisterMX authored Mar 6, 2024
2 parents ad4045a + 60c832a commit ee64725
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 10 deletions.
3 changes: 3 additions & 0 deletions apis/applications/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ type ApplicationParameters struct {

// Sources is a reference to the location of the application's manifests or chart
Sources ApplicationSources `json:"sources,omitempty" protobuf:"bytes,8,opt,name=sources"`

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

// ResourceIgnoreDifferences contains resource filter and list of json paths which should be ignored during comparison with live state.
Expand Down
7 changes: 7 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.

22 changes: 22 additions & 0 deletions examples/application/application-with-annotations.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
# Example using annotations
apiVersion: applications.argocd.crossplane.io/v1alpha1
kind: Application
metadata:
name: example-application-annotations
spec:
providerConfigRef:
name: argocd-provider
forProvider:
annotations:
notifications.argoproj.io/subscribe.on-deployed.slack: slack-channel-name
notifications.argoproj.io/subscribe.on-failure.slack: slack-channel-name
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 @@ -63,6 +63,11 @@ spec:
description: ApplicationParameters define the desired state of an
ArgoCD Git Application
properties:
annotations:
additionalProperties:
type: string
description: Annotations that will be applied to the ArgoCD Application
type: object
destination:
description: Destination is a reference to the target Kubernetes
server and namespace
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/applications/comp.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ 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...)
return cmp.Equal(*cluster, remote.Spec, opts...) && cmp.Equal(cr.Annotations, remote.Annotations, opts...)
}
6 changes: 4 additions & 2 deletions pkg/controller/applications/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ func generateCreateApplicationRequest(cr *v1alpha1.Application) *application.App
app := &argocdv1alpha1.Application{
TypeMeta: metav1.TypeMeta{},
ObjectMeta: metav1.ObjectMeta{
Name: meta.GetExternalName(cr),
Name: meta.GetExternalName(cr),
Annotations: cr.Spec.ForProvider.Annotations,
},
Spec: *spec,
}
Expand All @@ -235,7 +236,8 @@ func generateUpdateRepositoryOptions(cr *v1alpha1.Application) *application.Appl
app := &argocdv1alpha1.Application{
TypeMeta: metav1.TypeMeta{},
ObjectMeta: metav1.ObjectMeta{
Name: meta.GetExternalName(cr),
Name: meta.GetExternalName(cr),
Annotations: cr.Spec.ForProvider.Annotations,
},
Spec: *spec,
}
Expand Down
28 changes: 21 additions & 7 deletions pkg/controller/applications/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var (
chartPath = "charts/podinfo"
revision = "HEAD"
selfHealEnabled = true
testApplicationAnnotations = map[string]string{"annotation1": "value1"}
)

type args struct {
Expand Down Expand Up @@ -123,7 +124,8 @@ func TestObserve(t *testing.T) {
Items: []argocdv1alpha1.Application{{
TypeMeta: metav1.TypeMeta{},
ObjectMeta: metav1.ObjectMeta{
Name: testApplicationExternalName,
Name: testApplicationExternalName,
Annotations: testApplicationAnnotations,
},
Spec: argocdv1alpha1.ApplicationSpec{
Project: testProjectName,
Expand Down Expand Up @@ -162,6 +164,7 @@ func TestObserve(t *testing.T) {
SelfHeal: &selfHealEnabled,
},
},
Annotations: testApplicationAnnotations,
}),
),
},
Expand All @@ -183,6 +186,7 @@ func TestObserve(t *testing.T) {
SelfHeal: &selfHealEnabled,
},
},
Annotations: testApplicationAnnotations,
}),
withConditions(xpv1.Available()),
withObservation(initializedArgoAppStatus()),
Expand Down Expand Up @@ -210,7 +214,8 @@ func TestObserve(t *testing.T) {
Items: []argocdv1alpha1.Application{{
TypeMeta: metav1.TypeMeta{},
ObjectMeta: metav1.ObjectMeta{
Name: testApplicationExternalName,
Name: testApplicationExternalName,
Annotations: testApplicationAnnotations,
},
Spec: argocdv1alpha1.ApplicationSpec{
Project: testProjectName,
Expand Down Expand Up @@ -244,6 +249,7 @@ func TestObserve(t *testing.T) {
SelfHeal: &selfHealEnabled,
},
},
Annotations: testApplicationAnnotations,
}),
),
},
Expand All @@ -265,6 +271,7 @@ func TestObserve(t *testing.T) {
SelfHeal: &selfHealEnabled,
},
},
Annotations: testApplicationAnnotations,
}),
withConditions(xpv1.Available()),
withObservation(initializedArgoAppStatus()),
Expand Down Expand Up @@ -496,7 +503,8 @@ func TestUpdate(t *testing.T) {
&argocdApplication.ApplicationUpdateRequest{
Application: &argocdv1alpha1.Application{
ObjectMeta: metav1.ObjectMeta{
Name: testApplicationExternalName,
Name: testApplicationExternalName,
Annotations: testApplicationAnnotations,
},
Spec: argocdv1alpha1.ApplicationSpec{
Project: testProjectName,
Expand All @@ -508,7 +516,8 @@ func TestUpdate(t *testing.T) {
},
).Return(&argocdv1alpha1.Application{
ObjectMeta: metav1.ObjectMeta{
Name: testApplicationExternalName,
Name: testApplicationExternalName,
Annotations: testApplicationAnnotations,
},
}, nil)
}),
Expand All @@ -519,6 +528,7 @@ func TestUpdate(t *testing.T) {
Destination: v1alpha1.ApplicationDestination{
Namespace: &testDestinationNamespace,
},
Annotations: testApplicationAnnotations,
}),
withExternalName(testApplicationExternalName),
),
Expand All @@ -531,6 +541,7 @@ func TestUpdate(t *testing.T) {
Destination: v1alpha1.ApplicationDestination{
Namespace: &testDestinationNamespace,
},
Annotations: testApplicationAnnotations,
}),
withExternalName(testApplicationExternalName),
),
Expand All @@ -546,7 +557,8 @@ func TestUpdate(t *testing.T) {
&argocdApplication.ApplicationUpdateRequest{
Application: &argocdv1alpha1.Application{
ObjectMeta: metav1.ObjectMeta{
Name: testApplicationExternalName,
Name: testApplicationExternalName,
Annotations: testApplicationAnnotations,
},
Spec: argocdv1alpha1.ApplicationSpec{
Project: testProjectName,
Expand All @@ -557,15 +569,17 @@ func TestUpdate(t *testing.T) {
}),
cr: Application(
withSpec(v1alpha1.ApplicationParameters{
Project: testProjectName,
Project: testProjectName,
Annotations: testApplicationAnnotations,
}),
withExternalName(testApplicationExternalName),
),
},
want: want{
cr: Application(
withSpec(v1alpha1.ApplicationParameters{
Project: testProjectName,
Project: testProjectName,
Annotations: testApplicationAnnotations,
}),
withExternalName(testApplicationExternalName),
),
Expand Down

0 comments on commit ee64725

Please sign in to comment.