Skip to content

Commit

Permalink
Init klog flags
Browse files Browse the repository at this point in the history
Due to updating the machine config operator, we removed an indirect
dependency on github.com/golang/glog. This package provides an init()
method which sets a number of flags that we expect to be present [1].

To ensure compatability with the updates, we can explicitly add these
flags with the klog.init() method [2]. It is better to include packages
that are required to keep the API consistent explicitly.

[1] https://github.com/golang/glog/blob/424d2337a5299a465c8a8228fc3ba4b1c28337a2/glog.go#L398-L404
[2]
https://github.com/kubernetes/klog#:~:text=Use%20klog.InitFlags(nil)%20explicitly%20for%20initializing%20global%20flags%20as%20we%20no%20longer%20use%20init()%20method%20to%20register%20the%20flags

Signed-off-by: Salvatore Daniele <[email protected]>
  • Loading branch information
SalDaniele committed Jun 6, 2024
1 parent 4e0da08 commit 1d99976
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

"github.com/spf13/cobra"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/log"

snolog "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/log"
Expand All @@ -23,6 +24,7 @@ var (
)

func init() {
klog.InitFlags(nil)
snolog.BindFlags(flag.CommandLine)
rootCmd.PersistentFlags().AddGoFlagSet(flag.CommandLine)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ require (
k8s.io/apimachinery v0.28.3
k8s.io/client-go v0.28.3
k8s.io/code-generator v0.28.3
k8s.io/klog/v2 v2.100.1
k8s.io/kubectl v0.28.3
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
sigs.k8s.io/controller-runtime v0.16.3
Expand Down Expand Up @@ -150,7 +151,6 @@ require (
k8s.io/cli-runtime v0.28.3 // indirect
k8s.io/component-base v0.28.3 // indirect
k8s.io/gengo v0.0.0-20230829151522-9cce18d56c01 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-aggregator v0.27.4 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/kubelet v0.27.7 // indirect
Expand Down

0 comments on commit 1d99976

Please sign in to comment.