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

Fix hyperkube flag parsing #25512

Merged
merged 1 commit into from
May 22, 2016

Conversation

colhom
Copy link

@colhom colhom commented May 11, 2016

Hyperkube flag parsing was not playing nicely with kubectl command and sub-commands. This PR addresses that problem, and adds some tests which exercise hyperkube dispatching to nested cobra commands.

\cc @aaronlevy @kbrwn @mumoshu

fixes #24088

Analytics

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@k8s-bot
Copy link

k8s-bot commented May 11, 2016

Can one of the admins verify that this patch is reasonable to test? If so, please reply "ok to test".
(Note: "add to whitelist" is no longer supported. Please update configurations in kubernetes/test-infra/jenkins/job-configs/kubernetes-jenkins-pull instead.)

This message may repeat a few times in short succession due to jenkinsci/ghprb-plugin#292. Sorry.

Otherwise, if this message is too spammy, please complain to ixdy.

2 similar comments
@k8s-bot
Copy link

k8s-bot commented May 11, 2016

Can one of the admins verify that this patch is reasonable to test? If so, please reply "ok to test".
(Note: "add to whitelist" is no longer supported. Please update configurations in kubernetes/test-infra/jenkins/job-configs/kubernetes-jenkins-pull instead.)

This message may repeat a few times in short succession due to jenkinsci/ghprb-plugin#292. Sorry.

Otherwise, if this message is too spammy, please complain to ixdy.

@k8s-bot
Copy link

k8s-bot commented May 11, 2016

Can one of the admins verify that this patch is reasonable to test? If so, please reply "ok to test".
(Note: "add to whitelist" is no longer supported. Please update configurations in kubernetes/test-infra/jenkins/job-configs/kubernetes-jenkins-pull instead.)

This message may repeat a few times in short succession due to jenkinsci/ghprb-plugin#292. Sorry.

Otherwise, if this message is too spammy, please complain to ixdy.

@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. release-note-label-needed labels May 11, 2016
@colhom
Copy link
Author

colhom commented May 11, 2016

@k8s-bot I signed it!

@thockin thockin assigned mikedanese and unassigned thockin May 12, 2016
@thockin
Copy link
Member

thockin commented May 12, 2016

I'm assigning to to Mike semi-randomly

@bgrant0607 bgrant0607 added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-label-needed labels May 12, 2016
@bgrant0607
Copy link
Member

ok to test

@bgrant0607
Copy link
Member

See also #22737

cc @ingvagabund

@bgrant0607 bgrant0607 assigned jbeda and unassigned mikedanese May 12, 2016
@ingvagabund
Copy link
Contributor

@colhom I am definitely +1 for the hyperkube_test.go.

if serverName == hk.Name {
args = args[1:]
Copy link
Contributor

Choose a reason for hiding this comment

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

As long as you run hyperkube kubectl, this should not matter. Why movin 2 lines higher?

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks to perhaps break things when you softlink kubectl to the hyperkube binary. Have you tested that?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Author

Choose a reason for hiding this comment

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

Ironically enough, this was actually a fix to make softlinking work better :) I've tested it.

There's no reason to pass the command arg to any of the Server Run blocks . In particular, since kubectl is now a Cobra command, it requires that if args[0] is not a flag, it match the command name exactly. In the case of a softlink, it's possible thats args[0] will be for example /usr/bin/kubectl, and the Cobra command will complain. This removes that possibility.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah! Looking at the documentation for pflags.FlagSet.Parse it looks like the args should not contain the command name. That would imply that we were doing it wrong before when the command name was being included. interspersed defaulting to true must have covered our sins.

Copy link
Author

Choose a reason for hiding this comment

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

Yep, that's very true!

}
os.Exit(0)
return nil
cmd.SetArgs(args)
Copy link
Contributor

Choose a reason for hiding this comment

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

if we don't muck with args above, this should be args[1:]

Copy link
Author

Choose a reason for hiding this comment

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

Depending on whether or not it's a softlink (os.Args[0] == "hyperkube"), it's either os.Args[1:] or os.Args[2:]. It's kind of nice to let the hyperkube server deal with that logic and sub-servers can just assume that their args list starts with the first relevant flag. This would easily support, for example, nesting servers in servers.

