Merge pull request #31333 from xingzhou/kube-25287

Automatic merge from submit-queue

Fixed incomplete kubectl bash completion.

Added bash completion for several kubectl commands.

Fixes #25287
This commit is contained in:
Kubernetes Submit Queue 2016-09-01 10:49:51 -07:00 committed by GitHub
commit c98a1e2416
9 changed files with 60 additions and 15 deletions

View File

@ -55,6 +55,9 @@ var (
func NewCmdAutoscale(f *cmdutil.Factory, out io.Writer) *cobra.Command { func NewCmdAutoscale(f *cmdutil.Factory, out io.Writer) *cobra.Command {
options := &AutoscaleOptions{} options := &AutoscaleOptions{}
validArgs := []string{"deployment", "replicaset", "replicationcontroller"}
argAliases := kubectl.ResourceAliases(validArgs)
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "autoscale (-f FILENAME | TYPE NAME | TYPE/NAME) [--min=MINPODS] --max=MAXPODS [--cpu-percent=CPU] [flags]", Use: "autoscale (-f FILENAME | TYPE NAME | TYPE/NAME) [--min=MINPODS] --max=MAXPODS [--cpu-percent=CPU] [flags]",
Short: "Auto-scale a Deployment, ReplicaSet, or ReplicationController", Short: "Auto-scale a Deployment, ReplicaSet, or ReplicationController",
@ -64,6 +67,8 @@ func NewCmdAutoscale(f *cmdutil.Factory, out io.Writer) *cobra.Command {
err := RunAutoscale(f, out, cmd, args, options) err := RunAutoscale(f, out, cmd, args, options)
cmdutil.CheckErr(err) cmdutil.CheckErr(err)
}, },
ValidArgs: validArgs,
ArgAliases: argAliases,
} }
cmdutil.AddPrinterFlags(cmd) cmdutil.AddPrinterFlags(cmd)
cmd.Flags().String("generator", "horizontalpodautoscaler/v1", "The name of the API generator to use. Currently there is only 1 generator.") cmd.Flags().String("generator", "horizontalpodautoscaler/v1", "The name of the API generator to use. Currently there is only 1 generator.")

View File

@ -102,6 +102,11 @@ __kubectl_get_resource_rc()
__kubectl_parse_get "rc" __kubectl_parse_get "rc"
} }
__kubectl_get_resource_node()
{
__kubectl_parse_get "node"
}
# $1 is the name of the pod we want to get the list of containers inside # $1 is the name of the pod we want to get the list of containers inside
__kubectl_get_containers() __kubectl_get_containers()
{ {
@ -134,15 +139,15 @@ __kubectl_require_pod_and_container()
__custom_func() { __custom_func() {
case ${last_command} in case ${last_command} in
kubectl_get | kubectl_describe | kubectl_delete | kubectl_label | kubectl_stop | kubectl_edit | kubectl_patch |\ kubectl_get | kubectl_describe | kubectl_delete | kubectl_label | kubectl_stop | kubectl_edit | kubectl_patch |\
kubectl_annotate | kubectl_expose) kubectl_annotate | kubectl_expose | kubectl_scale | kubectl_autoscale | kubectl_taint | kubectl_rollout_*)
__kubectl_get_resource __kubectl_get_resource
return return
;; ;;
kubectl_logs) kubectl_logs | kubectl_attach)
__kubectl_require_pod_and_container __kubectl_require_pod_and_container
return return
;; ;;
kubectl_exec) kubectl_exec | kubectl_port-forward | kubectl_top_pod)
__kubectl_get_resource_pod __kubectl_get_resource_pod
return return
;; ;;
@ -150,6 +155,10 @@ __custom_func() {
__kubectl_get_resource_rc __kubectl_get_resource_rc
return return
;; ;;
kubectl_cordon | kubectl_uncordon | kubectl_drain | kubectl_top_node)
__kubectl_get_resource_node
return
;;
*) *)
;; ;;
esac esac

View File

@ -49,6 +49,9 @@ var (
func NewCmdRolloutHistory(f *cmdutil.Factory, out io.Writer) *cobra.Command { func NewCmdRolloutHistory(f *cmdutil.Factory, out io.Writer) *cobra.Command {
options := &HistoryOptions{} options := &HistoryOptions{}
validArgs := []string{"deployment"}
argAliases := kubectl.ResourceAliases(validArgs)
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "history (TYPE NAME | TYPE/NAME) [flags]", Use: "history (TYPE NAME | TYPE/NAME) [flags]",
Short: "View rollout history", Short: "View rollout history",
@ -57,6 +60,8 @@ func NewCmdRolloutHistory(f *cmdutil.Factory, out io.Writer) *cobra.Command {
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
cmdutil.CheckErr(RunHistory(f, cmd, out, args, options)) cmdutil.CheckErr(RunHistory(f, cmd, out, args, options))
}, },
ValidArgs: validArgs,
ArgAliases: argAliases,
} }
cmd.Flags().Int64("revision", 0, "See the details, including podTemplate of the revision specified") cmd.Flags().Int64("revision", 0, "See the details, including podTemplate of the revision specified")

