Skip to content

Commit c212a12

Browse files
feat: Edit annotations for the argocd-server service
1 parent 78563f0 commit c212a12

File tree

9 files changed

+121
-2
lines changed

9 files changed

+121
-2
lines changed

api/v1alpha1/argocd_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,9 @@ type ArgoCDServerServiceSpec struct {
589589
// Type is the ServiceType to use for the Service resource.
590590
//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Service Type",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:fieldGroup:Server","urn:alm:descriptor:com.tectonic.ui:text"}
591591
Type corev1.ServiceType `json:"type"`
592+
593+
// Annotations is the map of annotations to apply to the Server Service.
594+
Annotations map[string]string `json:"annotations,omitempty"`
592595
}
593596

594597
// Resource Customization for custom health check

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta1/argocd_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,9 @@ type ArgoCDServerServiceSpec struct {
745745
// Type is the ServiceType to use for the Service resource.
746746
//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Service Type",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:fieldGroup:Server","urn:alm:descriptor:com.tectonic.ui:text"}
747747
Type corev1.ServiceType `json:"type"`
748+
749+
// Annotations is the map of annotations to apply to the Server Service.
750+
Annotations map[string]string `json:"annotations,omitempty"`
748751
}
749752

750753
// Resource Customization for custom health check

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundle/manifests/argoproj.io_argocds.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8455,6 +8455,12 @@ spec:
84558455
description: Service defines the options for the Service backing
84568456
the ArgoCD Server component.
84578457
properties:
8458+
annotations:
8459+
additionalProperties:
8460+
type: string
8461+
description: Annotations is the map of annotations to apply
8462+
to the Server Service.
8463+
type: object
84588464
type:
84598465
description: Type is the ServiceType to use for the Service
84608466
resource.
@@ -26355,6 +26361,12 @@ spec:
2635526361
description: Service defines the options for the Service backing
2635626362
the ArgoCD Server component.
2635726363
properties:
26364+
annotations:
26365+
additionalProperties:
26366+
type: string
26367+
description: Annotations is the map of annotations to apply
26368+
to the Server Service.
26369+
type: object
2635826370
type:
2635926371
description: Type is the ServiceType to use for the Service
2636026372
resource.

config/crd/bases/argoproj.io_argocds.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8444,6 +8444,12 @@ spec:
84448444
description: Service defines the options for the Service backing
84458445
the ArgoCD Server component.
84468446
properties:
8447+
annotations:
8448+
additionalProperties:
8449+
type: string
8450+
description: Annotations is the map of annotations to apply
8451+
to the Server Service.
8452+
type: object
84478453
type:
84488454
description: Type is the ServiceType to use for the Service
84498455
resource.
@@ -26344,6 +26350,12 @@ spec:
2634426350
description: Service defines the options for the Service backing
2634526351
the ArgoCD Server component.
2634626352
properties:
26353+
annotations:
26354+
additionalProperties:
26355+
type: string
26356+
description: Annotations is the map of annotations to apply
26357+
to the Server Service.
26358+
type: object
2634726359
type:
2634826360
description: Type is the ServiceType to use for the Service
2634926361
resource.

