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

kubectl: fix deprecation warning bug #46062

Merged

Conversation

alexandercampbell
Copy link
Contributor

@alexandercampbell alexandercampbell commented May 18, 2017

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:

NONE

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.
@k8s-ci-robot
Copy link
Contributor

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.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label May 18, 2017
@k8s-ci-robot
Copy link
Contributor

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 @k8s-bot 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.

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 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 May 18, 2017
@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. release-note-none Denotes a PR that doesn't merit a release note. labels May 18, 2017
@alexandercampbell
Copy link
Contributor Author

@k8s-ci-robot signed CLA

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels May 19, 2017
@pwittrock
Copy link
Member

clever

@pwittrock
Copy link
Member

@k8s-bot ok to test

@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 May 19, 2017
@pwittrock
Copy link
Member

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

@alexandercampbell
Copy link
Contributor Author

@pwittrock awesome, thanks. I was going to ask where tests for this should be written.

@droot
Copy link
Contributor

droot commented May 19, 2017

LGTM

@@ -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)),
Copy link
Contributor

Choose a reason for hiding this comment

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

sweet :)

@k8s-github-robot k8s-github-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 19, 2017
cmd.Hidden = true
return cmd
}

Copy link
Contributor

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)

Copy link
Contributor Author

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.

Copy link
Contributor Author

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!

Alexander Campbell added 3 commits May 19, 2017 10:40
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.
@pwittrock
Copy link
Member

@alexandercampbell Write a PTAL comment when you are ready to have us take another look

@alexandercampbell
Copy link
Contributor Author

Thanks! I will do that as soon as I figure out what's up with the CI.

Copy link
Contributor

@droot droot left a 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"
Copy link
Contributor

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 ?

Copy link
Contributor Author

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.

Copy link
Contributor

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")
}

Copy link
Contributor

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 ?

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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!

Alexander Campbell added 2 commits May 19, 2017 14:20
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.
Copy link
Contributor

@droot droot left a 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"
Copy link
Contributor

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")
}

Copy link
Contributor

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!

@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented May 22, 2017

@alexandercampbell: The following test(s) failed:

Test name Commit Details Rerun command
Jenkins unit/integration 5e1a3fd link @k8s-bot unit test this
Jenkins verification 5e1a3fd link @k8s-bot verify test this
Jenkins kops AWS e2e 5e1a3fd link @k8s-bot kops aws e2e test this
pull-kubernetes-federation-e2e-gce b7cc618 link @k8s-bot pull-kubernetes-federation-e2e-gce test this

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.

@alexandercampbell
Copy link
Contributor Author

I tentatively believe that the tests are green.
PTAL, and let me know if you guys want me to rebase out the extraneous commits.

@pwittrock
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 23, 2017
@pwittrock
Copy link
Member

/approve

@k8s-github-robot
Copy link

[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 /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 23, 2017
@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 46201, 45952, 45427, 46247, 46062)

@k8s-github-robot k8s-github-robot merged commit 644a544 into kubernetes:master May 23, 2017
@alexandercampbell alexandercampbell deleted the correct-deprecation-errors branch May 23, 2017 16:06
dims pushed a commit to dims/kubernetes that referenced this pull request Feb 8, 2018
…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
```
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. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. 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.

None yet

6 participants