Skip to content

Add klog-verbosity flag to config-logging ConfigMap#9035

Open
Ankitsinghsisodya wants to merge 8 commits intoknative:mainfrom
Ankitsinghsisodya:feat/klog-verbosity
Open

Add klog-verbosity flag to config-logging ConfigMap#9035
Ankitsinghsisodya wants to merge 8 commits intoknative:mainfrom
Ankitsinghsisodya:feat/klog-verbosity

Conversation

@Ankitsinghsisodya
Copy link
Copy Markdown
Contributor

Summary

Fixes #8706

  • Adds klog-verbosity key to config-logging ConfigMap (default "0") to control klog verbosity for Kubernetes client-go internals
  • ConfigMap-based adapters (e.g. ApiServerSource) apply the level at startup and update it live via the existing ConfigMap watcher
  • Env-based adapters read K_KLOG_VERBOSITY env var, which can be injected from the ConfigMap
  • Parsing/validation logic lives in pkg/utils/logging.go with unit tests

Test plan

  • go test ./pkg/utils/... passes (7 new unit tests for valid/invalid/absent values)
  • Deploy ApiServerSource, set klog-verbosity: "5" in config-logging, confirm klog output at verbosity 5 appears in adapter logs
  • Update ConfigMap live, confirm verbosity changes without pod restart

Copilot AI review requested due to automatic review settings April 21, 2026 18:29
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented Apr 21, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Ankitsinghsisodya
Once this PR has been reviewed and has the lgtm label, please assign pierdipi 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

@knative-prow knative-prow Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/test-and-release Test infrastructure, tests or release needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 21, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented Apr 21, 2026

Hi @Ankitsinghsisodya. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support for configuring Kubernetes klog verbosity via the existing config-logging ConfigMap (and via env var for env-configured adapters), so operators can increase client-go/internal Kubernetes logging without code changes.

Changes:

  • Adds klog-verbosity: "0" to the config-logging ConfigMap (core + test manifests).
  • Implements parsing/apply + live update of klog verbosity in pkg/utils/logging.go, wires it into adapter v2 configmap-based and env-based logger setup.
  • Adds unit tests for SetKlogVerbosityFromConfigMap and introduces a new .github/dependabot.yml config.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
config/core/configmaps/logging.yaml Documents and adds the klog-verbosity key to the shipped logging ConfigMap.
test/config/configmaps/logging.yaml Updates test ConfigMap to include klog-verbosity.
pkg/utils/logging.go Adds klog verbosity parsing/apply logic and a ConfigMap watcher callback.
pkg/utils/logging_test.go Unit tests for valid/invalid/absent verbosity values.
pkg/adapter/v2/configurator_configmap.go Applies initial klog verbosity from ConfigMap and watches for live updates.
pkg/adapter/v2/config.go Adds K_KLOG_VERBOSITY env support and applies it when constructing the logger.
.github/dependabot.yml Adds weekly GitHub Actions Dependabot updates configuration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/utils/logging.go Outdated
Comment thread .github/dependabot.yml Outdated
Comment thread pkg/utils/logging.go Outdated
Comment thread pkg/utils/logging.go Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

❌ Patch coverage is 82.22222% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 51.12%. Comparing base (32bc524) to head (40ba684).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
pkg/utils/logging.go 86.20% 2 Missing and 2 partials ⚠️
pkg/adapter/v2/config.go 0.00% 1 Missing and 1 partial ⚠️
pkg/adapter/v2/configurator_configmap.go 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9035      +/-   ##
==========================================
+ Coverage   51.07%   51.12%   +0.05%     
==========================================
  Files         409      409              
  Lines       21999    22042      +43     
==========================================
+ Hits        11236    11270      +34     
- Misses       9903     9905       +2     
- Partials      860      867       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Exposes klog verbosity level (used by k8s client-go) via the
config-logging ConfigMap under the klog-verbosity key. Adapters
using ConfigMap-based logging apply the level on startup and update
it dynamically via the existing ConfigMap watcher. Env-based adapters
read K_KLOG_VERBOSITY injected from the ConfigMap.

Fixes: knative#8706
- Use package-level FlagSet (init once, reuse) instead of creating new
  FlagSet + calling klog.InitFlags on every ConfigMap update
- Combine int validation with range check (0-9); drop redundant Atoi
- Only emit INFO log when verbosity actually changes to non-zero value
- Inject K_KLOG_VERBOSITY env var from ConfigWatcher.ToEnvVars() so
  env-based adapters receive it via the reconciler (fixes dead-code path)
- Add test coverage for UpdateKlogVerbosityFromConfigMap (all log paths)
- Add out-of-range and negative test cases for SetKlogVerbosityFromConfigMap
- Remove "0" short-circuit so operators can reset verbosity after raising it
- Guard klogFlagSet.Set with sync.Mutex — flag.FlagSet.Set is not goroutine-safe
- Call SetKlogVerbosityFromConfigMap in updateFromLoggingConfigMap so the
  controller/reconciler process applies klog verbosity to its own output
- Add K_KLOG_VERBOSITY to expected env vars in apiserversource and
  pingsource receive adapter tests (EmptyVarsGenerator now returns 3 vars)
- Promote k8s.io/klog/v2 from indirect to direct in go.mod
@Ankitsinghsisodya
Copy link
Copy Markdown
Contributor Author

@creydr can you please run /retest? I think these these test cases are flaky.

Return whether verbosity was actually applied so callers don't need to
re-implement the no-op check. UpdateKlogVerbosityFromConfigMap now
branches on the returned bool instead of duplicating the level != "" &&
level != "0" guard. Three callers that only need the error use _, err :=.
@Ankitsinghsisodya Ankitsinghsisodya force-pushed the feat/klog-verbosity branch 2 times, most recently from aa69fb2 to d2f9943 Compare April 22, 2026 19:55
Copy link
Copy Markdown
Member

@creydr creydr left a comment

Choose a reason for hiding this comment

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

Thanks for working on this.
I left a few comments

Comment thread pkg/adapter/v2/config.go Outdated
Comment thread pkg/utils/logging.go Outdated
Comment thread pkg/reconciler/source/config_watcher.go Outdated
Replace SetKlogVerbosityFromConfigMap with a direct SetKlogVerbosity function that simplifies verbosity application. Update related calls in ConfigWatcher and tests to reflect this change, ensuring proper logging behavior for zero values. This refactor enhances clarity and reduces redundancy in the logging configuration process.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/test-and-release Test infrastructure, tests or release needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. 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.

Add flag to enable KLOG verbosity levels

3 participants