Skip to content

Migrate from klog v1 to klog/v2 and honor stderrthreshold#69

Open
pierluigilenoci wants to merge 2 commits intovolcano-sh:masterfrom
pierluigilenoci:fix/migrate-klog-v2-honor-stderrthreshold
Open

Migrate from klog v1 to klog/v2 and honor stderrthreshold#69
pierluigilenoci wants to merge 2 commits intovolcano-sh:masterfrom
pierluigilenoci:fix/migrate-klog-v2-honor-stderrthreshold

Conversation

@pierluigilenoci
Copy link
Copy Markdown

Summary

  • Replace all k8s.io/klog imports with k8s.io/klog/v2 across all non-vendor Go source files
  • Update go.mod to depend on k8s.io/klog/v2 v2.140.0 and run go mod tidy + go mod vendor
  • Configure stderrthreshold=INFO and legacy_stderr_threshold_behavior=false after klog.InitFlags() in the main entry point so that log messages are properly written to stderr

Motivation

k8s.io/klog v1 is deprecated and unmaintained. Migrating to k8s.io/klog/v2 brings bug fixes, better performance, and alignment with the broader Kubernetes ecosystem.

Additionally, klog's default stderrthreshold behavior silently drops INFO/WARNING messages from stderr unless explicitly configured. This patch ensures all log levels are emitted to stderr as expected.

Ref: kubernetes/klog#212, kubernetes/klog#432

Test plan

  • go build ./cmd/kube-dag/... compiles successfully
  • Run existing unit tests: go test ./...
  • Verify klog output appears on stderr at all verbosity levels

Replace all imports of k8s.io/klog with k8s.io/klog/v2, update
go.mod dependencies, and configure stderrthreshold to ensure
log messages are properly written to stderr.

Ref: kubernetes/klog#212, kubernetes/klog#432
Signed-off-by: Pierluigi Lenoci <[email protected]>
@pierluigilenoci
Copy link
Copy Markdown
Author

cc @wackxu @kevin-wangzefeng for review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request upgrades the project to Go 1.21 and migrates the logging infrastructure from klog v1 to v2. The changes include updating imports across multiple packages, refreshing the go.mod and go.sum files, and adding the necessary vendored dependencies. Additionally, the gene-controller main function now explicitly configures klog flags. Feedback was provided to improve error handling when setting these flags to ensure the application does not start with an invalid logging configuration.

Comment on lines +39 to +40
_ = goflag.Set("legacy_stderr_threshold_behavior", "false")
_ = goflag.Set("stderrthreshold", "INFO")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

It's important to check the errors returned by goflag.Set. If these flags fail to set, for example if the flag names change in a future version of klog, the logging behavior will not be as expected. This could make debugging issues in production very difficult. I suggest logging a fatal error if setting these flags fails to ensure the application starts with the correct logging configuration.

Suggested change
_ = goflag.Set("legacy_stderr_threshold_behavior", "false")
_ = goflag.Set("stderrthreshold", "INFO")
if err := goflag.Set("legacy_stderr_threshold_behavior", "false"); err != nil {
klog.Fatalf("failed to set klog flag 'legacy_stderr_threshold_behavior': %v", err)
}
if err := goflag.Set("stderrthreshold", "INFO"); err != nil {
klog.Fatalf("failed to set klog flag 'stderrthreshold': %v", err)
}

Replace discarded error returns (_ = goflag.Set(...)) with
proper error handling that calls klog.Fatalf on failure, so
misconfigured logging flags are surfaced immediately instead
of being silently ignored.

Signed-off-by: Pierluigi Lenoci <[email protected]>
@pierluigilenoci
Copy link
Copy Markdown
Author

Hi @wackxu @kevin-wangzefeng — friendly follow-up on this PR. It migrates the logging from klog v1 to v2 and updates the Go version. All CI checks are passing (DCO passed, tide pending labels as expected).

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