-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
kubectl: fix deprecation warning bug #46062
kubectl: fix deprecation warning bug #46062
Conversation
Some kubectl commands were deprecated but would fail to print the correct warning message when a flag was given before the command name. # Correctly prints the warning that "resize" is deprecated and # "scale" is now preferred. kubectl scale [...] # Should print the same warning but no warning is printed. kubectl --v=1 scale [...] This was due to a fragile check on os.Args[1]. This commit implements a new function deprecatedCmd() that is used to construct new "passthrough" commands which are marked as deprecated and hidden. Note that there is an existing "filters" system that may be preferable to the system created in this commit. I'm not sure why the "filters" array was not used for all deprecated commands in the first place.
Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please follow instructions at https://github.com/kubernetes/kubernetes/wiki/CLA-FAQ to sign the CLA. It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.
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/test-infra repository. I understand the commands that are listed here. |
Hi @alexandercampbell. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with 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/test-infra repository. I understand the commands that are listed here. |
@k8s-ci-robot signed CLA |
clever |
@k8s-bot ok to test |
Looks good. Are there existing tests for this? If not, add some to https://github.com/kubernetes/kubernetes/blob/master/hack/make-rules/test-cmd-util.sh |
@pwittrock awesome, thanks. I was going to ask where tests for this should be written. |
LGTM |
pkg/kubectl/cmd/cmd.go
Outdated
@@ -284,6 +284,7 @@ func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob | |||
NewCmdCreate(f, out, err), | |||
NewCmdExposeService(f, out), | |||
NewCmdRun(f, in, out, err), | |||
deprecatedCmd("run-container", NewCmdRun(f, in, out, err)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sweet :)
cmd.Hidden = true | ||
return cmd | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was thinking more about the unit test for this function. We can write a unit test which wraps a NoOp cobra.Command and captures the "deprecated" string in the output. Thoughts ? (happy to discuss in person)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me. Will look at that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unit test written. Thanks for the suggestion!
This will clear up some of the confusion around the deprecatedCmd / Deprecated function.
There's no reason to export this function, so I've made it private.
@alexandercampbell Write a PTAL comment when you are ready to have us take another look |
Thanks! I will do that as soon as I figure out what's up with the CI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took a quick look at the unit test and have a few comments.
@@ -25,9 +25,12 @@ import ( | |||
"net/http" | |||
"os" | |||
"reflect" | |||
stdstrings "strings" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any advantage of aliasing "strings" pkg here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name strings
is taken by k8s.io/kubernetes/pkg/util/strings
which is also imported in this package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. makes sense.
t.Errorf("original command has name %q, expected %q", | ||
original.Name(), "print") | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm... I was thinking more along the lines of....invoking the deprecated command and then grabbing the output and check if deprecated warning is being emitted ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also include the output writer as a dependency defaulted to stdout, but overridden the test, and see what bytes that it writes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the test to include more coverage-- see 5e1a3fd.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just looked at it that commit. Looks good to me!
Two new behaviors are tested: 1. The output message that deprecatedAlias gives when it is called must include the word "deprecatated" and the name of the new function that the user should use instead. 2. The correct function must be called by the alias (alias should "fall back" to the functionality of the original.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
@@ -25,9 +25,12 @@ import ( | |||
"net/http" | |||
"os" | |||
"reflect" | |||
stdstrings "strings" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. makes sense.
t.Errorf("original command has name %q, expected %q", | ||
original.Name(), "print") | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just looked at it that commit. Looks good to me!
Additionally, move the test down to ensure definition order matches run order.
@alexandercampbell: The following test(s) failed:
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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/test-infra repository. I understand the commands that are listed here. |
I tentatively believe that the tests are green. |
/lgtm |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alexandercampbell, pwittrock
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
Automatic merge from submit-queue (batch tested with PRs 46201, 45952, 45427, 46247, 46062) |
…precation-errors Automatic merge from submit-queue (batch tested with PRs 46201, 45952, 45427, 46247, 46062) kubectl: fix deprecation warning bug **What this PR does / why we need it**: Some kubectl commands were deprecated but would fail to print the correct warning message when a flag was given before the command name. # Correctly prints the warning that "resize" is deprecated and # "scale" is now preferred. kubectl resize [...] # Should print the same warning but no warning is printed. kubectl --v=1 resize [...] This was due to a fragile check on os.Args[1]. This commit implements a new function deprecatedCmd() that is used to construct new "passthrough" commands which are marked as deprecated and hidden. Note that there is an existing "filters" system that may be preferable to the system created in this commit. I'm not sure why the "filters" array was not used for all deprecated commands in the first place. **Release note**: ```release-note NONE ```
What this PR does / why we need it:
Some kubectl commands were deprecated but would fail to print the
correct warning message when a flag was given before the command name.
This was due to a fragile check on os.Args[1].
This commit implements a new function deprecatedCmd() that is used to
construct new "passthrough" commands which are marked as deprecated and
hidden.
Note that there is an existing "filters" system that may be preferable
to the system created in this commit. I'm not sure why the "filters"
array was not used for all deprecated commands in the first place.
Release note: