diff --git a/common/keys.go b/common/keys.go index 2998bdc37..70bef5360 100644 --- a/common/keys.go +++ b/common/keys.go @@ -212,4 +212,5 @@ const ( // misc const ( TLSSecretNameKey = "tls-secret-name" + WantAutoTLSKey = "wantAutoTLS" ) diff --git a/pkg/openshift/mutation.go b/pkg/openshift/mutation.go index 20e812b59..072a26843 100644 --- a/pkg/openshift/mutation.go +++ b/pkg/openshift/mutation.go @@ -2,6 +2,7 @@ package openshift import ( "fmt" + "strconv" "golang.org/x/mod/semver" corev1 "k8s.io/api/core/v1" @@ -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 } diff --git a/pkg/util/log.go b/pkg/util/log.go index f0cf226d1..1ffd20d0b 100644 --- a/pkg/util/log.go +++ b/pkg/util/log.go @@ -3,9 +3,27 @@ package util import ( "strings" + "github.com/go-logr/logr" "go.uber.org/zap/zapcore" + ctrl "sigs.k8s.io/controller-runtime" ) +type Logger struct { + logr.Logger +} + +func NewLogger(name string, keysAndValues ...interface{}) *Logger { + return &Logger{ + ctrl.Log.WithName(name).WithValues(keysAndValues...), + } +} + +func (logger *Logger) Debug(msg string, keysAndValues ...interface{}) { + lvl := int(-1 * zapcore.DebugLevel) + + logger.V(lvl).Info(msg, keysAndValues...) +} + func GetLogLevel(lvl string) zapcore.Level { switch strings.ToLower(lvl) { case "error":