@jbeda
Copy link
Contributor

jbeda commented May 12, 2016

I'm in favor of integrating this with the cobra command structure (I looked at it originally but found it a forced fit) but we need to make sure we don't change behavior of existing commands. Also, need to make sure we don't get divergent implementations between the hyperkube version and the stand along version of kubectl.

@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 12, 2016
@jbeda
Copy link
Contributor

jbeda commented May 12, 2016

Looks good to me.

@ingvagabund, what are your thoughts?

Honestly, I lean toward merging both changes. The cobra stuff does enough fancy flag parsing that it makes sense to let it do it. It is a decent service for the rest of the servers.

Also, we need to figure out what is going on with the CLA for @colhom. I think you need to respond with I signed it! without any other text. Apparently the googlebot is picky.

@colhom
Copy link
Author

colhom commented May 12, 2016

I signed it!

@k8s-github-robot
Copy link

@k8s-bot test this issue: #IGNORE

Tests have been pending for 24 hours

@k8s-bot
Copy link

k8s-bot commented May 21, 2016

GCE e2e build/test passed for commit fd1771e.

@jbeda
Copy link
Contributor

jbeda commented May 22, 2016

I believe this is not merged because it isn't marked for 1.3. @bgrant0607 -- what is the criteria/process for that? I don't see it linked off of the 1.3 release wiki page or obvious from kubernetes-dev chatter.

@luxas luxas added this to the v1.3 milestone May 22, 2016
@luxas
Copy link
Member

luxas commented May 22, 2016

@jbeda I added it to the v1.3 milestone.
This will be merged although it doesn't have the milestone attached to it, but having a milestone adds a little more priority to it
It's just waiting to be on the top of the queue

@k8s-github-robot
Copy link

@k8s-bot test this [submit-queue is verifying that this PR is safe to merge]

@k8s-bot
Copy link

k8s-bot commented May 22, 2016

GCE e2e build/test passed for commit fd1771e.

@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit 8e81025 into kubernetes:master May 22, 2016
@jbeda
Copy link
Contributor

jbeda commented May 22, 2016

Thanks @luxas!

@colhom
Copy link
Author

colhom commented May 26, 2016

@mikedanese what do you think about a cherrypick-candidate label?

@colhom
Copy link
Author

colhom commented May 26, 2016

\cc @jbeda

@roberthbailey
Copy link
Contributor

@colhom I assume you are asking about cherry picking into 1.2 (and that the 1.3 milestone was added to get through the submit queue). Is that correct?

@colhom
Copy link
Author

colhom commented Jun 2, 2016

@roberthbailey that is correct.

@roberthbailey roberthbailey modified the milestones: v1.2, v1.3 Jun 2, 2016
@roberthbailey roberthbailey added the cherry-pick-approved Indicates a cherry-pick PR into a release branch has been approved by the release branch manager. label Jun 2, 2016
@roberthbailey
Copy link
Contributor

@colhom I've adjusted the milestone label to indicate where you want it cherry picked to. Please send a cherry pick PR for the 1.2 release branch.

@colhom
Copy link
Author

colhom commented Jun 2, 2016

@roberthbailey cherry pick PR is up: #26754

roberthbailey added a commit that referenced this pull request Jun 17, 2016
…-upstream-release-1.2

Automated cherry pick of #25512
@roberthbailey
Copy link
Contributor

This was cherrypicked into 1.2 in #26754. Manually removing the cherrypick candidate label.

shyamjvs pushed a commit to shyamjvs/kubernetes that referenced this pull request Dec 1, 2016
…-of-#25512-upstream-release-1.2

Automated cherry pick of kubernetes#25512
shouhong pushed a commit to shouhong/kubernetes that referenced this pull request Feb 14, 2017
…-of-#25512-upstream-release-1.2

Automated cherry pick of kubernetes#25512
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick-approved Indicates a cherry-pick PR into a release branch has been approved by the release branch manager. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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.

hyperkube + kubectl - unknown flag