Skip to content

Commit f451aec

Browse files
authored
Merge pull request kubernetes#128296 from AnishShah/kubectl-resize
[FG:InPlacePodVerticalScaling] Remove restrictions on subresource flag in kubectl commands
2 parents 833ee85 + e1ca634 commit f451aec

File tree

7 files changed

+9
-39
lines changed

7 files changed

+9
-39
lines changed

staging/src/k8s.io/kubectl/pkg/cmd/apply/apply.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ import (
5050
"k8s.io/kubectl/pkg/util/i18n"
5151
"k8s.io/kubectl/pkg/util/openapi"
5252
"k8s.io/kubectl/pkg/util/prune"
53-
"k8s.io/kubectl/pkg/util/slice"
5453
"k8s.io/kubectl/pkg/util/templates"
5554
"k8s.io/kubectl/pkg/validation"
5655
)
@@ -181,8 +180,6 @@ var (
181180

182181
var ApplySetToolVersion = version.Get().GitVersion
183182

184-
var supportedSubresources = []string{"status", "scale"}
185-
186183
// NewApplyFlags returns a default ApplyFlags
187184
func NewApplyFlags(streams genericiooptions.IOStreams) *ApplyFlags {
188185
return &ApplyFlags{
@@ -240,7 +237,7 @@ func (flags *ApplyFlags) AddFlags(cmd *cobra.Command) {
240237
cmdutil.AddPruningFlags(cmd, &flags.Prune, &flags.PruneAllowlist, &flags.All, &flags.ApplySetRef)
241238
cmd.Flags().BoolVar(&flags.Overwrite, "overwrite", flags.Overwrite, "Automatically resolve conflicts between the modified and live configuration by using values from the modified configuration")
242239
cmd.Flags().BoolVar(&flags.OpenAPIPatch, "openapi-patch", flags.OpenAPIPatch, "If true, use openapi to calculate diff when the openapi presents and the resource can be found in the openapi spec. Otherwise, fall back to use baked-in types.")
243-
cmdutil.AddSubresourceFlags(cmd, &flags.Subresource, "If specified, apply will operate on the subresource of the requested object. Only allowed when using --server-side.", supportedSubresources...)
240+
cmdutil.AddSubresourceFlags(cmd, &flags.Subresource, "If specified, apply will operate on the subresource of the requested object. Only allowed when using --server-side.")
244241
}
245242

246243
// ToOptions converts from CLI inputs to runtime inputs
@@ -445,9 +442,6 @@ func (o *ApplyOptions) Validate() error {
445442
}
446443
}
447444
}
448-
if len(o.Subresource) > 0 && !slice.ContainsString(supportedSubresources, o.Subresource, nil) {
449-
return fmt.Errorf("invalid subresource value: %q. Must be one of %v", o.Subresource, supportedSubresources)
450-
}
451445
if len(o.Subresource) > 0 && !o.ServerSideApply {
452446
return fmt.Errorf("--subresource can only be specified for --server-side")
453447
}

staging/src/k8s.io/kubectl/pkg/cmd/edit/edit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,6 @@ func NewCmdEdit(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.
103103
"Defaults to the line ending native to your platform.")
104104
cmdutil.AddFieldManagerFlagVar(cmd, &o.FieldManager, "kubectl-edit")
105105
cmdutil.AddApplyAnnotationVarFlags(cmd, &o.ApplyAnnotation)
106-
cmdutil.AddSubresourceFlags(cmd, &o.Subresource, "If specified, edit will operate on the subresource of the requested object.", editor.SupportedSubresources...)
106+
cmdutil.AddSubresourceFlags(cmd, &o.Subresource, "If specified, edit will operate on the subresource of the requested object.")
107107
return cmd
108108
}

staging/src/k8s.io/kubectl/pkg/cmd/get/get.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import (
4747
"k8s.io/kubectl/pkg/scheme"
4848
"k8s.io/kubectl/pkg/util/i18n"
4949
"k8s.io/kubectl/pkg/util/interrupt"
50-
"k8s.io/kubectl/pkg/util/slice"
5150
"k8s.io/kubectl/pkg/util/templates"
5251
"k8s.io/utils/ptr"
5352
)
@@ -145,8 +144,6 @@ const (
145144
useServerPrintColumns = "server-print"
146145
)
147146

