mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 15:58:37 +00:00
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:
commit
c98a1e2416
@ -55,6 +55,9 @@ var (
|
||||
func NewCmdAutoscale(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
||||
options := &AutoscaleOptions{}
|
||||
|
||||
validArgs := []string{"deployment", "replicaset", "replicationcontroller"}
|
||||
argAliases := kubectl.ResourceAliases(validArgs)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "autoscale (-f FILENAME | TYPE NAME | TYPE/NAME) [--min=MINPODS] --max=MAXPODS [--cpu-percent=CPU] [flags]",
|
||||
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)
|
||||
cmdutil.CheckErr(err)
|
||||
},
|
||||
ValidArgs: validArgs,
|
||||
ArgAliases: argAliases,
|
||||
}
|
||||
cmdutil.AddPrinterFlags(cmd)
|
||||
cmd.Flags().String("generator", "horizontalpodautoscaler/v1", "The name of the API generator to use. Currently there is only 1 generator.")
|
||||
|
@ -102,6 +102,11 @@ __kubectl_get_resource_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
|
||||
__kubectl_get_containers()
|
||||
{
|
||||
@ -134,15 +139,15 @@ __kubectl_require_pod_and_container()
|
||||
__custom_func() {
|
||||
case ${last_command} in
|
||||
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
|
||||
return
|
||||
;;
|
||||
kubectl_logs)
|
||||
kubectl_logs | kubectl_attach)
|
||||
__kubectl_require_pod_and_container
|
||||
return
|
||||
;;
|
||||
kubectl_exec)
|
||||
kubectl_exec | kubectl_port-forward | kubectl_top_pod)
|
||||
__kubectl_get_resource_pod
|
||||
return
|
||||
;;
|
||||
@ -150,6 +155,10 @@ __custom_func() {
|
||||
__kubectl_get_resource_rc
|
||||
return
|
||||
;;
|
||||
kubectl_cordon | kubectl_uncordon | kubectl_drain | kubectl_top_node)
|
||||
__kubectl_get_resource_node
|
||||
return
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
|
@ -49,6 +49,9 @@ var (
|
||||
func NewCmdRolloutHistory(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
||||
options := &HistoryOptions{}
|
||||
|
||||
validArgs := []string{"deployment"}
|
||||
argAliases := kubectl.ResourceAliases(validArgs)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "history (TYPE NAME | TYPE/NAME) [flags]",
|
||||
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) {
|
||||
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")
|
||||
|
@ -61,6 +61,9 @@ var (
|
||||
func NewCmdRolloutPause(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
||||
opts := &PauseConfig{}
|
||||
|
||||
validArgs := []string{"deployment"}
|
||||
argAliases := kubectl.ResourceAliases(validArgs)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "pause RESOURCE",
|
||||
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)))
|
||||
},
|
||||
ValidArgs: validArgs,
|
||||
ArgAliases: argAliases,
|
||||
}
|
||||
|
||||
usage := "Filename, directory, or URL to a file identifying the resource to get from a server."
|
||||
|
@ -59,6 +59,9 @@ var (
|
||||
func NewCmdRolloutResume(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
||||
opts := &ResumeConfig{}
|
||||
|
||||
validArgs := []string{"deployment"}
|
||||
argAliases := kubectl.ResourceAliases(validArgs)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "resume 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)))
|
||||
},
|
||||
ValidArgs: validArgs,
|
||||
ArgAliases: argAliases,
|
||||
}
|
||||
|
||||
usage := "Filename, directory, or URL to a file identifying the resource to get from a server."
|
||||
|
@ -47,6 +47,9 @@ var (
|
||||
func NewCmdRolloutStatus(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
||||
options := &StatusOptions{}
|
||||
|
||||
validArgs := []string{"deployment"}
|
||||
argAliases := kubectl.ResourceAliases(validArgs)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "status (TYPE NAME | TYPE/NAME) [flags]",
|
||||
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) {
|
||||
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."
|
||||
|
@ -58,6 +58,9 @@ var (
|
||||
func NewCmdRolloutUndo(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
||||
opts := &UndoOptions{}
|
||||
|
||||
validArgs := []string{"deployment"}
|
||||
argAliases := kubectl.ResourceAliases(validArgs)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "undo (TYPE NAME | TYPE/NAME) [flags]",
|
||||
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)))
|
||||
},
|
||||
ValidArgs: validArgs,
|
||||
ArgAliases: argAliases,
|
||||
}
|
||||
|
||||
cmd.Flags().Int64("to-revision", 0, "The revision to rollback to. Default to 0 (last revision).")
|
||||
|
@ -66,6 +66,9 @@ var (
|
||||
func NewCmdScale(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
||||
options := &ScaleOptions{}
|
||||
|
||||
validArgs := []string{"deployment", "replicaset", "replicationcontroller", "job"}
|
||||
argAliases := kubectl.ResourceAliases(validArgs)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "scale [--resource-version=version] [--current-replicas=count] --replicas=COUNT (-f FILENAME | TYPE NAME)",
|
||||
// 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)
|
||||
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().Int("current-replicas", -1, "Precondition for current size. Requires that the current size of the resource match this value in order to scale.")
|
||||
|
@ -76,15 +76,8 @@ var (
|
||||
func NewCmdTaint(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
||||
options := &TaintOptions{}
|
||||
|
||||
// retrieve a list of handled resources from printer as valid args
|
||||
validArgs := []string{}
|
||||
p, err := f.Printer(nil, kubectl.PrintOptions{
|
||||
ColumnLabels: []string{},
|
||||
})
|
||||
cmdutil.CheckErr(err)
|
||||
if p != nil {
|
||||
validArgs = p.HandledResources()
|
||||
}
|
||||
validArgs := []string{"node"}
|
||||
argAliases := kubectl.ResourceAliases(validArgs)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
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)
|
||||
}
|
||||
},
|
||||
ValidArgs: validArgs,
|
||||
ValidArgs: validArgs,
|
||||
ArgAliases: argAliases,
|
||||
}
|
||||
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.
|
||||
func (o TaintOptions) Validate(args []string) error {
|
||||
resourceType := strings.ToLower(o.resources[0])
|
||||
if resourceType != "node" && resourceType != "nodes" {
|
||||
return fmt.Errorf("invalid resource type %s, only node(s) is supported", o.resources[0])
|
||||
validResources, isValidResource := append(kubectl.ResourceAliases([]string{"node"}), "node"), false
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user