Merge pull request #60139 from soltysh/deprecate_scale_job

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Deprecate kubectl scale job

**What this PR does / why we need it**:
With the generic scaler (https://github.com/kubernetes/kubernetes/pull/58298) the only problem is job and as discussed in https://github.com/kubernetes/kubernetes/pull/58468#issuecomment-360794229 and during SIG CLI we've agreed that scaling jobs was a mistake we need to revert. 
This PR deprecates scale command for jobs, only. 

/assign @deads2k @pwittrock 

**Release note**:
```release-note
Deprecate kubectl scale jobs (only jobs). 
```
This commit is contained in:
Kubernetes Submit Queue 2018-02-22 01:29:30 -08:00 committed by GitHub
commit 39c7e9242b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 19 deletions

View File

@ -32,7 +32,6 @@ import (
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/util/i18n" "k8s.io/kubernetes/pkg/kubectl/util/i18n"
"github.com/golang/glog"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -270,7 +269,7 @@ func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob
Commands: []*cobra.Command{ Commands: []*cobra.Command{
rollout.NewCmdRollout(f, out, err), rollout.NewCmdRollout(f, out, err),
NewCmdRollingUpdate(f, out), NewCmdRollingUpdate(f, out),
NewCmdScale(f, out), NewCmdScale(f, out, err),
NewCmdAutoscale(f, out), NewCmdAutoscale(f, out),
}, },
}, },
@ -290,7 +289,7 @@ func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob
Message: "Troubleshooting and Debugging Commands:", Message: "Troubleshooting and Debugging Commands:",
Commands: []*cobra.Command{ Commands: []*cobra.Command{
NewCmdDescribe(f, out, err), NewCmdDescribe(f, out, err),
NewCmdLogs(f, out), NewCmdLogs(f, out, err),
NewCmdAttach(f, in, out, err), NewCmdAttach(f, in, out, err),
NewCmdExec(f, in, out, err), NewCmdExec(f, in, out, err),
NewCmdPortForward(f, out, err), NewCmdPortForward(f, out, err),
@ -355,8 +354,8 @@ func runHelp(cmd *cobra.Command, args []string) {
cmd.Help() cmd.Help()
} }
func printDeprecationWarning(command, alias string) { func printDeprecationWarning(errOut io.Writer, command, alias string) {
glog.Warningf("%s is DEPRECATED and will be removed in a future version. Use %s instead.", alias, command) fmt.Fprintf(errOut, "%s is DEPRECATED and will be removed in a future version. Use %s instead.", alias, command)
} }
// deprecatedAlias is intended to be used to create a "wrapper" command around // deprecatedAlias is intended to be used to create a "wrapper" command around

View File

@ -155,7 +155,7 @@ func (p *ExecOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, argsIn []s
return cmdutil.UsageErrorf(cmd, execUsageStr) return cmdutil.UsageErrorf(cmd, execUsageStr)
} }
if len(p.PodName) != 0 { if len(p.PodName) != 0 {
printDeprecationWarning("exec POD_NAME", "-p POD_NAME") printDeprecationWarning(p.Err, "exec POD_NAME", "-p POD_NAME")
if len(argsIn) < 1 { if len(argsIn) < 1 {
return cmdutil.UsageErrorf(cmd, execUsageStr) return cmdutil.UsageErrorf(cmd, execUsageStr)
} }

View File

@ -142,6 +142,7 @@ func TestPodAndContainer(t *testing.T) {
cmd := &cobra.Command{} cmd := &cobra.Command{}
options := test.p options := test.p
options.Err = bytes.NewBuffer([]byte{})
err := options.Complete(f, cmd, test.args, test.argsLenAtDash) err := options.Complete(f, cmd, test.args, test.argsLenAtDash)
if test.expectError && err == nil { if test.expectError && err == nil {
t.Errorf("%s: unexpected non-error", test.name) t.Errorf("%s: unexpected non-error", test.name)

View File

@ -86,7 +86,7 @@ type LogsOptions struct {
} }
// NewCmdLogs creates a new pod logs command // NewCmdLogs creates a new pod logs command
func NewCmdLogs(f cmdutil.Factory, out io.Writer) *cobra.Command { func NewCmdLogs(f cmdutil.Factory, out, errOut io.Writer) *cobra.Command {
o := &LogsOptions{} o := &LogsOptions{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]", Use: "logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]",
@ -96,7 +96,7 @@ func NewCmdLogs(f cmdutil.Factory, out io.Writer) *cobra.Command {
Example: logsExample, Example: logsExample,
PreRun: func(cmd *cobra.Command, args []string) { PreRun: func(cmd *cobra.Command, args []string) {
if len(os.Args) > 1 && os.Args[1] == "log" { if len(os.Args) > 1 && os.Args[1] == "log" {
printDeprecationWarning("logs", "log") printDeprecationWarning(errOut, "logs", "log")
} }
}, },
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {

View File

@ -74,7 +74,7 @@ func TestLog(t *testing.T) {
tf.ClientConfig = defaultClientConfig() tf.ClientConfig = defaultClientConfig()
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdLogs(f, buf) cmd := NewCmdLogs(f, buf, buf)
cmd.Flags().Set("namespace", "test") cmd.Flags().Set("namespace", "test")
cmd.Run(cmd, []string{"foo"}) cmd.Run(cmd, []string{"foo"})
@ -129,7 +129,8 @@ func TestValidateLogFlags(t *testing.T) {
}, },
} }
for _, test := range tests { for _, test := range tests {
cmd := NewCmdLogs(f, bytes.NewBuffer([]byte{})) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdLogs(f, buf, buf)
out := "" out := ""
for flag, value := range test.flags { for flag, value := range test.flags {
cmd.Flags().Set(flag, value) cmd.Flags().Set(flag, value)
@ -188,7 +189,8 @@ func TestLogComplete(t *testing.T) {
}, },
} }
for _, test := range tests { for _, test := range tests {
cmd := NewCmdLogs(f, bytes.NewBuffer([]byte{})) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdLogs(f, buf, buf)
var err error var err error
out := "" out := ""
for flag, value := range test.flags { for flag, value := range test.flags {

View File

@ -57,7 +57,7 @@ var (
) )
// NewCmdScale returns a cobra command with the appropriate configuration and flags to run scale // 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{} options := &resource.FilenameOptions{}
validArgs := []string{"deployment", "replicaset", "replicationcontroller", "job", "statefulset"} validArgs := []string{"deployment", "replicaset", "replicationcontroller", "job", "statefulset"}
@ -72,7 +72,7 @@ func NewCmdScale(f cmdutil.Factory, out io.Writer) *cobra.Command {
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
cmdutil.CheckErr(cmdutil.ValidateOutputArgs(cmd)) cmdutil.CheckErr(cmdutil.ValidateOutputArgs(cmd))
shortOutput := cmdutil.GetFlagString(cmd, "output") == "name" 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) cmdutil.CheckErr(err)
}, },
ValidArgs: validArgs, ValidArgs: validArgs,
@ -95,12 +95,17 @@ func NewCmdScale(f cmdutil.Factory, out io.Writer) *cobra.Command {
} }
// RunScale executes the scaling // 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() cmdNamespace, enforceNamespace, err := f.DefaultNamespace()
if err != nil { if err != nil {
return err 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") selector := cmdutil.GetFlagString(cmd, "selector")
all := cmdutil.GetFlagBool(cmd, "all") all := cmdutil.GetFlagBool(cmd, "all")
@ -121,11 +126,6 @@ func RunScale(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
return err 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{} infos := []*resource.Info{}
err = r.Visit(func(info *resource.Info, err error) error { err = r.Visit(func(info *resource.Info, err error) error {
if err == nil { if err == nil {
@ -146,6 +146,10 @@ func RunScale(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
} }
mapping := info.ResourceMapping() 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) scaler, err := f.Scaler(mapping)
if err != nil { if err != nil {
return err return err