View File

@ -61,6 +61,9 @@ var (
func NewCmdRolloutPause(f *cmdutil.Factory, out io.Writer) *cobra.Command { func NewCmdRolloutPause(f *cmdutil.Factory, out io.Writer) *cobra.Command {
opts := &PauseConfig{} opts := &PauseConfig{}
validArgs := []string{"deployment"}
argAliases := kubectl.ResourceAliases(validArgs)
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "pause RESOURCE", Use: "pause RESOURCE",
Short: "Mark the provided resource as paused", Short: "Mark the provided resource as paused",
@ -78,6 +81,8 @@ func NewCmdRolloutPause(f *cmdutil.Factory, out io.Writer) *cobra.Command {
} }
cmdutil.CheckErr(utilerrors.Flatten(utilerrors.NewAggregate(allErrs))) cmdutil.CheckErr(utilerrors.Flatten(utilerrors.NewAggregate(allErrs)))
}, },
ValidArgs: validArgs,
ArgAliases: argAliases,
} }
usage := "Filename, directory, or URL to a file identifying the resource to get from a server." usage := "Filename, directory, or URL to a file identifying the resource to get from a server."

View File

@ -59,6 +59,9 @@ var (
func NewCmdRolloutResume(f *cmdutil.Factory, out io.Writer) *cobra.Command { func NewCmdRolloutResume(f *cmdutil.Factory, out io.Writer) *cobra.Command {
opts := &ResumeConfig{} opts := &ResumeConfig{}
validArgs := []string{"deployment"}
argAliases := kubectl.ResourceAliases(validArgs)
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "resume RESOURCE", Use: "resume RESOURCE",
Short: "Resume a paused resource", Short: "Resume a paused resource",
@ -76,6 +79,8 @@ func NewCmdRolloutResume(f *cmdutil.Factory, out io.Writer) *cobra.Command {
} }
cmdutil.CheckErr(utilerrors.Flatten(utilerrors.NewAggregate(allErrs))) cmdutil.CheckErr(utilerrors.Flatten(utilerrors.NewAggregate(allErrs)))
}, },
ValidArgs: validArgs,
ArgAliases: argAliases,
} }
usage := "Filename, directory, or URL to a file identifying the resource to get from a server." usage := "Filename, directory, or URL to a file identifying the resource to get from a server."

View File

@ -47,6 +47,9 @@ var (
func NewCmdRolloutStatus(f *cmdutil.Factory, out io.Writer) *cobra.Command { func NewCmdRolloutStatus(f *cmdutil.Factory, out io.Writer) *cobra.Command {
options := &StatusOptions{} options := &StatusOptions{}
validArgs := []string{"deployment"}
argAliases := kubectl.ResourceAliases(validArgs)
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "status (TYPE NAME | TYPE/NAME) [flags]", Use: "status (TYPE NAME | TYPE/NAME) [flags]",
Short: "Watch rollout status until it's done", Short: "Watch rollout status until it's done",
@ -55,6 +58,8 @@ func NewCmdRolloutStatus(f *cmdutil.Factory, out io.Writer) *cobra.Command {
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
cmdutil.CheckErr(RunStatus(f, cmd, out, args, options)) cmdutil.CheckErr(RunStatus(f, cmd, out, args, options))
}, },
ValidArgs: validArgs,
ArgAliases: argAliases,
} }
usage := "Filename, directory, or URL to a file identifying the resource to get from a server." usage := "Filename, directory, or URL to a file identifying the resource to get from a server."

View File

