Skip to content

Commit

Permalink
code-refactoring: Generalize auto TLS annotation mutation for other c…
Browse files Browse the repository at this point in the history
…omponents (argoproj-labs#1184)

* generalize tls annotation mutation for all components
---------

Signed-off-by: Jaideep Rao <[email protected]>
  • Loading branch information
jaideepr97 authored Jan 25, 2024
1 parent 8eac334 commit e993de1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions common/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,5 @@ const (
// misc
const (
TLSSecretNameKey = "tls-secret-name"
WantAutoTLSKey = "wantAutoTLS"
)
27 changes: 18 additions & 9 deletions pkg/openshift/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package openshift

import (
"fmt"
"strconv"

"golang.org/x/mod/semver"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -30,24 +31,32 @@ func AddAutoTLSAnnotationForOpenShift(cr *argoproj.ArgoCD, resource interface{},
}
switch obj := resource.(type) {
case *corev1.Service:
if cr == nil {
return nil
}
// return if autoTLS is not requested
if !cr.Spec.Redis.WantsAutoTLS() {
return nil
}

if obj.Annotations == nil {
obj.Annotations = make(map[string]string)
}

// Ensure that args carries only one argument, which is a map of type map[string]string
// containing the key "tls-secret-name". If this is the case, the associated value
// can be used within the service annotation
// containing the keys "wantAutoTLS" and "tls-secret-name". If this is the case, the associated value
// can be used within the service annotation if auto TLS is requested
if len(args) == 1 {
for _, arg := range args {
argMap := arg.(map[string]string)

if val, ok := argMap[common.WantAutoTLSKey]; !ok {
return nil
} else {
wantTLS, err := strconv.ParseBool(val)
if err != nil {
return errors.Wrapf(err, "AddAutoTLSAnnotationForOpenShift: failed to parse mutation args for resource")
}

// return if autoTLS is not requested
if !wantTLS {
return nil
}
}

if val, ok := argMap[common.TLSSecretNameKey]; ok {
obj.Annotations[common.ServiceBetaOpenshiftKeyCertSecret] = val
}
Expand Down

0 comments on commit e993de1

Please sign in to comment.