From b8d329e98cb51393089ed666ce0818f3738abf7e Mon Sep 17 00:00:00 2001 From: Thomas Ferrandiz Date: Thu, 20 Apr 2023 15:00:56 +0000 Subject: [PATCH] Add go routine to periodically set the klog verbosity level to the correct value Signed-off-by: Thomas Ferrandiz --- pkg/agent/netpol/netpol.go | 7 ++----- pkg/daemons/executor/embed.go | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/pkg/agent/netpol/netpol.go b/pkg/agent/netpol/netpol.go index 5dc3a3eb8e33..0f7d2230e301 100644 --- a/pkg/agent/netpol/netpol.go +++ b/pkg/agent/netpol/netpol.go @@ -29,7 +29,6 @@ import ( "k8s.io/client-go/informers" "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/clientcmd" - "k8s.io/klog/v2" ) // Run creates and starts a new instance of the kube-router network policy controller @@ -130,10 +129,8 @@ func Run(ctx context.Context, nodeConfig *config.Node) error { wg.Add(1) go hc.RunCheck(healthCh, stopCh, &wg) - //init klog v2 which is used by kube-router - var krFlags flag.FlagSet - klog.InitFlags(&krFlags) - krFlags.Set("v", strconv.Itoa(cmds.LogConfig.VLevel)) + //set klog v2 verbosity level + flag.Set("v", strconv.Itoa(cmds.LogConfig.VLevel)) npc, err := netpol.NewNetworkPolicyController(client, krConfig, podInformer, npInformer, nsInformer, &sync.Mutex{}, iptablesCmdHandlers, ipSetHandlers) diff --git a/pkg/daemons/executor/embed.go b/pkg/daemons/executor/embed.go index c09dd8277bae..bf55ecffd844 100644 --- a/pkg/daemons/executor/embed.go +++ b/pkg/daemons/executor/embed.go @@ -5,9 +5,12 @@ package executor import ( "context" + "flag" "net/http" "runtime" "runtime/debug" + "strconv" + "time" "github.com/k3s-io/k3s/pkg/cli/cmds" daemonconfig "github.com/k3s-io/k3s/pkg/daemons/config" @@ -31,6 +34,7 @@ import ( cloudcontrollerconfig "k8s.io/cloud-provider/app/config" ccmopt "k8s.io/cloud-provider/options" cliflag "k8s.io/component-base/cli/flag" + "k8s.io/klog/v2" "k8s.io/kubernetes/cmd/kube-apiserver/app" cmapp "k8s.io/kubernetes/cmd/kube-controller-manager/app" proxy "k8s.io/kubernetes/cmd/kube-proxy/app" @@ -47,6 +51,22 @@ func init() { func (e *Embedded) Bootstrap(ctx context.Context, nodeConfig *daemonconfig.Node, cfg cmds.Agent) error { e.nodeConfig = nodeConfig + + go func() { + //init klog v2 which is used by kube-router + klog.InitFlags(nil) + flag.Set("v", strconv.Itoa(cmds.LogConfig.VLevel)) + for { + select { + case <-ctx.Done(): + return + case <-time.After(time.Minute * 5): + //periodically set the verbosity level to the same value as logrus since other components can reset it + flag.Set("v", strconv.Itoa(cmds.LogConfig.VLevel)) + } + } + }() + return nil }