Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature/Operator] Configurable log levels #20

Merged
merged 3 commits into from
Mar 16, 2022
Merged
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Added

- [PR #21](https://github.com/konpyutaika/nifikop/pull/21) - **[Operator]** Propagate user provided issuerRef Group for custom CertManager Issuer.
- [PR #20](https://github.com/konpyutaika/nifikop/pull/20) - **[Operator]** Configurable log levels
- [PR #19](https://github.com/konpyutaika/nifikop/pull/19) - **[Helm chart]** Support --namespace helm arg
- [PR #18](https://github.com/konpyutaika/nifikop/pull/18) - **[Operator/NiFiCluster]** Support `topologySpreadConstraint`
- [PR #17](https://github.com/konpyutaika/nifikop/pull/17) - **[Operator/NiFiCluster]** Add ability to set max event driven thread count to NiFi Cluster.
Expand Down
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
golang.org/x/tools v0.0.0-20201014231627-1610a49f37af // indirect
k8s.io/api v0.20.2
k8s.io/apimachinery v0.20.2
Expand Down
4 changes: 1 addition & 3 deletions helm/nifikop/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,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
10 changes: 7 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package main
import (
"flag"
"fmt"
"os"
"strings"

certv1 "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1alpha2"
"github.com/konpyutaika/nifikop/pkg/common"
"github.com/konpyutaika/nifikop/pkg/util"
"github.com/konpyutaika/nifikop/version"
"os"
"sigs.k8s.io/controller-runtime/pkg/cache"
"strings"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
Expand Down Expand Up @@ -56,8 +58,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
24 changes: 23 additions & 1 deletion pkg/common/common.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package common

import (
"github.com/go-logr/logr"
"github.com/konpyutaika/nifikop/pkg/nificlient"
"github.com/konpyutaika/nifikop/pkg/util"
"github.com/konpyutaika/nifikop/pkg/util/clientconfig"
"github.com/go-logr/logr"
"go.uber.org/zap/zapcore"
)

//// NewFromCluster is a convenient wrapper around New() and ClusterConfig()
Expand Down Expand Up @@ -84,3 +85,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
}
}