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:
parent
c762ce8d6f
commit
5bd0bc8cba
|
@ -34,6 +34,9 @@ spec:
|
|||
fieldRef:
|
||||
fieldPath: metadata.namespace
|
||||
args:
|
||||
- --watch-all-namespaces
|
||||
- --log-level=info
|
||||
- --log-json
|
||||
- --enable-leader-election
|
||||
resources:
|
||||
limits:
|
||||
|
|
8
main.go
8
main.go
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue