Set klog's logtostderr flag (#2529)

* Parse as well as  setlogtostderr flag

* Enforce setting of logtostderr for klog

* Clearup comment on klog
This commit is contained in:
Guy Templeton 2019-02-07 07:33:31 +00:00 committed by Miek Gieben
parent 92836cc6f9
commit 39cf482348

View file

@ -20,6 +20,9 @@ import (
"github.com/miekg/dns" "github.com/miekg/dns"
meta "k8s.io/apimachinery/pkg/apis/meta/v1" 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 // Excluding azure because it is failing to compile
// pull this in here, because we want it excluded if plugin.cfg doesn't have k8s // 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" _ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
@ -33,12 +36,15 @@ import (
var log = clog.NewWithPlugin("kubernetes") var log = clog.NewWithPlugin("kubernetes")
func init() { 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(). // 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 // 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 // all CoreDNS logging. We can't do *that* in the init function, because we, when starting, also barf some
// things to stderr. // 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{ caddy.RegisterPlugin("kubernetes", caddy.Plugin{
ServerType: "dns", ServerType: "dns",