From da311e8e7eeb9cbcf2d098fd123b794cb8034e9d Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Tue, 24 Jun 2025 11:07:47 +0200 Subject: [PATCH] kubectl: avoid logging during init LoadTranslations gets called during the init phase: 0 0x0000000005926c56 in k8s.io/kubectl/pkg/util/i18n.LoadTranslations at ./staging/src/k8s.io/kubectl/pkg/util/i18n/i18n.go:146 1 0x0000000005926727 in k8s.io/kubectl/pkg/util/i18n.init.func1 at ./staging/src/k8s.io/kubectl/pkg/util/i18n/i18n.go:60 2 0x000000000592780f in k8s.io/kubectl/pkg/util/i18n.lazyLoadTranslations.func1 at ./staging/src/k8s.io/kubectl/pkg/util/i18n/i18n.go:191 3 0x0000000001b876e8 in sync.(*Once).doSlow at /nvme/gopath/go-1.24.0/src/sync/once.go:78 4 0x0000000001b8753e in sync.(*Once).Do at /nvme/gopath/go-1.24.0/src/sync/once.go:69 5 0x0000000005927565 in k8s.io/kubectl/pkg/util/i18n.lazyLoadTranslations at ./staging/src/k8s.io/kubectl/pkg/util/i18n/i18n.go:187 6 0x00000000059275cd in k8s.io/kubectl/pkg/util/i18n.T at ./staging/src/k8s.io/kubectl/pkg/util/i18n/i18n.go:201 7 0x000000000599fb6d in k8s.io/kubectl/pkg/cmd/apiresources.init at :1 8 0x0000000001b41bf4 in runtime.doInit1 at /nvme/gopath/go-1.24.0/src/runtime/proc.go:7350 9 0x0000000001b6bf8a in runtime.doInit at /nvme/gopath/go-1.24.0/src/runtime/proc.go:7317 10 0x0000000001b33910 in runtime.main at /nvme/gopath/go-1.24.0/src/runtime/proc.go:254 11 0x0000000001b72881 in runtime.goexit at /nvme/gopath/go-1.24.0/src/runtime/asm_amd64.s:1700 During init, klog verbosity is either zero (making the log call redundant because it doesn't print anything) or some other init function reconfigures logging, in which case the output is potentially confusing because it is not guaranteed that logging is reconfigured before the log call is invoked. In other scenarios, flag parsing might switch from klog text format to something else entirely, which then leads to a mixture of text and e.g. JSON output. In general, code running during init should not log. Kubernetes-commit: 0276769c2c85e14902f39760abce82512aa6b120 --- pkg/util/i18n/i18n.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/util/i18n/i18n.go b/pkg/util/i18n/i18n.go index d850b283d..8b8481c7b 100644 --- a/pkg/util/i18n/i18n.go +++ b/pkg/util/i18n/i18n.go @@ -154,7 +154,6 @@ func LoadTranslations(root string, getLanguageFn func() string) error { fmt.Sprintf("%s/%s/LC_MESSAGES/k8s.mo", root, langStr), } - klog.V(3).Infof("Setting language to %s", langStr) // TODO: list the directory and load all files. buf := new(bytes.Buffer) w := zip.NewWriter(buf)