diff --git a/go.mod b/go.mod index 069c207f1..be12d36f8 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( github.com/onsi/gomega v1.10.2 github.com/pavel-v-chernykh/keystore-go v2.1.0+incompatible github.com/stretchr/testify v1.6.1 + go.uber.org/zap v1.15.0 // indirect golang.org/x/tools v0.0.0-20201014231627-1610a49f37af // indirect k8s.io/api v0.20.2 k8s.io/apimachinery v0.20.2 diff --git a/helm/nifikop/templates/deployment.yaml b/helm/nifikop/templates/deployment.yaml index 9d372f0a1..41a404bd7 100644 --- a/helm/nifikop/templates/deployment.yaml +++ b/helm/nifikop/templates/deployment.yaml @@ -42,7 +42,7 @@ spec: {{- end }} {{- if .Values.rbacEnable }} {{- if and .Values.serviceAccount .Values.serviceAccount.name }} - serviceAccountName: {{ .Values.serviceAccount.name }} + serviceAccountName: {{ .Values.serviceAccount.name }} {{- else }} serviceAccountName: {{ template "nifikop.name" . }} {{- end }} @@ -103,10 +103,8 @@ spec: - name: VAULT_CACERT value: /etc/vault/certs/ca.crt {{- end }} - {{- if .Values.debug.enabled }} - name: LOG_LEVEL - value: Debug - {{- end }} + value: {{ default "Info" .Values.logLevel }} livenessProbe: httpGet: path: /healthz diff --git a/helm/nifikop/values.yaml b/helm/nifikop/values.yaml index 5664bdfc3..917346ebf 100644 --- a/helm/nifikop/values.yaml +++ b/helm/nifikop/values.yaml @@ -41,8 +41,7 @@ metrics: enabled: false port: 8081 -debug: - enabled: false +logLevel: Info certManager: enabled: true diff --git a/main.go b/main.go index 91cfb98e1..7c9c0d65c 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,7 @@ import ( "flag" "fmt" "github.com/Orange-OpenSource/nifikop/pkg/common" + "github.com/Orange-OpenSource/nifikop/pkg/util" "github.com/Orange-OpenSource/nifikop/version" certv1 "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1alpha2" "os" @@ -72,8 +73,10 @@ func main() { "Enabling this will ensure there is only one active controller manager.") flag.BoolVar(&certManagerEnabled, "cert-manager-enabled", false, "Enable cert-manager integration") + logLvl, isDevelopment := common.NewLogLevel(util.GetEnvWithDefault("LOG_LEVEL", "Debug")) opts := zap.Options{ - Development: true, + Development: isDevelopment, + Level: logLvl, } opts.BindFlags(flag.CommandLine) flag.Parse() diff --git a/pkg/common/common.go b/pkg/common/common.go index 4eec36d6c..272fbe78b 100644 --- a/pkg/common/common.go +++ b/pkg/common/common.go @@ -1,10 +1,12 @@ package common import ( + "github.com/go-logr/logr" + "go.uber.org/zap/zapcore" + "github.com/Orange-OpenSource/nifikop/pkg/nificlient" "github.com/Orange-OpenSource/nifikop/pkg/util" "github.com/Orange-OpenSource/nifikop/pkg/util/clientconfig" - "github.com/go-logr/logr" ) //// NewFromCluster is a convenient wrapper around New() and ClusterConfig() @@ -84,3 +86,24 @@ func NewRequeueConfig() *RequeueConfig { RequeueOffset: util.MustConvertToInt(util.GetEnvWithDefault("REQUEUE_OFFSET", "0"), "REQUEUE_OFFSET"), } } + +func NewLogLevel(lvl string) (zapcore.LevelEnabler, bool) { + switch lvl { + case "Debug": + return zapcore.DebugLevel, true + case "Info": + return zapcore.InfoLevel, false + case "Warn": + return zapcore.WarnLevel, false + case "Error": + return zapcore.ErrorLevel, false + case "DPanic": + return zapcore.DPanicLevel, false + case "Panic": + return zapcore.PanicLevel, false + case "Fatal": + return zapcore.FatalLevel, false + default: + return zapcore.DebugLevel, true + } +}