diff --git a/go.mod b/go.mod index 1d9dfbd40032..4864ed93cb92 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/pkg/agent/netpol/netpol.go b/pkg/agent/netpol/netpol.go index b2c97ccd6cb0..4fd7821d1372 100644 --- a/pkg/agent/netpol/netpol.go +++ b/pkg/agent/netpol/netpol.go @@ -8,7 +8,9 @@ package netpol import ( "context" + "flag" "runtime" + "strconv" "strings" "sync" @@ -19,6 +21,7 @@ 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" @@ -26,6 +29,7 @@ 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 @@ -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 {