diff --git a/staging/src/k8s.io/component-base/logs/logs.go b/staging/src/k8s.io/component-base/logs/logs.go index 8276a9cadc07..d1088e7bd3c4 100644 --- a/staging/src/k8s.io/component-base/logs/logs.go +++ b/staging/src/k8s.io/component-base/logs/logs.go @@ -26,7 +26,6 @@ import ( "time" "github.com/spf13/pflag" - "k8s.io/apimachinery/pkg/util/wait" "k8s.io/klog/v2" ) @@ -175,7 +174,7 @@ func InitLogs() { if logFlushFreqAdded { // The flag from this file was activated, so use it now. // Otherwise LoggingConfiguration.Apply will do this. - go wait.Forever(FlushLogs, logFlushFreq) + klog.StartFlushDaemon(logFlushFreq) } } diff --git a/staging/src/k8s.io/component-base/logs/options.go b/staging/src/k8s.io/component-base/logs/options.go index c629399ed1a7..551fe5a36612 100644 --- a/staging/src/k8s.io/component-base/logs/options.go +++ b/staging/src/k8s.io/component-base/logs/options.go @@ -22,7 +22,6 @@ import ( "github.com/spf13/pflag" utilerrors "k8s.io/apimachinery/pkg/util/errors" - "k8s.io/apimachinery/pkg/util/wait" "k8s.io/component-base/config" "k8s.io/component-base/config/v1alpha1" "k8s.io/component-base/logs/registry" @@ -90,5 +89,5 @@ func (o *Options) apply() { if err := loggingFlags.Lookup("vmodule").Value.Set(o.Config.VModule.String()); err != nil { panic(fmt.Errorf("internal error while setting klog vmodule: %v", err)) } - go wait.Forever(FlushLogs, o.Config.FlushFrequency) + klog.StartFlushDaemon(o.Config.FlushFrequency) } diff --git a/staging/src/k8s.io/component-base/logs/options_test.go b/staging/src/k8s.io/component-base/logs/options_test.go index e6e758c391c1..bf3b19870ef9 100644 --- a/staging/src/k8s.io/component-base/logs/options_test.go +++ b/staging/src/k8s.io/component-base/logs/options_test.go @@ -24,6 +24,7 @@ import ( "github.com/stretchr/testify/assert" "k8s.io/apimachinery/pkg/util/validation/field" + "k8s.io/klog/v2" ) func TestFlags(t *testing.T) { @@ -89,6 +90,7 @@ func TestOptions(t *testing.T) { t.Errorf("Wrong Validate() result for %q. expect %v, got %v", tc.name, tc.want, o) } err := o.ValidateAndApply() + defer klog.StopFlushDaemon() if !assert.ElementsMatch(t, tc.errs.ToAggregate(), err) { t.Errorf("Wrong Validate() result for %q.\n expect:\t%+v\n got:\t%+v", tc.name, tc.errs, err)