Skip to content

fix: opt into fixed klog stderrthreshold behavior#13872

Open
pierluigilenoci wants to merge 1 commit intok3s-io:mainfrom
pierluigilenoci:cs/fix-klog-stderrthreshold
Open

fix: opt into fixed klog stderrthreshold behavior#13872
pierluigilenoci wants to merge 1 commit intok3s-io:mainfrom
pierluigilenoci:cs/fix-klog-stderrthreshold

Conversation

@pierluigilenoci
Copy link
Copy Markdown

Problem

klog's legacy stderrthreshold behavior (kubernetes/klog#432) causes WARNING+ messages to be duplicated on stderr when logtostderr=true, because the legacy stderrthreshold mechanism operates independently of the logtostderr flag.

Solution

Set legacy_stderr_threshold_behavior=false and stderrthreshold=INFO in the existing klog flag loop in pkg/executor/embed/embed.go, alongside the current verbosity (v) flag setting.

  • legacy_stderr_threshold_behavior=false: Opts into the corrected behavior where stderrthreshold is properly respected
  • stderrthreshold=INFO: Preserves the current observable behavior (all log levels visible on stderr) while using the corrected code path

Both flags are set inside the loop (not just once after klog.InitFlags) to match the existing pattern: Kubernetes components re-initialize klog on start, resetting flags to defaults. The loop re-applies desired values every second for the first 2 minutes.

Context

This was originally submitted to rancher/rke2 (#10046), where @brandond correctly pointed out that the actual klog initialization for the process happens here in K3s, not in rke2's pkg/logging/logging.go (which is only used for stripping legacy klog args from kubelet arguments).

cc @brandond — does this look like the right approach?

Set legacy_stderr_threshold_behavior=false and stderrthreshold=INFO
in the klog flag loop alongside the existing verbosity setting.

This addresses the klog bug (kubernetes/klog#432) where WARNING+
messages are duplicated on stderr when logtostderr=true, because
the legacy stderrthreshold mechanism operates independently.

The flags are set inside the existing loop (not just once) to match
the current pattern: Kubernetes components re-initialize klog on
start, resetting flags to defaults. The loop re-applies the desired
values every second for the first 2 minutes.

stderrthreshold=INFO preserves current behavior (all levels visible
on stderr) while using the corrected code path.

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
@pierluigilenoci
Copy link
Copy Markdown
Author

Hi @brandond — this PR applies the klog stderrthreshold fix to pkg/executor/embed/embed.go as you suggested in rancher/rke2#10046. Would you be able to review when you get a chance? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant