@@ -21,6 +21,7 @@ import (
21
21
corev1 "k8s.io/api/core/v1"
22
22
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23
23
"k8s.io/apimachinery/pkg/util/intstr"
24
+ "sigs.k8s.io/controller-runtime/pkg/client"
24
25
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
25
26
26
27
argoproj "github.com/argoproj-labs/argocd-operator/api/v1beta1"
@@ -210,7 +211,7 @@ func (r *ReconcileArgoCD) reconcileRedisHAProxyService(cr *argoproj.ArgoCD) erro
210
211
return r .Client .Delete (context .TODO (), svc )
211
212
}
212
213
213
- if ensureAutoTLSAnnotation (svc , common .ArgoCDRedisServerTLSSecretName , cr .Spec .Redis .WantsAutoTLS ()) {
214
+ if ensureAutoTLSAnnotation (r . Client , svc , common .ArgoCDRedisServerTLSSecretName , cr .Spec .Redis .WantsAutoTLS ()) {
214
215
return r .Client .Update (context .TODO (), svc )
215
216
}
216
217
return nil // Service found, do nothing
@@ -220,7 +221,7 @@ func (r *ReconcileArgoCD) reconcileRedisHAProxyService(cr *argoproj.ArgoCD) erro
220
221
return nil //return as Ha is not enabled do nothing
221
222
}
222
223
223
- ensureAutoTLSAnnotation (svc , common .ArgoCDRedisServerTLSSecretName , cr .Spec .Redis .WantsAutoTLS ())
224
+ ensureAutoTLSAnnotation (r . Client , svc , common .ArgoCDRedisServerTLSSecretName , cr .Spec .Redis .WantsAutoTLS ())
224
225
225
226
svc .Spec .Selector = map [string ]string {
226
227
common .ArgoCDKeyName : nameWithSuffix ("redis-ha-haproxy" , cr ),
@@ -266,7 +267,7 @@ func (r *ReconcileArgoCD) reconcileRedisService(cr *argoproj.ArgoCD) error {
266
267
if ! cr .Spec .Redis .IsEnabled () {
267
268
return r .Client .Delete (context .TODO (), svc )
268
269
}
269
- if ensureAutoTLSAnnotation (svc , common .ArgoCDRedisServerTLSSecretName , cr .Spec .Redis .WantsAutoTLS ()) {
270
+ if ensureAutoTLSAnnotation (r . Client , svc , common .ArgoCDRedisServerTLSSecretName , cr .Spec .Redis .WantsAutoTLS ()) {
270
271
return r .Client .Update (context .TODO (), svc )
271
272
}
272
273
if cr .Spec .HA .Enabled {
@@ -279,7 +280,7 @@ func (r *ReconcileArgoCD) reconcileRedisService(cr *argoproj.ArgoCD) error {
279
280
return nil //return as Ha is enabled do nothing
280
281
}
281
282
282
- ensureAutoTLSAnnotation (svc , common .ArgoCDRedisServerTLSSecretName , cr .Spec .Redis .WantsAutoTLS ())
283
+ ensureAutoTLSAnnotation (r . Client , svc , common .ArgoCDRedisServerTLSSecretName , cr .Spec .Redis .WantsAutoTLS ())
283
284
284
285
svc .Spec .Selector = map [string ]string {
285
286
common .ArgoCDKeyName : nameWithSuffix ("redis" , cr ),
@@ -308,7 +309,7 @@ func (r *ReconcileArgoCD) reconcileRedisService(cr *argoproj.ArgoCD) error {
308
309
//
309
310
// When this method returns true, the svc resource will need to be updated on
310
311
// the cluster.
311
- func ensureAutoTLSAnnotation (svc * corev1.Service , secretName string , enabled bool ) bool {
312
+ func ensureAutoTLSAnnotation (k8sClient client. Client , svc * corev1.Service , secretName string , enabled bool ) bool {
312
313
var autoTLSAnnotationName , autoTLSAnnotationValue string
313
314
314
315
// We currently only support OpenShift for automatic TLS
@@ -323,6 +324,12 @@ func ensureAutoTLSAnnotation(svc *corev1.Service, secretName string, enabled boo
323
324
if autoTLSAnnotationName != "" {
324
325
val , ok := svc .Annotations [autoTLSAnnotationName ]
325
326
if enabled {
327
+ // Don't request a TLS certificate from the OpenShift Service CA if the secret already exists.
328
+ isTLSSecretFound := argoutil .IsObjectFound (k8sClient , svc .Namespace , secretName , & corev1.Secret {})
329
+ if ! ok && isTLSSecretFound {
330
+ log .Info (fmt .Sprintf ("skipping AutoTLS on service %s since the TLS secret is already present" , svc .Name ))
331
+ return false
332
+ }
326
333
if ! ok || val != secretName {
327
334
log .Info (fmt .Sprintf ("requesting AutoTLS on service %s" , svc .ObjectMeta .Name ))
328
335
svc .Annotations [autoTLSAnnotationName ] = autoTLSAnnotationValue
@@ -348,7 +355,7 @@ func (r *ReconcileArgoCD) reconcileRepoService(cr *argoproj.ArgoCD) error {
348
355
if ! cr .Spec .Repo .IsEnabled () {
349
356
return r .Client .Delete (context .TODO (), svc )
350
357
}
351
- if ensureAutoTLSAnnotation (svc , common .ArgoCDRepoServerTLSSecretName , cr .Spec .Repo .WantsAutoTLS ()) {
358
+ if ensureAutoTLSAnnotation (r . Client , svc , common .ArgoCDRepoServerTLSSecretName , cr .Spec .Repo .WantsAutoTLS ()) {
352
359
return r .Client .Update (context .TODO (), svc )
353
360
}
354
361
return nil // Service found, do nothing
@@ -358,7 +365,7 @@ func (r *ReconcileArgoCD) reconcileRepoService(cr *argoproj.ArgoCD) error {
358
365
return nil
359
366
}
360
367
361
- ensureAutoTLSAnnotation (svc , common .ArgoCDRepoServerTLSSecretName , cr .Spec .Repo .WantsAutoTLS ())
368
+ ensureAutoTLSAnnotation (r . Client , svc , common .ArgoCDRepoServerTLSSecretName , cr .Spec .Repo .WantsAutoTLS ())
362
369
363
370
svc .Spec .Selector = map [string ]string {
364
371
common .ArgoCDKeyName : nameWithSuffix ("repo-server" , cr ),
@@ -417,7 +424,7 @@ func (r *ReconcileArgoCD) reconcileServerService(cr *argoproj.ArgoCD) error {
417
424
if ! cr .Spec .Server .IsEnabled () {
418
425
return r .Client .Delete (context .TODO (), svc )
419
426
}
420
- if ensureAutoTLSAnnotation (svc , common .ArgoCDServerTLSSecretName , cr .Spec .Server .WantsAutoTLS ()) {
427
+ if ensureAutoTLSAnnotation (r . Client , svc , common .ArgoCDServerTLSSecretName , cr .Spec .Server .WantsAutoTLS ()) {
421
428
return r .Client .Update (context .TODO (), svc )
422
429
}
423
430
return nil // Service found, do nothing
@@ -427,7 +434,7 @@ func (r *ReconcileArgoCD) reconcileServerService(cr *argoproj.ArgoCD) error {
427
434
return nil
428
435
}
429
436
430
- ensureAutoTLSAnnotation (svc , common .ArgoCDServerTLSSecretName , cr .Spec .Server .WantsAutoTLS ())
437
+ ensureAutoTLSAnnotation (r . Client , svc , common .ArgoCDServerTLSSecretName , cr .Spec .Server .WantsAutoTLS ())
431
438
432
439
svc .Spec .Ports = []corev1.ServicePort {
433
440
{
0 commit comments