Skip to content

Commit

Permalink
Deprecate kubectl scale job
Browse files Browse the repository at this point in the history
  • Loading branch information
soltysh committed Feb 21, 2018
1 parent 6e6c4ce commit 0bf2561
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/kubectl/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob
Commands: []*cobra.Command{
rollout.NewCmdRollout(f, out, err),
NewCmdRollingUpdate(f, out),
NewCmdScale(f, out),
NewCmdScale(f, out, err),
NewCmdAutoscale(f, out),
},
},
Expand Down
20 changes: 12 additions & 8 deletions pkg/kubectl/cmd/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var (
)

// NewCmdScale returns a cobra command with the appropriate configuration and flags to run scale
func NewCmdScale(f cmdutil.Factory, out io.Writer) *cobra.Command {
func NewCmdScale(f cmdutil.Factory, out, errOut io.Writer) *cobra.Command {
options := &resource.FilenameOptions{}

validArgs := []string{"deployment", "replicaset", "replicationcontroller", "job", "statefulset"}
Expand All @@ -72,7 +72,7 @@ func NewCmdScale(f cmdutil.Factory, out io.Writer) *cobra.Command {
Run: func(cmd *cobra.Command, args []string) {
cmdutil.CheckErr(cmdutil.ValidateOutputArgs(cmd))
shortOutput := cmdutil.GetFlagString(cmd, "output") == "name"
err := RunScale(f, out, cmd, args, shortOutput, options)
err := RunScale(f, out, errOut, cmd, args, shortOutput, options)
cmdutil.CheckErr(err)
},
ValidArgs: validArgs,
Expand All @@ -95,12 +95,17 @@ func NewCmdScale(f cmdutil.Factory, out io.Writer) *cobra.Command {
}

// RunScale executes the scaling
func RunScale(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string, shortOutput bool, options *resource.FilenameOptions) error {
func RunScale(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args []string, shortOutput bool, options *resource.FilenameOptions) error {
cmdNamespace, enforceNamespace, err := f.DefaultNamespace()
if err != nil {
return err
}

count := cmdutil.GetFlagInt(cmd, "replicas")
if count < 0 {
return cmdutil.UsageErrorf(cmd, "The --replicas=COUNT flag is required, and COUNT must be greater than or equal to 0")
}

selector := cmdutil.GetFlagString(cmd, "selector")
all := cmdutil.GetFlagBool(cmd, "all")

Expand All @@ -121,11 +126,6 @@ func RunScale(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
return err
}

count := cmdutil.GetFlagInt(cmd, "replicas")
if count < 0 {
return cmdutil.UsageErrorf(cmd, "The --replicas=COUNT flag is required, and COUNT must be greater than or equal to 0")
}

infos := []*resource.Info{}
err = r.Visit(func(info *resource.Info, err error) error {
if err == nil {
Expand All @@ -146,6 +146,10 @@ func RunScale(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
}

mapping := info.ResourceMapping()
if mapping.Resource == "jobs" {
fmt.Fprintf(errOut, "%s scale job is DEPRECATED and will be removed in a future version.", cmd.Parent().Name())
}

scaler, err := f.Scaler(mapping)
if err != nil {
return err
Expand Down

0 comments on commit 0bf2561

Please sign in to comment.