From e01603b2e3326a5eafb7df0e216dcd31772284a5 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Tue, 1 Jul 2025 15:48:10 +0200 Subject: [PATCH] ktesting: document side effect of SetDefaultVerbosity during init --- test/utils/ktesting/ktesting.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/utils/ktesting/ktesting.go b/test/utils/ktesting/ktesting.go index b48e3ea7014..fc15f809759 100644 --- a/test/utils/ktesting/ktesting.go +++ b/test/utils/ktesting/ktesting.go @@ -35,6 +35,15 @@ func init() { // SetDefaultVerbosity can be called during init to modify the default // log verbosity of the program. +// +// Note that this immediately reconfigures the klog verbosity, already before +// flag parsing. If the verbosity is non-zero and SetDefaultVerbosity is called +// during init, then other init functions might start logging where normally +// they wouldn't log anything. Should this occur, then the right fix is to +// remove those log calls because logging during init is discouraged. It leads +// to unpredictable output (init order is not specified) and/or is useless +// (logging not initialized during init and thus conditional log output gets +// omitted). func SetDefaultVerbosity(v int) { f := flag.CommandLine.Lookup("v") _ = f.Value.Set(fmt.Sprintf("%d", v))