148-
var supportedSubresources = []string{"status", "scale"}
149-
150147
// NewGetOptions returns a GetOptions with default chunk size 500.
151148
func NewGetOptions(parent string, streams genericiooptions.IOStreams) *GetOptions {
152149
return &GetOptions{
@@ -192,7 +189,7 @@ func NewCmdGet(parent string, f cmdutil.Factory, streams genericiooptions.IOStre
192189
cmdutil.AddFilenameOptionFlags(cmd, &o.FilenameOptions, "identifying the resource to get from a server.")
193190
cmdutil.AddChunkSizeFlag(cmd, &o.ChunkSize)
194191
cmdutil.AddLabelSelectorFlagVar(cmd, &o.LabelSelector)
195-
cmdutil.AddSubresourceFlags(cmd, &o.Subresource, "If specified, gets the subresource of the requested object.", supportedSubresources...)
192+
cmdutil.AddSubresourceFlags(cmd, &o.Subresource, "If specified, gets the subresource of the requested object.")
196193
return cmd
197194
}
198195

@@ -319,9 +316,6 @@ func (o *GetOptions) Validate() error {
319316
if o.OutputWatchEvents && !(o.Watch || o.WatchOnly) {
320317
return fmt.Errorf("--output-watch-events option can only be used with --watch or --watch-only")
321318
}
322-
if len(o.Subresource) > 0 && !slice.ContainsString(supportedSubresources, o.Subresource, nil) {
323-
return fmt.Errorf("invalid subresource value: %q. Must be one of %v", o.Subresource, supportedSubresources)
324-
}
325319
return nil
326320
}
327321

staging/src/k8s.io/kubectl/pkg/cmd/patch/patch.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import (
4545
"k8s.io/kubectl/pkg/scheme"
4646
"k8s.io/kubectl/pkg/util/completion"
4747
"k8s.io/kubectl/pkg/util/i18n"
48-
"k8s.io/kubectl/pkg/util/slice"
4948
"k8s.io/kubectl/pkg/util/templates"
5049
)
5150

@@ -107,8 +106,6 @@ var (
107106
kubectl patch deployment nginx-deployment --subresource='scale' --type='merge' -p '{"spec":{"replicas":2}}'`))
108107
)
109108

110-
var supportedSubresources = []string{"status", "scale"}
111-
112109
func NewPatchOptions(ioStreams genericiooptions.IOStreams) *PatchOptions {
113110
return &PatchOptions{
114111
RecordFlags: genericclioptions.NewRecordFlags(),
@@ -145,7 +142,7 @@ func NewCmdPatch(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra
145142
cmdutil.AddFilenameOptionFlags(cmd, &o.FilenameOptions, "identifying the resource to update")
146143
cmd.Flags().BoolVar(&o.Local, "local", o.Local, "If true, patch will operate on the content of the file, not the server-side resource.")
147144
cmdutil.AddFieldManagerFlagVar(cmd, &o.fieldManager, "kubectl-patch")
148-
cmdutil.AddSubresourceFlags(cmd, &o.Subresource, "If specified, patch will operate on the subresource of the requested object.", supportedSubresources...)
145+
cmdutil.AddSubresourceFlags(cmd, &o.Subresource, "If specified, patch will operate on the subresource of the requested object.")
149146

150147
return cmd
151148
}
@@ -200,9 +197,6 @@ func (o *PatchOptions) Validate() error {
200197
return fmt.Errorf("--type must be one of %v, not %q", sets.StringKeySet(patchTypes).List(), o.PatchType)
201198
}
202199
}
203-
if len(o.Subresource) > 0 && !slice.ContainsString(supportedSubresources, o.Subresource, nil) {
204-
return fmt.Errorf("invalid subresource value: %q. Must be one of %v", o.Subresource, supportedSubresources)
205-
}
206200
return nil
207201
}
208202

staging/src/k8s.io/kubectl/pkg/cmd/replace/replace.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import (
4040
"k8s.io/kubectl/pkg/scheme"
4141
"k8s.io/kubectl/pkg/util"
4242
"k8s.io/kubectl/pkg/util/i18n"
43-
"k8s.io/kubectl/pkg/util/slice"
4443
"k8s.io/kubectl/pkg/util/templates"
4544
"k8s.io/kubectl/pkg/validation"
4645
)
@@ -68,8 +67,6 @@ var (
6867
kubectl replace --force -f ./pod.json`))
6968
)
7069

