mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-01 18:58:18 +00:00
kubectl: Support scaling deployments
This commit adds support for using kubectl scale to scale deployments. Makes use of the deployments/scale endpoint instead of updating deployment.spec.replicas directly.
This commit is contained in:
@@ -36,23 +36,26 @@ type ScaleOptions struct {
|
||||
}
|
||||
|
||||
const (
|
||||
scale_long = `Set a new size for a Replication Controller.
|
||||
scale_long = `Set a new size for a Replication Controller, Job, or Deployment.
|
||||
|
||||
Scale also allows users to specify one or more preconditions for the scale action.
|
||||
If --current-replicas or --resource-version is specified, it is validated before the
|
||||
scale is attempted, and it is guaranteed that the precondition holds true when the
|
||||
scale is sent to the server.`
|
||||
scale_example = `# Scale replication controller named 'foo' to 3.
|
||||
$ kubectl scale --replicas=3 replicationcontrollers foo
|
||||
$ kubectl scale --replicas=3 rc/foo
|
||||
|
||||
# Scale a replication controller identified by type and name specified in "foo-controller.yaml" to 3.
|
||||
$ kubectl scale --replicas=3 -f foo-controller.yaml
|
||||
# Scale a resource identified by type and name specified in "foo.yaml" to 3.
|
||||
$ kubectl scale --replicas=3 -f foo.yaml
|
||||
|
||||
# If the replication controller named foo's current size is 2, scale foo to 3.
|
||||
$ kubectl scale --current-replicas=2 --replicas=3 replicationcontrollers foo
|
||||
# If the deployment named mysql's current size is 2, scale mysql to 3.
|
||||
$ kubectl scale --current-replicas=2 --replicas=3 deployment/mysql
|
||||
|
||||
# Scale multiple replication controllers.
|
||||
$ kubectl scale --replicas=5 rc/foo rc/bar`
|
||||
$ kubectl scale --replicas=5 rc/foo rc/bar rc/baz
|
||||
|
||||
# Scale job named 'cron' to 3.
|
||||
$ kubectl scale --replicas=3 job/cron`
|
||||
)
|
||||
|
||||
// NewCmdScale returns a cobra command with the appropriate configuration and flags to run scale
|
||||
@@ -63,7 +66,7 @@ func NewCmdScale(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
||||
Use: "scale [--resource-version=version] [--current-replicas=count] --replicas=COUNT (-f FILENAME | TYPE NAME)",
|
||||
// resize is deprecated
|
||||
Aliases: []string{"resize"},
|
||||
Short: "Set a new size for a Replication Controller.",
|
||||
Short: "Set a new size for a Replication Controller, Job, or Deployment.",
|
||||
Long: scale_long,
|
||||
Example: scale_example,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
@@ -74,13 +77,13 @@ func NewCmdScale(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
||||
},
|
||||
}
|
||||
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 replication controller 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("replicas", -1, "The new desired number of replicas. Required.")
|
||||
cmd.MarkFlagRequired("replicas")
|
||||
cmd.Flags().Duration("timeout", 0, "The length of time to wait before giving up on a scale operation, zero means don't wait.")
|
||||
cmdutil.AddOutputFlagsForMutation(cmd)
|
||||
|
||||
usage := "Filename, directory, or URL to a file identifying the replication controller to set a new size"
|
||||
usage := "Filename, directory, or URL to a file identifying the resource to set a new size"
|
||||
kubectl.AddJsonFilenameFlag(cmd, &options.Filenames, usage)
|
||||
return cmd
|
||||
}
|
||||
@@ -127,11 +130,11 @@ func RunScale(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
|
||||
|
||||
resourceVersion := cmdutil.GetFlagString(cmd, "resource-version")
|
||||
if len(resourceVersion) != 0 && len(infos) > 1 {
|
||||
return fmt.Errorf("cannot use --resource-version with multiple controllers")
|
||||
return fmt.Errorf("cannot use --resource-version with multiple resources")
|
||||
}
|
||||
currentSize := cmdutil.GetFlagInt(cmd, "current-replicas")
|
||||
if currentSize != -1 && len(infos) > 1 {
|
||||
return fmt.Errorf("cannot use --current-replicas with multiple controllers")
|
||||
return fmt.Errorf("cannot use --current-replicas with multiple resources")
|
||||
}
|
||||
precondition := &kubectl.ScalePrecondition{Size: currentSize, ResourceVersion: resourceVersion}
|
||||
retry := kubectl.NewRetryParams(kubectl.Interval, kubectl.Timeout)
|
||||
|
||||
Reference in New Issue
Block a user