Skip to content

dnsmasq-nanny: honor -stderrthreshold flag via klog v2.140.0#763

Closed
pierluigilenoci wants to merge 1 commit into
kubernetes:masterfrom
pierluigilenoci:fix/honor-stderrthreshold
Closed

dnsmasq-nanny: honor -stderrthreshold flag via klog v2.140.0#763
pierluigilenoci wants to merge 1 commit into
kubernetes:masterfrom
pierluigilenoci:fix/honor-stderrthreshold

Conversation

@pierluigilenoci
Copy link
Copy Markdown
Member

Summary

klog v2 defaults -logtostderr=true, which silently overrides -stderrthreshold. This makes it impossible to filter log output by severity level using the -stderrthreshold flag in dnsmasq-nanny.

klog v2.140.0 (kubernetes/klog#432) introduced the legacy_stderr_threshold_behavior feature flag that fixes this long-standing behavior (upstream issue: kubernetes/klog#212).

Changes

  • Bump k8s.io/klog/v2 from v2.130.1 to v2.140.0
  • cmd/dnsmasq-nanny/main.go: After klog.InitFlags(nil), set legacy_stderr_threshold_behavior=false and stderrthreshold=INFO so that -stderrthreshold is honored even when -logtostderr=true (the default)

Why

Without this fix, passing -stderrthreshold=WARNING (or any other severity) to dnsmasq-nanny has no effect because klog's legacy behavior copies all log output to stderr regardless of the threshold. The new klog flag restores the expected semantics: only messages at or above the configured severity threshold are written to stderr.

Testing

  • go build ./cmd/dnsmasq-nanny/... succeeds
  • go build ./cmd/kube-dns/... succeeds
  • go build ./cmd/sidecar/... succeeds
  • (node-cache has a pre-existing build failure on non-Linux due to iptables dependency — unrelated to this change)

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 24, 2026
@k8s-ci-robot k8s-ci-robot requested a review from bowei April 24, 2026 08:00
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: pierluigilenoci
Once this PR has been reviewed and has the lgtm label, please assign mrhohn for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 24, 2026
@pierluigilenoci pierluigilenoci marked this pull request as ready for review May 2, 2026 16:28
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 2, 2026
@pierluigilenoci
Copy link
Copy Markdown
Member Author

Hi — friendly follow-up. Would you be able to review this PR when you get a chance? Thank you!

Copy link
Copy Markdown
Collaborator

@DamianSawicki DamianSawicki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This repository is planned to be archived (#759 (comment), kubernetes/kubernetes#137556). Consider migrating away from dnsmasq-nanny or arguing against archiving.

Comment thread cmd/dnsmasq-nanny/main.go Outdated
// when -logtostderr=true (the default).
// Ref: kubernetes/klog#212, kubernetes/klog#432
flag.Set("legacy_stderr_threshold_behavior", "false") //nolint:errcheck
flag.Set("stderrthreshold", "INFO") //nolint:errcheck
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems cmd/dnsmasq-nanny/main.go has not used stderrthreshold before, and it's only proposed in the present PR. I suppose the behavior without these two new flags was to log everything.

  • In order not to change this existing behavior, stderrthreshold should probably default to WARNING.
  • In order to allow the user to adjust filtering to their preferences, stderrthreshold should be configurable and not hardcoded.

klog v2 defaults -logtostderr=true, which silently overrides
-stderrthreshold. This makes it impossible to filter log output by
severity level using the -stderrthreshold flag.

klog v2.140.0 (kubernetes/klog#432) introduced the
legacy_stderr_threshold_behavior feature flag that fixes this behavior
(upstream issue: kubernetes/klog#212).

Changes:
- Bump k8s.io/klog/v2 from v2.130.1 to v2.140.0
- After klog.InitFlags(nil), set legacy_stderr_threshold_behavior=false
  and stderrthreshold=INFO so that -stderrthreshold is honored even
  when -logtostderr=true

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
Signed-off-by: Pierluigi Lenoci <pierluigilenoci@gmail.com>
@pierluigilenoci pierluigilenoci force-pushed the fix/honor-stderrthreshold branch from c1584a8 to 325010a Compare May 18, 2026 21:33
@pierluigilenoci
Copy link
Copy Markdown
Member Author

Thanks for the review @DamianSawicki, and for the context on the archival plans (#759, kubernetes/kubernetes#137556) — much appreciated.

I've addressed the technical feedback:

  • Changed the default stderrthreshold from INFO to WARNING to better preserve the existing log volume going to stderr (less noisy than logging everything at INFO).
  • The threshold remains user-configurable via the standard -stderrthreshold klog flag (the flag.Set call only sets the initial default; flag.Parse will honor any value passed on the command line).

Re: archival — happy to defer to your judgement on whether this PR is still worth landing given the deprecation timeline. If you'd prefer to close it, no objection on my side. Otherwise, I'm available if any further changes are needed.

@pierluigilenoci
Copy link
Copy Markdown
Member Author

Thanks for the review and context, @DamianSawicki. Given that the repo is heading toward archival (#759, kubernetes/kubernetes#137556) and dnsmasq-nanny usage should be migrated away from, it makes no sense to land this fix here. Closing this out. Best of luck with the migration work!

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

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants