From 5ce21508d6f6017914cc05f571b2f778b194a311 Mon Sep 17 00:00:00 2001 From: Simon Pasquier Date: Tue, 3 Sep 2024 14:46:26 +0200 Subject: [PATCH] chore: redirect klog to slog PR #6890 removed the final bits from go-kit/log in the operator code base but forgot to redirect the klog logs to the new slog logger. `ResourceReconciler` has a dependency on klog because it uses `utilruntime.HandleError()` when it fails to sync a resource. As a consequence, the operator didn't log reconciliation failures anymore. Signed-off-by: Simon Pasquier --- cmd/operator/main.go | 6 ++---- go.mod | 1 - go.sum | 4 ++-- internal/log/log.go | 7 ------- 4 files changed, 4 insertions(+), 14 deletions(-) diff --git a/cmd/operator/main.go b/cmd/operator/main.go index f497236e5..da104d826 100644 --- a/cmd/operator/main.go +++ b/cmd/operator/main.go @@ -41,6 +41,7 @@ import ( "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" k8sflag "k8s.io/component-base/cli/flag" + "k8s.io/klog/v2" "k8s.io/utils/ptr" "github.com/prometheus-operator/prometheus-operator/internal/goruntime" @@ -198,10 +199,7 @@ func run(fs *flag.FlagSet) int { if err != nil { stdlog.Fatal(err) } - - if err != nil { - stdlog.Fatal(err) - } + klog.SetSlogLogger(logger) if err := cfg.Gates.UpdateFeatureGates(*featureGates.Map); err != nil { logger.Error("", "error", err) diff --git a/go.mod b/go.mod index b482db84d..35915078d 100644 --- a/go.mod +++ b/go.mod @@ -144,5 +144,4 @@ require ( replace ( github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring => ./pkg/apis/monitoring github.com/prometheus-operator/prometheus-operator/pkg/client => ./pkg/client - k8s.io/klog/v2 => github.com/simonpasquier/klog-gokit/v3 v3.5.0 ) diff --git a/go.sum b/go.sum index 15f420d0b..efa9ad6c8 100644 --- a/go.sum +++ b/go.sum @@ -377,8 +377,6 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/simonpasquier/klog-gokit/v3 v3.5.0 h1:ewnk+ickph0hkQFgdI4pffKIbruAxxWcg0Fe/vQmLOM= -github.com/simonpasquier/klog-gokit/v3 v3.5.0/go.mod h1:S9flvRzzpaYLYtXI2w8jf9R/IU/Cy14NrbvDUevNP1E= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= @@ -754,6 +752,8 @@ k8s.io/client-go v0.31.0 h1:QqEJzNjbN2Yv1H79SsS+SWnXkBgVu4Pj3CJQgbx0gI8= k8s.io/client-go v0.31.0/go.mod h1:Y9wvC76g4fLjmU0BA+rV+h2cncoadjvjjkkIGoTLcGU= k8s.io/component-base v0.31.0 h1:/KIzGM5EvPNQcYgwq5NwoQBaOlVFrghoVGr8lG6vNRs= k8s.io/component-base v0.31.0/go.mod h1:TYVuzI1QmN4L5ItVdMSXKvH7/DtvIuas5/mm8YT3rTo= +k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= +k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= k8s.io/kube-openapi v0.0.0-20240808142205-8e686545bdb8 h1:1Wof1cGQgA5pqgo8MxKPtf+qN6Sh/0JzznmeGPm1HnE= k8s.io/kube-openapi v0.0.0-20240808142205-8e686545bdb8/go.mod h1:Os6V6dZwLNii3vxFpxcNaTmH8LJJBkOTg1N0tOA0fvA= k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1J8+AsQnQCKsi8A= diff --git a/internal/log/log.go b/internal/log/log.go index af3490615..ee3fa202f 100644 --- a/internal/log/log.go +++ b/internal/log/log.go @@ -23,7 +23,6 @@ import ( "github.com/go-kit/log" loglevel "github.com/go-kit/log/level" - klogv2 "k8s.io/klog/v2" ) const ( @@ -59,14 +58,10 @@ func NewLogger(c Config) (log.Logger, error) { ) // For log levels other than debug, the klog verbosity level is 0. - klogv2.ClampLevel(0) switch strings.ToLower(c.Level) { case LevelAll: lvlOption = loglevel.AllowAll() case LevelDebug: - // When the log level is set to debug, we set the klog verbosity level to 6. - // Above level 6, the k8s client would log bearer tokens in clear-text. - klogv2.ClampLevel(6) lvlOption = loglevel.AllowDebug() case LevelInfo: lvlOption = loglevel.AllowInfo() @@ -93,8 +88,6 @@ func NewLogger(c Config) (log.Logger, error) { logger = log.With(logger, "ts", log.DefaultTimestampUTC) logger = log.With(logger, "caller", log.DefaultCaller) - klogv2.SetLogger(log.With(logger, "component", "k8s_client_runtime")) - return logger, nil }