From f9dc121f0d7a0e814b6e473313d5a3ac00ad5f0c Mon Sep 17 00:00:00 2001 From: Sunnatillo Date: Thu, 12 Dec 2024 13:35:29 +0200 Subject: [PATCH] Removes depreacted klogr.New() and rand.Seed() As of Go 1.20 there is no reason to call Seed with a random value klog.Background will automatically use the right logger Signed-off-by: Sunnatillo --- controllers/suite_test.go | 4 ++-- main.go | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 2bf3a0eba5..df39b2e1a8 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -32,7 +32,7 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" - "k8s.io/klog/v2/klogr" + "k8s.io/klog/v2" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/envtest" @@ -62,7 +62,7 @@ const ( ) func init() { - logf.SetLogger(klogr.New()) + logf.SetLogger(klog.Background()) // Register required object kinds with global scheme. _ = apiextensionsv1.AddToScheme(scheme.Scheme) diff --git a/main.go b/main.go index ed982ac531..ee54e3f207 100644 --- a/main.go +++ b/main.go @@ -20,7 +20,6 @@ import ( "context" "flag" "fmt" - "math/rand" "os" "strconv" "time" @@ -46,7 +45,7 @@ import ( "k8s.io/component-base/logs" logsv1 "k8s.io/component-base/logs/api/v1" _ "k8s.io/component-base/logs/json/register" - "k8s.io/klog/v2/klogr" + "k8s.io/klog/v2" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/controllers/remote" caipamv1 "sigs.k8s.io/cluster-api/exp/ipam/api/v1alpha1" @@ -110,7 +109,6 @@ func init() { // +kubebuilder:rbac:groups=authorization.k8s.io,resources=subjectaccessreviews,verbs=create func main() { - rand.Seed(time.Now().UnixNano()) initFlags(pflag.CommandLine) pflag.CommandLine.AddGoFlagSet(flag.CommandLine) pflag.Parse() @@ -120,7 +118,7 @@ func main() { os.Exit(1) } - ctrl.SetLogger(klogr.New()) + ctrl.SetLogger(klog.Background()) restConfig := ctrl.GetConfigOrDie() restConfig.QPS = restConfigQPS restConfig.Burst = restConfigBurst