Skip to content

Commit

Permalink
Add go routine to periodically set the klog verbosity level to the co…
Browse files Browse the repository at this point in the history
…rrect value

Signed-off-by: Thomas Ferrandiz <[email protected]>
  • Loading branch information
thomasferrandiz committed Apr 20, 2023
1 parent 33674fd commit b8d329e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
7 changes: 2 additions & 5 deletions pkg/agent/netpol/netpol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions pkg/daemons/executor/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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
}

Expand Down

0 comments on commit b8d329e

Please sign in to comment.