Skip to content

Fix(log flags): handle log streams correctly #8836

Merged
k8s-ci-robot merged 1 commit intokubernetes:masterfrom
lxuan94-pp:xl/klog-file
Jan 22, 2026
Merged

Fix(log flags): handle log streams correctly #8836
k8s-ci-robot merged 1 commit intokubernetes:masterfrom
lxuan94-pp:xl/klog-file

Conversation

@lxuan94-pp
Copy link
Copy Markdown
Contributor

@lxuan94-pp lxuan94-pp commented Nov 20, 2025

What type of PR is this?

/kind bug

Optionally add one or more of the following kinds if applicable:
/kind regression

What this PR does / why we need it:

After upgrading to Autoscaler v1.30.x, the log file no longer exists and is not created. This PR fixes the issue without modifying component-base or klog in vendor

Which issue(s) this PR fixes:

Fixes #7842

Special notes for your reviewer:

Persist the behavior from klog:

commandLine.StringVar(&logging.logFile, "log_file", "", "If non-empty, use this log file (no effect when -logtostderr=true)")
commandLine.BoolVar(&logging.toStderr, "logtostderr", true, "log to standard error instead of files")
commandLine.BoolVar(&logging.alsoToStderr, "alsologtostderr", false, "log to standard error as well as files (no effect when -logtostderr=true)")

Does this PR introduce a user-facing change?

None

For more information on release notes see: https://git.k8s.io/community/contributors/guide/release-notes.md
-->

Fixed an issue where the --log-file option stopped working. Logging now correctly writes to the specified file in addition to standard error.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

Tested in OCI cluster
Screenshot 2025-11-19 at 8 12 05 PM
Screenshot 2025-11-19 at 8 13 49 PM
Screenshot 2025-11-19 at 8 19 51 PM


@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. kind/regression Categorizes issue or PR as related to a regression from a prior release. do-not-merge/needs-area Indicates that a PR should not merge because it lacks an area label. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Nov 20, 2025
@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Nov 20, 2025
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Hi @lxuan94-pp. Thanks for your PR.

I'm waiting for a github.com 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. Regular contributors should join the org to skip this step.

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.

@k8s-ci-robot k8s-ci-robot added area/cluster-autoscaler Issues or PRs related to the Cluster Autoscaler component size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed do-not-merge/needs-area Indicates that a PR should not merge because it lacks an area label. labels Nov 20, 2025
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 20, 2025
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 20, 2025
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Nov 20, 2025
Comment thread cluster-autoscaler/config/flags/klog_flags.go
Comment thread cluster-autoscaler/go.sum Outdated
sigs.k8s.io/structured-merge-diff/v6 v6.3.0/go.mod h1:M3W8sfWvn2HhQDIbGWj3S099YozAsymCo/wrT5ohRUE=
sigs.k8s.io/yaml v1.6.0 h1:G8fkbMSAFqgEFgh4b1wmtzDnioxFCUgTZhlbj5P9QYs=
sigs.k8s.io/yaml v1.6.0/go.mod h1:796bPqUfzR/0jLAl6XjHl3Ck7MiyVv8dbTdyT3/pMf4=
sigs.k8s.io/yaml v1.6.0/go.mod h1:796bPqUfzR/0jLAl6XjHl3Ck7MiyVv8dbTdyT3/pMf4= No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please remove this newline change, thank you!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think it was changed by go mod tidy I ran, which caused different line endings. I have reverted it to the master version.

// default: both to stderr
var infoW, errW io.Writer = os.Stderr, os.Stderr

if logFilePath != "" && !logToStderr {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we drop the -alsologtostderr option?

If just --log-file is set but no --logtostderr (default to false), then we configure logging for redirecting both info and err logging to the configured log file.

If --log-file is set and --logtostderr=true we intrepret that as:

  • configure logging for redirecting both info and err logging to the configured log file
  • also tee log info and err output to stderr

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We can drop -alsologtostderr if we want to follow this model, but just to note: klog’s guidance is that --log-file and --alsologtostderr are ignored when --logtostderr=true

commandLine.StringVar(&logging.logFile, "log_file", "", "If non-empty, use this log file (no effect when -logtostderr=true)")
commandLine.BoolVar(&logging.toStderr, "logtostderr", true, "log to standard error instead of files")
commandLine.BoolVar(&logging.alsoToStderr, "alsologtostderr", false, "log to standard error as well as files (no effect when -logtostderr=true)")

from klog/v2 https://pkg.go.dev/k8s.io/klog/v2#klog.go

I’m fine proceeding with your proposed interpretation, as long as we’re aware it slightly diverges from the standard klog usage pattern. Let me know if you want me to update the flags accordingly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jackfrancis Please advise on how we should proceed, and I can update or keep the change accordingly.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK, probably best not to overthink and follow that guidance

@jackfrancis
Copy link
Copy Markdown
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Nov 21, 2025
@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Nov 21, 2025
@jackfrancis
Copy link
Copy Markdown
Contributor

/test pull-cluster-autoscaler-e2e-azure-master

@lxuan94-pp
Copy link
Copy Markdown
Contributor Author

Hi @jackfrancis, pls check the comment #8836 (comment) and advise on how we should proceed. IMO I want to keep the current behavior to align with klog.

@lxuan94-pp
Copy link
Copy Markdown
Contributor Author

Bumping #8836 (comment)
cc:@jackfrancis

Copy link
Copy Markdown
Contributor

@jackfrancis jackfrancis left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

// default: both to stderr
var infoW, errW io.Writer = os.Stderr, os.Stderr

if logFilePath != "" && !logToStderr {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK, probably best not to overthink and follow that guidance

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 22, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jackfrancis, lxuan94-pp

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

The pull request process is described 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 the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 22, 2026
@k8s-ci-robot k8s-ci-robot merged commit 872d31f into kubernetes:master Jan 22, 2026
9 checks passed
@jackfrancis
Copy link
Copy Markdown
Contributor

/cherry-pick cluster-autoscaler-release-1.32

@k8s-infra-cherrypick-robot
Copy link
Copy Markdown

@jackfrancis: new pull request created: #9101

Details

In response to this:

/cherry-pick cluster-autoscaler-release-1.32

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.

@jackfrancis
Copy link
Copy Markdown
Contributor

/cherry-pick cluster-autoscaler-release-1.33
/cherry-pick cluster-autoscaler-release-1.34
/cherry-pick cluster-autoscaler-release-1.35

@k8s-infra-cherrypick-robot
Copy link
Copy Markdown

@jackfrancis: new pull request created: #9102

Details

In response to this:

/cherry-pick cluster-autoscaler-release-1.33
/cherry-pick cluster-autoscaler-release-1.34
/cherry-pick cluster-autoscaler-release-1.35

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.

@k8s-infra-cherrypick-robot
Copy link
Copy Markdown

@jackfrancis: new pull request created: #9103

Details

In response to this:

/cherry-pick cluster-autoscaler-release-1.33
/cherry-pick cluster-autoscaler-release-1.34
/cherry-pick cluster-autoscaler-release-1.35

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.

@k8s-infra-cherrypick-robot
Copy link
Copy Markdown

@jackfrancis: new pull request created: #9104

Details

In response to this:

/cherry-pick cluster-autoscaler-release-1.33
/cherry-pick cluster-autoscaler-release-1.34
/cherry-pick cluster-autoscaler-release-1.35

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.

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/cluster-autoscaler Issues or PRs related to the Cluster Autoscaler component cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. kind/regression Categorizes issue or PR as related to a regression from a prior release. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

Cluster autoscaler argument --log-file is no longer working after v1.30.x

5 participants