From 780db3a0c13fbb8060f08da3ee4e258e38b82d73 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Tue, 16 Apr 2019 14:24:00 +0200 Subject: [PATCH] Initialize klog flags so it logs to stderr This got not caught in CircleCI as it does not perform a rebase on-top of latest master before testing. We bumped client-go a while ago which included a switch to klog, the klog flags need to be intialized before they can be set, as we did not have this initialization in place, the operator was unable to start. As logging to stderr is now the default for klog; only initialize the flags so it is enabled. --- cmd/fluxd/main.go | 8 ++++++-- cmd/helm-operator/main.go | 7 ++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cmd/fluxd/main.go b/cmd/fluxd/main.go index 2a69572de..3a3e4a2f6 100644 --- a/cmd/fluxd/main.go +++ b/cmd/fluxd/main.go @@ -23,6 +23,7 @@ import ( k8sclientdynamic "k8s.io/client-go/dynamic" k8sclient "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" + "k8s.io/klog" "github.com/weaveworks/flux/checkpoint" "github.com/weaveworks/flux/cluster" @@ -165,6 +166,9 @@ func main() { fs.MarkDeprecated("registry-cache-expiry", "no longer used; cache entries are expired adaptively according to how often they change") fs.MarkDeprecated("k8s-namespace-whitelist", "changed to --k8s-allow-namespace, use that instead") + // Explicitly initialize klog to enable stderr logging, + // and parse our own flags. + klog.InitFlags(nil) err := fs.Parse(os.Args[1:]) switch { case err == pflag.ErrHelp: @@ -188,7 +192,7 @@ func main() { logger.Log("version", version) // Silence access errors logged internally by client-go - klog := log.With(logger, "type", "internal kubernetes error") + k8slog := log.With(logger, "type", "internal kubernetes error") logErrorUnlessAccessRelated := func(err error) { errLower := strings.ToLower(err.Error()) if k8serrors.IsForbidden(err) || k8serrors.IsNotFound(err) || @@ -196,7 +200,7 @@ func main() { strings.Contains(errLower, "not found") { return } - klog.Log("err", err) + k8slog.Log("err", err) } k8sruntime.ErrorHandlers = []func(error){logErrorUnlessAccessRelated} diff --git a/cmd/helm-operator/main.go b/cmd/helm-operator/main.go index 3b76a4e8c..f2f80729b 100644 --- a/cmd/helm-operator/main.go +++ b/cmd/helm-operator/main.go @@ -1,7 +1,6 @@ package main import ( - "flag" "fmt" "os" "os/signal" @@ -14,6 +13,7 @@ import ( "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/util/workqueue" + "k8s.io/klog" "github.com/weaveworks/flux/checkpoint" clientset "github.com/weaveworks/flux/integrations/client/clientset/versioned" @@ -103,8 +103,9 @@ func init() { } func main() { - // set glog output to stderr - flag.CommandLine.Parse([]string{"-logtostderr"}) + // Explicitly initialize klog to enable stderr logging, + // and parse our own flags. + klog.InitFlags(nil) fs.Parse(os.Args) if *versionFlag {