Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed flag name underscore warning to prevent duplicate warnings and avoid recommending invalid flag name #103852

Merged
merged 1 commit into from Aug 19, 2021

Conversation

brianpursley
Copy link
Member

@brianpursley brianpursley commented Jul 22, 2021

What type of PR is this?

/kind bug

What this PR does / why we need it:

If you use kubectl with a flag name that has underscores as a word separator, but is an invalid flag name, kubectl recommends you use the invalid flag name with - as word separator. It also writes the same warning out numerous times.

Example below tells me foo_bar is deprecated (not true, it is an invalid flag) and to use a flag called foo-bar even though that obviously is not a valid flag.

$ kubectl run nginx --image=nginx --foo_bar
W0722 12:20:18.905885  381541 flags.go:39] foo_bar is DEPRECATED and will be removed in a future version. Use foo-bar instead.
W0722 12:20:18.906154  381541 flags.go:39] foo_bar is DEPRECATED and will be removed in a future version. Use foo-bar instead.
W0722 12:20:18.906204  381541 flags.go:39] foo_bar is DEPRECATED and will be removed in a future version. Use foo-bar instead.
W0722 12:20:18.906408  381541 flags.go:39] foo_bar is DEPRECATED and will be removed in a future version. Use foo-bar instead.
W0722 12:20:18.906478  381541 flags.go:39] foo_bar is DEPRECATED and will be removed in a future version. Use foo-bar instead.
W0722 12:20:18.906522  381541 flags.go:39] foo_bar is DEPRECATED and will be removed in a future version. Use foo-bar instead.
W0722 12:20:18.906579  381541 flags.go:39] foo_bar is DEPRECATED and will be removed in a future version. Use foo-bar instead.
W0722 12:20:18.906612  381541 flags.go:39] foo_bar is DEPRECATED and will be removed in a future version. Use foo-bar instead.
W0722 12:20:18.906645  381541 flags.go:39] foo_bar is DEPRECATED and will be removed in a future version. Use foo-bar instead.
W0722 12:20:18.906699  381541 flags.go:39] foo_bar is DEPRECATED and will be removed in a future version. Use foo-bar instead.
Error: unknown flag: --foo_bar
See 'kubectl run --help' for usage.

The message saying that all flags containing an underscore is deprecated is 5+ years old. However we don't really want to break someone who happens to be using a flag named this way.

The approach discussed during the 7/21 sig-cli bug scrub meeting is to allow the conversion to remain, but change the warning message to not say anything about deprecation and not make any recommendation about the flag name because we don't know at this point in the code execution whether the flag is valid or invalid.

The conversion between _ and - will still occur as it has to preserve compatibility.

This PR also prevents writing the same flag name warning out multiple times.

New output after this PR:

$ kubectl run nginx --image=nginx --foo_bar
W0722 12:38:42.412943  386533 flags.go:42] using an underscore in a flag name is not supported. foo_bar has been converted to foo-bar.
Error: unknown flag: --foo_bar
See 'kubectl run --help' for usage.

Which issue(s) this PR fixes:

Fixes kubernetes/kubectl#1078

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Fixed bug where kubectl would emit duplicate warning messages for flag names that contain an underscore and recommend using a nonexistent flag in some cases

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


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. 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. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jul 22, 2021
@brianpursley
Copy link
Member Author

/cc @eddiezane @seans3

@fedebongio
Copy link
Contributor

/remove-sig api-machinery
/sig cli

@k8s-ci-robot k8s-ci-robot added sig/cli Categorizes an issue or PR as relevant to SIG CLI. and removed sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. labels Jul 22, 2021
Copy link
Member

@eddiezane eddiezane left a comment

Choose a reason for hiding this comment

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

Nice!

/lgtm

"testing"
)

type FakeLogger struct {
Copy link
Member

Choose a reason for hiding this comment

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

I looked (could have missed something) and was surprised that this doesn't exist as a reusable thing for tests.

Might be a good PR to add to klog?

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 22, 2021
@eddiezane
Copy link
Member

/assign @stealthybox
/priority backlog
/triage accepted

@k8s-ci-robot k8s-ci-robot added priority/backlog Higher priority than priority/awaiting-more-evidence. triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Aug 4, 2021
Copy link
Contributor

@soltysh soltysh 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

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: brianpursley, eddiezane, soltysh

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

The pull request process is described here

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 Aug 19, 2021
@k8s-ci-robot k8s-ci-robot merged commit 3945e35 into kubernetes:master Aug 19, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.23 milestone Aug 19, 2021
@brianpursley brianpursley deleted the kubectl-1078 branch February 2, 2023 01:22
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/backlog Higher priority than priority/awaiting-more-evidence. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kubectl apply -k erroneously recommends unsupported "--load-restrictor" flag
6 participants