From 0da9d93d774150d32253d36dcd4ba3f40d3fb11a Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Thu, 21 Sep 2023 12:37:42 +0200 Subject: [PATCH] Initialize global controller-runtime logger So that global controller-runtime logs get collected and no warnings like the following are printed to stderr: [controller-runtime] log.SetLogger(...) was never called; logs will not be displayed. Detected at: > goroutine 2982 [running]: > runtime/debug.Stack() > /usr/local/go/src/runtime/debug/stack.go:24 +0x65 > sigs.k8s.io/controller-runtime/pkg/log.eventuallyFulfillRoot() > /run/k0s-build/go/mod/sigs.k8s.io/controller-runtime@v0.16.2/pkg/log/log.go:60 +0xcd > sigs.k8s.io/controller-runtime/pkg/log.(*delegatingLogSink).Enabled(0xc0002cb800, 0x0?) > /run/k0s-build/go/mod/sigs.k8s.io/controller-runtime@v0.16.2/pkg/log/deleg.go:111 +0x3d > github.com/go-logr/logr.Logger.Enabled(...) > /run/k0s-build/go/mod/github.com/go-logr/logr@v1.2.4/logr.go:261 > github.com/go-logr/logr.Logger.Info({{0x4066640?, 0xc0002cb800?}, 0xc001350c00?}, {0x39ea77f, 0x36}, {0x0, 0x0, 0x0}) > /run/k0s-build/go/mod/github.com/go-logr/logr@v1.2.4/logr.go:274 +0x78 > sigs.k8s.io/controller-runtime/pkg/manager.(*controllerManager).engageStopProcedure.func3() > /run/k0s-build/go/mod/sigs.k8s.io/controller-runtime@v0.16.2/pkg/manager/internal.go:516 +0x59 > created by sigs.k8s.io/controller-runtime/pkg/manager.(*controllerManager).engageStopProcedure > /run/k0s-build/go/mod/sigs.k8s.io/controller-runtime@v0.16.2/pkg/manager/internal.go:514 +0x28a Signed-off-by: Tom Wieczorek --- go.mod | 2 +- go.sum | 7 ++----- internal/pkg/log/k0s.go | 3 +++ pkg/component/controller/extensions_controller.go | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 30519f57a2ec..7c5c00db3e15 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/Microsoft/hcsshim v0.11.0 github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 github.com/avast/retry-go v3.0.0+incompatible - github.com/bombsimon/logrusr/v2 v2.0.1 + github.com/bombsimon/logrusr/v4 v4.0.0 github.com/carlmjohnson/requests v0.23.4 github.com/cavaliergopher/grab/v3 v3.0.1 github.com/cloudflare/cfssl v1.6.4 diff --git a/go.sum b/go.sum index ce6b208d446c..c1a783906697 100644 --- a/go.sum +++ b/go.sum @@ -110,8 +110,8 @@ github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= -github.com/bombsimon/logrusr/v2 v2.0.1 h1:1VgxVNQMCvjirZIYaT9JYn6sAVGVEcNtRE0y4mvaOAM= -github.com/bombsimon/logrusr/v2 v2.0.1/go.mod h1:ByVAX+vHdLGAfdroiMg6q0zgq2FODY2lc5YJvzmOJio= +github.com/bombsimon/logrusr/v4 v4.0.0 h1:Pm0InGphX0wMhPqC02t31onlq9OVyJ98eP/Vh63t1Oo= +github.com/bombsimon/logrusr/v4 v4.0.0/go.mod h1:pjfHC5e59CvjTBIU3V3sGhFWFAnsnhOR03TRc6im0l8= github.com/briandowns/spinner v1.19.0 h1:s8aq38H+Qju89yhp89b4iIiMzMm8YN3p6vGpwyh/a8E= github.com/briandowns/spinner v1.19.0/go.mod h1:mQak9GHqbspjC/5iUx3qMlIho8xBS/ppAL/hX5SmPJU= github.com/bshuster-repo/logrus-logstash-hook v1.0.0 h1:e+C0SB5R1pu//O4MQ3f9cFuPGoOVeF2fE4Og9otCc70= @@ -282,7 +282,6 @@ github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2 github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= -github.com/go-logr/logr v1.0.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= @@ -532,7 +531,6 @@ github.com/kisielk/sqlstruct v0.0.0-20201105191214-5f3e10d3ab46/go.mod h1:yyMNCy github.com/klauspost/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI= github.com/klauspost/compress v1.16.5/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kortschak/utter v1.0.1/go.mod h1:vSmSjbyrlKjjsL71193LmzBOKgwePk9DH6uFaWHIInc= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= @@ -1128,7 +1126,6 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210608053332-aa57babbf139/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/internal/pkg/log/k0s.go b/internal/pkg/log/k0s.go index 4db2ff1e836d..9bbf65524903 100644 --- a/internal/pkg/log/k0s.go +++ b/internal/pkg/log/k0s.go @@ -17,8 +17,10 @@ limitations under the License. package log import ( + "github.com/bombsimon/logrusr/v4" cfssllog "github.com/cloudflare/cfssl/log" "github.com/sirupsen/logrus" + crlog "sigs.k8s.io/controller-runtime/pkg/log" ) func InitLogging() { @@ -28,6 +30,7 @@ func InitLogging() { logrus.SetFormatter(customFormatter) cfssllog.SetLogger((*cfsslAdapter)(logrus.WithField("component", "cfssl"))) + crlog.SetLogger(logrusr.New(logrus.WithField("component", "controller-runtime"))) SetWarnLevel() } diff --git a/pkg/component/controller/extensions_controller.go b/pkg/component/controller/extensions_controller.go index 728fca7395db..6fbb393f9124 100644 --- a/pkg/component/controller/extensions_controller.go +++ b/pkg/component/controller/extensions_controller.go @@ -23,7 +23,7 @@ import ( "time" "github.com/avast/retry-go" - "github.com/bombsimon/logrusr/v2" + "github.com/bombsimon/logrusr/v4" "github.com/k0sproject/k0s/internal/pkg/templatewriter" helmapi "github.com/k0sproject/k0s/pkg/apis/helm" "github.com/k0sproject/k0s/pkg/apis/helm/v1beta1"