Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Initialize klog flags so it logs to stderr
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hiddeco committed Apr 16, 2019
1 parent ff93ae0 commit 780db3a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 6 additions & 2 deletions cmd/fluxd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand All @@ -188,15 +192,15 @@ 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) ||
strings.Contains(errLower, "forbidden") ||
strings.Contains(errLower, "not found") {
return
}
klog.Log("err", err)
k8slog.Log("err", err)
}
k8sruntime.ErrorHandlers = []func(error){logErrorUnlessAccessRelated}

Expand Down
7 changes: 4 additions & 3 deletions cmd/helm-operator/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"flag"
"fmt"
"os"
"os/signal"
Expand All @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 780db3a

Please sign in to comment.