controllers/argocd/service.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,18 @@ func (r *ReconcileArgoCD) reconcileServerService(cr *argoproj.ArgoCD) error {
495495

496496
svc.Spec.Type = getArgoServerServiceType(cr)
497497

498+
// Add annotations if specified without deleteing annotations from `ensureAutoTLSAnnotation()`
499+
if len(cr.Spec.Server.Service.Annotations) > 0 {
500+
if svc.Annotations == nil {
501+
svc.Annotations = make(map[string]string)
502+
svc.Annotations = cr.Spec.Server.Service.Annotations
503+
} else {
504+
for k, v := range cr.Spec.Server.Service.Annotations {
505+
svc.Annotations[k] = v
506+
}
507+
}
508+
}
509+
498510
if err := controllerutil.SetControllerReference(cr, svc, r.Scheme); err != nil {
499511
return err
500512
}
@@ -527,6 +539,14 @@ func (r *ReconcileArgoCD) reconcileServerService(cr *argoproj.ArgoCD) error {
527539
explanation += "service type"
528540
changed = true
529541
}
542+
if !reflect.DeepEqual(svc.Annotations, existingSVC.Annotations) {
543+
existingSVC.Annotations = svc.Annotations
544+
if changed {
545+
explanation += ", "
546+
}
547+
explanation += "service annotations"
548+
changed = true
549+
}
530550
if changed {
531551
argoutil.LogResourceUpdate(log, existingSVC, "updating", explanation)
532552
return r.Update(context.TODO(), existingSVC)

controllers/argocd/service_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,49 @@ func TestReconcileServerService(t *testing.T) {
142142
assert.NoError(t, err)
143143
assert.Equal(t, a.Spec.Server.Service.Type, serverService.Spec.Type)
144144
})
145+
146+
t.Run("Server Service annotations update", func(t *testing.T) {
147+
// Reconcile with previous existing Server Service with a different Annotations
148+
argoutil.SetRouteAPIFound(false)
149+
a.Spec.Server.Service.Annotations = map[string]string{"test.kubernetes.io/test": "test"}
150+
assert.NotEqual(t, a.Spec.Server.Service.Annotations, serverService.Annotations)
151+
152+
err := r.reconcileServerService(a)
153+
assert.NoError(t, err)
154+
155+
// Existing Server is found and has the argoCD new Server Service Annotations
156+
err = r.Get(context.TODO(), types.NamespacedName{
157+
Name: "argocd-server",
158+
Namespace: testNamespace,
159+
}, serverService)
160+
assert.NoError(t, err)
161+
assert.Equal(t, a.Spec.Server.Service.Annotations, serverService.Annotations)
162+
})
163+
t.Run("Server Service annotations update with Openshift auto TLS annotation", func(t *testing.T) {
164+
argoutil.SetRouteAPIFound(true)
165+
166+
testAnnotationKey := "test.kubernetes.io/test"
167+
testAnnotationVal := "test"
168+
a.Spec.Server.Service.Annotations = map[string]string{testAnnotationKey: testAnnotationVal}
169+
170+
err := r.reconcileServerService(a)
171+
assert.NoError(t, err)
172+
173+
// Existing Server is found and has the argoCD new Server Service Type
174+
err = r.Get(context.TODO(), types.NamespacedName{
175+
Name: "argocd-server",
176+
Namespace: testNamespace,
177+
}, serverService)
178+
assert.NoError(t, err)
179+
180+
val, ok := serverService.Annotations[common.AnnotationOpenShiftServiceCA]
181+
assert.Equal(t, ok, true)
182+
assert.Equal(t, val, common.ArgoCDServerTLSSecretName)
183+
184+
val, ok = serverService.Annotations[testAnnotationKey]
185+
assert.Equal(t, ok, true)
186+
assert.Equal(t, val, testAnnotationVal)
187+
})
145188
}
146189

147190
// If `remote` field is used in CR, then the component resources should not be created

deploy/olm-catalog/argocd-operator/0.18.0/argoproj.io_argocds.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8455,6 +8455,12 @@ spec:
84558455
description: Service defines the options for the Service backing
84568456
the ArgoCD Server component.
84578457
properties:
8458+
annotations:
8459+
additionalProperties:
8460+
type: string
8461+
description: Annotations is the map of annotations to apply
8462+
to the Server Service.
8463+
type: object
84588464
type:
84598465
description: Type is the ServiceType to use for the Service
84608466
resource.
@@ -26355,6 +26361,12 @@ spec:
2635526361
description: Service defines the options for the Service backing
2635626362
the ArgoCD Server component.
2635726363
properties:
26364+
annotations:
26365+
additionalProperties:
26366+
type: string
26367+
description: Annotations is the map of annotations to apply
26368+
to the Server Service.
26369+
type: object
2635826370
type:
2635926371
description: Type is the ServiceType to use for the Service
2636026372
resource.

0 commit comments

Comments
 (0)