fix: opt into fixed klog stderrthreshold behavior#10046
fix: opt into fixed klog stderrthreshold behavior#10046pierluigilenoci wants to merge 1 commit intorancher:masterfrom
Conversation
After klog.InitFlags(), set legacy_stderr_threshold_behavior=false and stderrthreshold=INFO so that klog honors the stderrthreshold flag correctly (kubernetes/klog#212). Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
|
I'm curious what effect this will actually have on rke2. All of the Rancher ecosystem uses logrus, so this will only really affect the Kubernetes client-go code and other such common bits that run in the main rke2 process and use klog. What specific change are you hoping to see from this? |
|
Good question! The primary effect is on klog output from the Kubernetes components embedded in rke2 (client-go, api-machinery, etc.). Without this fix, With It's a one-line defensive fix with zero risk of regression, aligned with the upstream guidance in kubernetes/klog#432. |
|
Can you provide an example of the duplicate messages that you're seeing, so that our QA team can validate the fix? Normally we'd want to see this sort of info in an issue, so that we know what the problem is. That's why there's a spot for linking to an issue in the PR template, which you didn't use. |
|
Thank you for the detailed questions, @brandond. You're right that rke2 primarily uses logrus, and the klog output comes from client-go and other Kubernetes libraries embedded in the process. The issue: When Before this change: After this change: That said, I understand this is a preventive fix rather than a critical bug — the duplicate output is a cosmetic issue in log analysis. If you'd prefer I open an issue first for proper tracking, I'm happy to do that. Let me know how you'd like to proceed. |
|
I don't think this is doing what you think it's doing. The flagset inited here is not intended to set up logging for the rke2 process. It is created so that we can use the registered flags to strip legacy klog args from the kubelet args, and set up lumberjack to match. This is literally documented in the code comments. See:
While your change may accidentally do what you want, it's the wrong place to fix it. If you want to change the ACTUAL logging configuration for the rke2 server and agent, setup for those is done in K3s, and should be changed there:
See also: |
|
Thank you for the thorough explanation, @brandond. You're absolutely right — I missed that this flagset is specifically for stripping legacy klog args from kubelet arguments and setting up lumberjack, not for configuring the rke2 process's own logging. Given that context, my change is in the wrong place and wouldn't achieve the intended effect. I'll close this PR. Apologies for the noise, and thank you for taking the time to explain the logging architecture. |
|
@pierluigilenoci am I speaking with a bot? Between ignoring our PR template in favor of your own, and the florid apologetic responses with em-dashes, this all sounds kinda botty. |
|
Not a bot, @brandond — I'm a human developer based in Berlin. Italian is my first language, so I use LLMs to help me write clearer and more readable English. I understand that can make messages sound a bit "polished", but I assure you there's a real person behind every PR. Thank you again for the detailed technical explanation about the flagset scope and the K3s logging setup. That's genuinely useful context. |
|
Also, regarding the PR template — I use |
|
Following your guidance, I've submitted the fix to the correct place in K3s: k3s-io/k3s#13872 The change adds |

Summary
klog.InitFlags(), setlegacy_stderr_threshold_behavior=falseandstderrthreshold=INFOso that klog honors thestderrthresholdflag correctly.stderrthresholdwas effectively ignored.Why
Without this fix, all log messages (including low-severity ones) are written to stderr regardless of the
stderrthresholdsetting. The newlegacy_stderr_threshold_behaviorflag was introduced in klog v2.140.0 to allow consumers to opt into the corrected behavior without breaking existing deployments.The repo's
go.modalready replacesk8s.io/klog/v2withgithub.com/k3s-io/klog/v2 v2.140.0-k3s1, so the flags are available.Test plan
/cc @brandond