Set logger up with log level and JSON flags

This is the GitOps Toolkit convention.  This commit also puts the
flags in the base deployment config, in the same order as for other
GOTK controllers.

Signed-off-by: Michael Bridgen <michael@weave.works>
This commit is contained in:
Michael Bridgen 2020-11-23 12:54:15 +00:00
parent c762ce8d6f
commit 5bd0bc8cba
2 changed files with 9 additions and 2 deletions

View File

@ -34,6 +34,9 @@ spec:
fieldRef:
fieldPath: metadata.namespace
args:
- --watch-all-namespaces
- --log-level=info
- --log-json
- --enable-leader-election
resources:
limits:

View File

@ -24,9 +24,9 @@ import (
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
imagev1alpha1_reflect "github.com/fluxcd/image-reflector-controller/api/v1alpha1"
"github.com/fluxcd/pkg/runtime/logger"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
imagev1alpha1_auto "github.com/fluxcd/image-automation-controller/api/v1alpha1"
@ -52,6 +52,8 @@ func main() {
var (
metricsAddr string
enableLeaderElection bool
logLevel string
logJSON bool
watchAllNamespaces bool
)
@ -59,11 +61,13 @@ func main() {
flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.StringVar(&logLevel, "log-level", "info", "Set logging level. Can be debug, info or error.")
flag.BoolVar(&logJSON, "log-json", false, "Set logging to JSON format.")
flag.BoolVar(&watchAllNamespaces, "watch-all-namespaces", true,
"Watch for custom resources in all namespaces, if set to false it will only watch the runtime namespace.")
flag.Parse()
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
ctrl.SetLogger(logger.NewLogger(logLevel, logJSON))
watchNamespace := ""
if !watchAllNamespaces {