71-
var supportedSubresources = []string{"status", "scale"}
72-
7370
type ReplaceOptions struct {
7471
PrintFlags *genericclioptions.PrintFlags
7572
RecordFlags *genericclioptions.RecordFlags
@@ -136,7 +133,7 @@ func NewCmdReplace(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra
136133

137134
cmd.Flags().StringVar(&o.Raw, "raw", o.Raw, "Raw URI to PUT to the server. Uses the transport specified by the kubeconfig file.")
138135
cmdutil.AddFieldManagerFlagVar(cmd, &o.fieldManager, "kubectl-replace")
139-
cmdutil.AddSubresourceFlags(cmd, &o.Subresource, "If specified, replace will operate on the subresource of the requested object.", supportedSubresources...)
136+
cmdutil.AddSubresourceFlags(cmd, &o.Subresource, "If specified, replace will operate on the subresource of the requested object.")
140137

141138
return cmd
142139
}
@@ -249,10 +246,6 @@ func (o *ReplaceOptions) Validate() error {
249246
}
250247
}
251248

252-
if len(o.Subresource) > 0 && !slice.ContainsString(supportedSubresources, o.Subresource, nil) {
253-
return fmt.Errorf("invalid subresource value: %q. Must be one of %v", o.Subresource, supportedSubresources)
254-
}
255-
256249
return nil
257250
}
258251

staging/src/k8s.io/kubectl/pkg/cmd/util/editor/editoptions.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,8 @@ import (
5252
"k8s.io/kubectl/pkg/cmd/util/editor/crlf"
5353
"k8s.io/kubectl/pkg/scheme"
5454
"k8s.io/kubectl/pkg/util"
55-
"k8s.io/kubectl/pkg/util/slice"
5655
)
5756

58-
var SupportedSubresources = []string{"status"}
59-
6057
// EditOptions contains all the options for running edit cli command.
6158
type EditOptions struct {
6259
resource.FilenameOptions
@@ -230,9 +227,6 @@ func (o *EditOptions) Complete(f cmdutil.Factory, args []string, cmd *cobra.Comm
230227

231228
// Validate checks the EditOptions to see if there is sufficient information to run the command.
232229
func (o *EditOptions) Validate() error {
233-
if len(o.Subresource) > 0 && !slice.ContainsString(SupportedSubresources, o.Subresource, nil) {
234-
return fmt.Errorf("invalid subresource value: %q. Must be one of %v", o.Subresource, SupportedSubresources)
235-
}
236230
return nil
237231
}
238232

staging/src/k8s.io/kubectl/pkg/cmd/util/helpers.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,10 +537,11 @@ func AddPruningFlags(cmd *cobra.Command, prune *bool, pruneAllowlist *[]string,
537537
}
538538
}
539539

540-
func AddSubresourceFlags(cmd *cobra.Command, subresource *string, usage string, allowedSubresources ...string) {
541-
cmd.Flags().StringVar(subresource, "subresource", "", fmt.Sprintf("%s Must be one of %v. This flag is beta and may change in the future.", usage, allowedSubresources))
540+
func AddSubresourceFlags(cmd *cobra.Command, subresource *string, usage string) {
541+
cmd.Flags().StringVar(subresource, "subresource", "", fmt.Sprintf("%s This flag is beta and may change in the future.", usage))
542542
CheckErr(cmd.RegisterFlagCompletionFunc("subresource", func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) {
543-
return allowedSubresources, cobra.ShellCompDirectiveNoFileComp
543+
var commonSubresources = []string{"status", "scale", "resize"}
544+
return commonSubresources, cobra.ShellCompDirectiveNoFileComp
544545
}))
545546
}
546547

0 commit comments

Comments
 (0)