mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-02 19:28:16 +00:00
Fixes #30562: Refactor kubectl command options to use common struct for common file params
This commit is contained in:
@@ -30,13 +30,6 @@ import (
|
||||
"k8s.io/kubernetes/pkg/kubectl/resource"
|
||||
)
|
||||
|
||||
// ScaleOptions is the start of the data required to perform the operation. As new fields are added, add them here instead of
|
||||
// referencing the cmd.Flags()
|
||||
type ScaleOptions struct {
|
||||
Filenames []string
|
||||
Recursive bool
|
||||
}
|
||||
|
||||
var (
|
||||
scale_long = dedent.Dedent(`
|
||||
Set a new size for a Deployment, ReplicaSet, Replication Controller, or Job.
|
||||
@@ -64,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 {
|
||||
options := &ScaleOptions{}
|
||||
options := &resource.FilenameOptions{}
|
||||
|
||||
validArgs := []string{"deployment", "replicaset", "replicationcontroller", "job"}
|
||||
argAliases := kubectl.ResourceAliases(validArgs)
|
||||
@@ -94,14 +87,13 @@ func NewCmdScale(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
||||
cmdutil.AddRecordFlag(cmd)
|
||||
cmdutil.AddInclude3rdPartyFlags(cmd)
|
||||
|
||||
usage := "Filename, directory, or URL to a file identifying the resource to set a new size"
|
||||
kubectl.AddJsonFilenameFlag(cmd, &options.Filenames, usage)
|
||||
cmdutil.AddRecursiveFlag(cmd, &options.Recursive)
|
||||
usage := "identifying the resource to set a new size"
|
||||
cmdutil.AddFilenameOptionFlags(cmd, options, usage)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// RunScale executes the scaling
|
||||
func RunScale(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string, shortOutput bool, options *ScaleOptions) error {
|
||||
func RunScale(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string, shortOutput bool, options *resource.FilenameOptions) error {
|
||||
if len(os.Args) > 1 && os.Args[1] == "resize" {
|
||||
printDeprecationWarning("scale", "resize")
|
||||
}
|
||||
@@ -115,7 +107,7 @@ func RunScale(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
|
||||
r := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), f.Decoder(true)).
|
||||
ContinueOnError().
|
||||
NamespaceParam(cmdNamespace).DefaultNamespace().
|
||||
FilenameParam(enforceNamespace, options.Recursive, options.Filenames...).
|
||||
FilenameParam(enforceNamespace, options).
|
||||
ResourceTypeOrNameArgs(false, args...).
|
||||
Flatten().
|
||||
Do()
|
||||
|
||||
Reference in New Issue
Block a user