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

Initialize klog flags so it logs to stderr #1945

Merged
merged 1 commit into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
hiddeco marked this conversation as resolved.
Show resolved Hide resolved
fs.Parse(os.Args)

if *versionFlag {
Expand Down