-
Notifications
You must be signed in to change notification settings - Fork 40k
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
Fix hyperkube flag parsing #25512
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,21 +19,23 @@ package main | |
import ( | ||
"os" | ||
|
||
"k8s.io/kubernetes/cmd/kubectl/app" | ||
"k8s.io/kubernetes/pkg/kubectl/cmd" | ||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" | ||
) | ||
|
||
func NewKubectlServer() *Server { | ||
cmd := cmd.NewKubectlCommand(cmdutil.NewFactory(nil), os.Stdin, os.Stdout, os.Stderr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So far hyperkube has always collected cmds from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm okay with skipping There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. addressed in followup commit. |
||
localFlags := cmd.LocalFlags() | ||
localFlags.SetInterspersed(false) | ||
|
||
return &Server{ | ||
name: "kubectl", | ||
SimpleUsage: "Kubernetes command line client", | ||
Long: "Kubernetes command line client", | ||
Run: func(s *Server, args []string) error { | ||
os.Args = os.Args[1:] | ||
if err := app.Run(); err != nil { | ||
os.Exit(1) | ||
} | ||
os.Exit(0) | ||
return nil | ||
cmd.SetArgs(args) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Depending on whether or not it's a softlink ( |
||
return cmd.Execute() | ||
}, | ||
flags: localFlags, | ||
} | ||
} |
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.
As long as you run
hyperkube kubectl
, this should not matter. Why movin 2 lines higher?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.
This looks to perhaps break things when you softlink
kubectl
to thehyperkube
binary. Have you tested 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.
+1
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.
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 ifargs[0]
is not a flag, it match the command name exactly. In the case of a softlink, it's possible thatsargs[0]
will be for example/usr/bin/kubectl
, and the Cobra command will complain. This removes that possibility.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.
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 totrue
must have covered our sins.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.
Yep, that's very true!