Skip to content

Commit

Permalink
propagate log level into kube-router
Browse files Browse the repository at this point in the history
Init klog v2 with the same V level set for logrus so that the verbosity level is correct in kube-router.

Signed-off-by: Thomas Ferrandiz <[email protected]>
  • Loading branch information
thomasferrandiz committed Apr 18, 2023
1 parent 257fa2c commit 035fda7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ require (
k8s.io/component-helpers v0.26.4
k8s.io/cri-api v0.26.4
k8s.io/klog v1.0.0
k8s.io/klog/v2 v2.80.1
k8s.io/kubectl v0.25.0
k8s.io/kubernetes v1.26.4
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d
Expand Down Expand Up @@ -385,7 +386,6 @@ require (
k8s.io/csi-translation-lib v0.0.0 // indirect
k8s.io/dynamic-resource-allocation v0.0.0 // indirect
k8s.io/gengo v0.0.0-20220902162205-c0856e24416d // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kms v0.0.0 // indirect
k8s.io/kube-aggregator v0.25.4 // indirect
k8s.io/kube-controller-manager v0.0.0 // indirect
Expand Down
8 changes: 8 additions & 0 deletions pkg/agent/netpol/netpol.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ package netpol

import (
"context"
"flag"
"runtime"
"strconv"
"strings"
"sync"

Expand All @@ -19,13 +21,15 @@ import (
"github.com/cloudnativelabs/kube-router/v2/pkg/options"
"github.com/cloudnativelabs/kube-router/v2/pkg/utils"
"github.com/coreos/go-iptables/iptables"
"github.com/k3s-io/k3s/pkg/cli/cmds"
"github.com/k3s-io/k3s/pkg/daemons/config"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
v1core "k8s.io/api/core/v1"
"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 @@ -126,6 +130,10 @@ 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
klog.InitFlags(nil)
flag.Set("v", strconv.Itoa(cmds.LogConfig.VLevel))

npc, err := netpol.NewNetworkPolicyController(client, krConfig, podInformer, npInformer, nsInformer, &sync.Mutex{},
iptablesCmdHandlers, ipSetHandlers)
if err != nil {
Expand Down

0 comments on commit 035fda7

Please sign in to comment.