From 0679ebde63a859395e940c31193018a19aedb767 Mon Sep 17 00:00:00 2001 From: Yury Kulazhenkov Date: Wed, 9 Mar 2022 18:40:36 +0300 Subject: [PATCH] Move logger initialization before k8s client creation ctrl.Log var contains noop logger until logger instance is explicitly set with ctrl.SetLogger function If error happen during k8s client creation it will be not logged because ctrl.SetLogger is called after. Move logger initialization step before k8s client creation to be able to log client initialization errors. Signed-off-by: Yury Kulazhenkov --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 7a146b1bc..d6bcb990f 100644 --- a/main.go +++ b/main.go @@ -78,6 +78,7 @@ func main() { } opts.BindFlags(flag.CommandLine) flag.Parse() + ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts))) restConfig := ctrl.GetConfigOrDie() kubeClient, err := client.New(restConfig, client.Options{Scheme: scheme}) @@ -88,7 +89,6 @@ func main() { le := leaderelection.GetLeaderElectionConfig(kubeClient, enableLeaderElection) - ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts))) namespace := os.Getenv("NAMESPACE") mgr, err := ctrl.NewManager(restConfig, ctrl.Options{ Scheme: scheme,