Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "log.SetLogger(...) was never called" error #4274

Merged
merged 1 commit into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"k8s.io/client-go/tools/leaderelection/resourcelock"
cgrecord "k8s.io/client-go/tools/record"
"k8s.io/component-base/logs"
"k8s.io/klog/v2"
"k8s.io/klog/v2/textlogger"
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-azure/controllers"
Expand Down Expand Up @@ -254,7 +255,8 @@ func main() {
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()

ctrl.SetLogger(textlogger.NewLogger(logConfig))
// klog.Background will automatically use the right logger.
ctrl.SetLogger(klog.Background())

// Machine and cluster operations can create enough events to trigger the event recorder spam filter
// Setting the burst size higher ensures all events will be recorded and submitted to the API
Expand Down
4 changes: 4 additions & 0 deletions test/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ import (
"path/filepath"

. "github.com/onsi/gomega"
"k8s.io/klog/v2"
"sigs.k8s.io/cluster-api-provider-azure/test/e2e"
"sigs.k8s.io/cluster-api/test/framework"
ctrl "sigs.k8s.io/controller-runtime"
)

func Fail(message string, callerSkip ...int) {
Expand All @@ -40,6 +42,8 @@ func main() {
// needed for ginkgo/gomega which is used by the capi test framework
RegisterFailHandler(Fail)

ctrl.SetLogger(klog.Background())

// using a custom FlagSet here due to the dependency in controller-runtime that is already using this flag
// https://github.com/kubernetes-sigs/controller-runtime/blob/c7a98aa706379c4e5c79ea675c7f333192677971/pkg/client/config/config.go#L37-L41
fs := flag.NewFlagSet("logger", flag.ExitOnError)
Expand Down