@ -58,6 +58,9 @@ var (
func NewCmdRolloutUndo(f *cmdutil.Factory, out io.Writer) *cobra.Command { func NewCmdRolloutUndo(f *cmdutil.Factory, out io.Writer) *cobra.Command {
opts := &UndoOptions{} opts := &UndoOptions{}
validArgs := []string{"deployment"}
argAliases := kubectl.ResourceAliases(validArgs)
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "undo (TYPE NAME | TYPE/NAME) [flags]", Use: "undo (TYPE NAME | TYPE/NAME) [flags]",
Short: "Undo a previous rollout", Short: "Undo a previous rollout",
@ -75,6 +78,8 @@ func NewCmdRolloutUndo(f *cmdutil.Factory, out io.Writer) *cobra.Command {
} }
cmdutil.CheckErr(utilerrors.Flatten(utilerrors.NewAggregate(allErrs))) cmdutil.CheckErr(utilerrors.Flatten(utilerrors.NewAggregate(allErrs)))
}, },
ValidArgs: validArgs,
ArgAliases: argAliases,
} }
cmd.Flags().Int64("to-revision", 0, "The revision to rollback to. Default to 0 (last revision).") cmd.Flags().Int64("to-revision", 0, "The revision to rollback to. Default to 0 (last revision).")

View File

@ -66,6 +66,9 @@ var (
func NewCmdScale(f *cmdutil.Factory, out io.Writer) *cobra.Command { func NewCmdScale(f *cmdutil.Factory, out io.Writer) *cobra.Command {
options := &ScaleOptions{} options := &ScaleOptions{}
validArgs := []string{"deployment", "replicaset", "replicationcontroller", "job"}
argAliases := kubectl.ResourceAliases(validArgs)
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "scale [--resource-version=version] [--current-replicas=count] --replicas=COUNT (-f FILENAME | TYPE NAME)", Use: "scale [--resource-version=version] [--current-replicas=count] --replicas=COUNT (-f FILENAME | TYPE NAME)",
// resize is deprecated // resize is deprecated
@ -79,6 +82,8 @@ func NewCmdScale(f *cmdutil.Factory, out io.Writer) *cobra.Command {
err := RunScale(f, out, cmd, args, shortOutput, options) err := RunScale(f, out, cmd, args, shortOutput, options)
cmdutil.CheckErr(err) cmdutil.CheckErr(err)
}, },
ValidArgs: validArgs,
ArgAliases: argAliases,
} }
cmd.Flags().String("resource-version", "", "Precondition for resource version. Requires that the current resource version match this value in order to scale.") cmd.Flags().String("resource-version", "", "Precondition for resource version. Requires that the current resource version match this value in order to scale.")
cmd.Flags().Int("current-replicas", -1, "Precondition for current size. Requires that the current size of the resource match this value in order to scale.") cmd.Flags().Int("current-replicas", -1, "Precondition for current size. Requires that the current size of the resource match this value in order to scale.")

View File

@ -76,15 +76,8 @@ var (
func NewCmdTaint(f *cmdutil.Factory, out io.Writer) *cobra.Command { func NewCmdTaint(f *cmdutil.Factory, out io.Writer) *cobra.Command {
options := &TaintOptions{} options := &TaintOptions{}
// retrieve a list of handled resources from printer as valid args validArgs := []string{"node"}
validArgs := []string{} argAliases := kubectl.ResourceAliases(validArgs)
p, err := f.Printer(nil, kubectl.PrintOptions{
ColumnLabels: []string{},
})
cmdutil.CheckErr(err)
if p != nil {
validArgs = p.HandledResources()
}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N", Use: "taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N",
@ -102,7 +95,8 @@ func NewCmdTaint(f *cmdutil.Factory, out io.Writer) *cobra.Command {
cmdutil.CheckErr(err) cmdutil.CheckErr(err)
} }
}, },
ValidArgs: validArgs, ValidArgs: validArgs,
ArgAliases: argAliases,
} }
cmdutil.AddValidateFlags(cmd) cmdutil.AddValidateFlags(cmd)
@ -288,8 +282,15 @@ func (o *TaintOptions) Complete(f *cmdutil.Factory, out io.Writer, cmd *cobra.Co
// Validate checks to the TaintOptions to see if there is sufficient information run the command. // Validate checks to the TaintOptions to see if there is sufficient information run the command.
func (o TaintOptions) Validate(args []string) error { func (o TaintOptions) Validate(args []string) error {
resourceType := strings.ToLower(o.resources[0]) resourceType := strings.ToLower(o.resources[0])
if resourceType != "node" && resourceType != "nodes" { validResources, isValidResource := append(kubectl.ResourceAliases([]string{"node"}), "node"), false
return fmt.Errorf("invalid resource type %s, only node(s) is supported", o.resources[0]) for _, validResource := range validResources {
if resourceType == validResource {
isValidResource = true
break
}
}
if !isValidResource {
return fmt.Errorf("invalid resource type %s, only %q are supported", o.resources[0], validResources)
} }
// check the format of taint args and checks removed taints aren't in the new taints list // check the format of taint args and checks removed taints aren't in the new taints list