Skip to content

Commit 8479915

Browse files
alicehclaude
andcommitted
Fix controller-runtime logger initialization warning
Remove conditional check in setRuntimeLoggerDiscard() that was causing stack trace warnings when commands took more than 30 seconds to execute. The controller-runtime library enforces logger initialization by printing a stack trace if SetLogger() hasn't been called within 30 seconds of startup. The previous implementation tried to check if the logger was already enabled before setting it, but this check itself triggered the eventuallyFulfillRoot() mechanism that prints the warning. Solution: Unconditionally call SetLogger() since it can be called multiple times safely (the last call wins). This prevents the warning regardless of execution timing. Affected commands: - osdctl network verify-egress - osdctl cluster resize (infra/controlplane/requestserving nodes) - osdctl cluster resync - osdctl dynatrace cluster - And any other commands using k8s.New() or k8s.NewAsBackplaneClusterAdmin() Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 757858d commit 8479915

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

pkg/k8s/client.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,13 @@ func NewAsBackplaneClusterAdmin(clusterID string, options client.Options, elevat
177177
}
178178

179179
func setRuntimeLoggerDiscard() {
180-
// To avoid warnings/backtrace, if k8s controller-runtime logger has not already been set, do it now...
181-
if !log.Log.Enabled() {
182-
log.SetLogger(zap.New(zap.WriteTo(io.Discard)))
183-
}
180+
// Unconditionally set logger to discard to avoid initialization warnings.
181+
// The controller-runtime library prints a stack trace if the logger is accessed
182+
// before SetLogger() is called within 30 seconds of startup. Checking if the
183+
// logger is enabled before setting it causes this warning because the check
184+
// itself triggers the eventuallyFulfillRoot() mechanism. SetLogger() can be
185+
// called multiple times safely - the last call wins.
186+
log.SetLogger(zap.New(zap.WriteTo(io.Discard)))
184187
}
185188

186189
func GetCurrentCluster() (string, error) {

0 commit comments

Comments
 (0)