Skip to content
This repository was archived by the owner on Oct 20, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions helm/nifikop/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions helm/nifikop/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ metrics:
enabled: false
port: 8081

debug:
enabled: false
logLevel: Info

certManager:
enabled: true
Expand Down
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down
25 changes: 24 additions & 1 deletion pkg/common/common.go
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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
}
}