NewCmdScale returns a cobra command with the appropriate configuration and flags to run scale
(f cmdutil.Factory, ioStreams genericiooptions.IOStreams)
| 105 | |
| 106 | // NewCmdScale returns a cobra command with the appropriate configuration and flags to run scale |
| 107 | func NewCmdScale(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command { |
| 108 | o := NewScaleOptions(ioStreams) |
| 109 | |
| 110 | validArgs := []string{"deployment", "replicaset", "replicationcontroller", "statefulset"} |
| 111 | |
| 112 | cmd := &cobra.Command{ |
| 113 | Use: "scale [--resource-version=version] [--current-replicas=count] --replicas=COUNT (-f FILENAME | TYPE NAME)", |
| 114 | DisableFlagsInUseLine: true, |
| 115 | Short: i18n.T("Set a new size for a deployment, replica set, or replication controller"), |
| 116 | Long: scaleLong, |
| 117 | Example: scaleExample, |
| 118 | ValidArgsFunction: completion.SpecifiedResourceTypeAndNameCompletionFunc(f, validArgs), |
| 119 | Run: func(cmd *cobra.Command, args []string) { |
| 120 | cmdutil.CheckErr(o.Complete(f, cmd, args)) |
| 121 | cmdutil.CheckErr(o.Validate()) |
| 122 | cmdutil.CheckErr(o.RunScale()) |
| 123 | }, |
| 124 | } |
| 125 | |
| 126 | o.RecordFlags.AddFlags(cmd) |
| 127 | o.PrintFlags.AddFlags(cmd) |
| 128 | |
| 129 | cmd.Flags().BoolVar(&o.All, "all", o.All, "Select all resources in the namespace of the specified resource types") |
| 130 | cmd.Flags().StringVar(&o.ResourceVersion, "resource-version", o.ResourceVersion, i18n.T("Precondition for resource version. Requires that the current resource version match this value in order to scale.")) |
| 131 | cmd.Flags().IntVar(&o.CurrentReplicas, "current-replicas", o.CurrentReplicas, "Precondition for current size. Requires that the current size of the resource match this value in order to scale. -1 (default) for no condition.") |
| 132 | cmd.Flags().IntVar(&o.Replicas, "replicas", o.Replicas, "The new desired number of replicas. Required.") |
| 133 | cmd.MarkFlagRequired("replicas") |
| 134 | cmd.Flags().DurationVar(&o.Timeout, "timeout", 0, "The length of time to wait before giving up on a scale operation, zero means don't wait. Any other values should contain a corresponding time unit (e.g. 1s, 2m, 3h).") |
| 135 | cmdutil.AddFilenameOptionFlags(cmd, &o.FilenameOptions, "identifying the resource to set a new size") |
| 136 | cmdutil.AddDryRunFlag(cmd) |
| 137 | cmdutil.AddLabelSelectorFlagVar(cmd, &o.Selector) |
| 138 | return cmd |
| 139 | } |
| 140 | |
| 141 | func (o *ScaleOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error { |
| 142 | var err error |
no test coverage detected
searching dependent graphs…