From 39cf4823485000fc5d83ac8d2513d6efda93b2e9 Mon Sep 17 00:00:00 2001 From: Guy Templeton Date: Thu, 7 Feb 2019 07:33:31 +0000 Subject: [PATCH] Set klog's logtostderr flag (#2529) * Parse as well as setlogtostderr flag * Enforce setting of logtostderr for klog * Clearup comment on klog --- plugin/kubernetes/setup.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugin/kubernetes/setup.go b/plugin/kubernetes/setup.go index faf0f8ca3..ae32a904e 100644 --- a/plugin/kubernetes/setup.go +++ b/plugin/kubernetes/setup.go @@ -20,6 +20,9 @@ import ( "github.com/miekg/dns" meta "k8s.io/apimachinery/pkg/apis/meta/v1" + // Pull this in for logtostderr flag parsing + "k8s.io/klog" + // Excluding azure because it is failing to compile // pull this in here, because we want it excluded if plugin.cfg doesn't have k8s _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" @@ -33,12 +36,15 @@ import ( var log = clog.NewWithPlugin("kubernetes") func init() { - // Kubernetes plugin uses the kubernetes library, which uses glog (ugh), we must set this *flag*, + // Kubernetes plugin uses the kubernetes library, which now uses klog, we must set and parse this flag // so we don't log to the filesystem, which can fill up and crash CoreDNS indirectly by calling os.Exit(). // We also set: os.Stderr = os.Stdout in the setup function below so we output to standard out; as we do for // all CoreDNS logging. We can't do *that* in the init function, because we, when starting, also barf some // things to stderr. - flag.Set("logtostderr", "true") + klogFlags := flag.NewFlagSet("klog", flag.ExitOnError) + klog.InitFlags(klogFlags) + logtostderr := klogFlags.Lookup("logtostderr") + logtostderr.Value.Set("true") caddy.RegisterPlugin("kubernetes", caddy.Plugin{ ServerType: "dns",