Skip to content

Commit 814c7f0

Browse files
Merge pull request #833 from aliceh/fix/controller-runtime-logger-initialization
Fix controller-runtime logger initialization warning
2 parents cf2b358 + 8479915 commit 814c7f0

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
@@ -218,10 +218,13 @@ func NewAsBackplaneClusterAdminWithConn(clusterID string, options client.Options
218218
}
219219

220220
func setRuntimeLoggerDiscard() {
221-
// To avoid warnings/backtrace, if k8s controller-runtime logger has not already been set, do it now...
222-
if !log.Log.Enabled() {
223-
log.SetLogger(zap.New(zap.WriteTo(io.Discard)))
224-
}
221+
// Unconditionally set logger to discard to avoid initialization warnings.
222+
// The controller-runtime library prints a stack trace if the logger is accessed
223+
// before SetLogger() is called within 30 seconds of startup. Checking if the
224+
// logger is enabled before setting it causes this warning because the check
225+
// itself triggers the eventuallyFulfillRoot() mechanism. SetLogger() can be
226+
// called multiple times safely - the last call wins.
227+
log.SetLogger(zap.New(zap.WriteTo(io.Discard)))
225228
}
226229

227230
func GetCurrentCluster() (string, error) {

0 commit comments

Comments
 (0)