mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
logs: replace our custom flush daemon with klog's daemon
The advantage is that klog properly handles restarting of the daemon with a new interval and the daemon can be stopped. Stopping the daemon solves a data race that the tests had when modifying the Logger's flush function while goroutines from previous tests were still running.
This commit is contained in:
parent
f8bb67cc2e
commit
0b7d303a90
@ -26,7 +26,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -175,7 +174,7 @@ func InitLogs() {
|
|||||||
if logFlushFreqAdded {
|
if logFlushFreqAdded {
|
||||||
// The flag from this file was activated, so use it now.
|
// The flag from this file was activated, so use it now.
|
||||||
// Otherwise LoggingConfiguration.Apply will do this.
|
// Otherwise LoggingConfiguration.Apply will do this.
|
||||||
go wait.Forever(FlushLogs, logFlushFreq)
|
klog.StartFlushDaemon(logFlushFreq)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
|
||||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
|
||||||
"k8s.io/component-base/config"
|
"k8s.io/component-base/config"
|
||||||
"k8s.io/component-base/config/v1alpha1"
|
"k8s.io/component-base/config/v1alpha1"
|
||||||
"k8s.io/component-base/logs/registry"
|
"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 {
|
if err := loggingFlags.Lookup("vmodule").Value.Set(o.Config.VModule.String()); err != nil {
|
||||||
panic(fmt.Errorf("internal error while setting klog vmodule: %v", err))
|
panic(fmt.Errorf("internal error while setting klog vmodule: %v", err))
|
||||||
}
|
}
|
||||||
go wait.Forever(FlushLogs, o.Config.FlushFrequency)
|
klog.StartFlushDaemon(o.Config.FlushFrequency)
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||||
|
"k8s.io/klog/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFlags(t *testing.T) {
|
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)
|
t.Errorf("Wrong Validate() result for %q. expect %v, got %v", tc.name, tc.want, o)
|
||||||
}
|
}
|
||||||
err := o.ValidateAndApply()
|
err := o.ValidateAndApply()
|
||||||
|
defer klog.StopFlushDaemon()
|
||||||
|
|
||||||
if !assert.ElementsMatch(t, tc.errs.ToAggregate(), err) {
|
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)
|
t.Errorf("Wrong Validate() result for %q.\n expect:\t%+v\n got:\t%+v", tc.name, tc.errs, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user