From 18bf5d23f122589e1ef24bb68e8c5f3662fe2467 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Fri, 1 Apr 2022 15:31:03 +0200 Subject: [PATCH] logs: simplify flush daemon startup StartFlushDaemon can be called more than once. We can take advantage of that an eliminate the tracking of where we need to start it. --- staging/src/k8s.io/component-base/logs/logs.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/staging/src/k8s.io/component-base/logs/logs.go b/staging/src/k8s.io/component-base/logs/logs.go index da815e11669..9d66354a4c1 100644 --- a/staging/src/k8s.io/component-base/logs/logs.go +++ b/staging/src/k8s.io/component-base/logs/logs.go @@ -43,8 +43,7 @@ var ( // Periodic flushing gets configured either via the global flag // in this file or via LoggingConfiguration. - logFlushFreq time.Duration - logFlushFreqAdded bool + logFlushFreq time.Duration ) func init() { @@ -100,7 +99,6 @@ func AddFlags(fs *pflag.FlagSet, opts ...Option) { if o.skipLoggingConfigurationFlags { return } - logFlushFreqAdded = true case "vmodule": // TODO: see above // pf.Usage += vmoduleUsage @@ -142,7 +140,6 @@ func AddGoFlags(fs *flag.FlagSet, opts ...Option) { if o.skipLoggingConfigurationFlags { return } - logFlushFreqAdded = true case "vmodule": // TODO: see above // usage += vmoduleUsage @@ -181,11 +178,11 @@ func (writer KlogWriter) Write(data []byte) (n int, err error) { func InitLogs() { log.SetOutput(KlogWriter{}) log.SetFlags(0) - if logFlushFreqAdded { - // The flag from this file was activated, so use it now. - // Otherwise LoggingConfiguration.Apply will do this. - klog.StartFlushDaemon(logFlushFreq) - } + + // Start flushing now. If LoggingConfiguration.ApplyAndValidate is + // used, it will restart the daemon with the log flush interval defined + // there. + klog.StartFlushDaemon(logFlushFreq) // This is the default in Kubernetes. Options.ValidateAndApply // will override this with the result of a feature gate check.