Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kubectl: fix the bug that kubectl autoscale does not honor --name flag #91855

Merged
merged 1 commit into from Jul 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions staging/src/k8s.io/kubectl/pkg/cmd/autoscale/autoscale.go
Expand Up @@ -78,7 +78,7 @@ type AutoscaleOptions struct {
dryRunStrategy cmdutil.DryRunStrategy
dryRunVerifier *resource.DryRunVerifier
builder *resource.Builder
generatorFunc func(string, *meta.RESTMapping) (generate.StructuredGenerator, error)
generatorFunc func(name, refName string, mapping *meta.RESTMapping) (generate.StructuredGenerator, error)
fieldManager string

HPAClient autoscalingv1client.HorizontalPodAutoscalersGetter
Expand Down Expand Up @@ -170,15 +170,18 @@ func (o *AutoscaleOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args
o.HPAClient = kubeClient.AutoscalingV1()

// get the generator
o.generatorFunc = func(name string, mapping *meta.RESTMapping) (generate.StructuredGenerator, error) {
o.generatorFunc = func(name, refName string, mapping *meta.RESTMapping) (generate.StructuredGenerator, error) {
if len(name) == 0 {
name = refName
}
switch o.Generator {
case generateversioned.HorizontalPodAutoscalerV1GeneratorName:
return &generateversioned.HorizontalPodAutoscalerGeneratorV1{
Name: name,
MinReplicas: o.Min,
MaxReplicas: o.Max,
CPUPercent: o.CPUPercent,
ScaleRefName: name,
ScaleRefName: refName,
ScaleRefKind: mapping.GroupVersionKind.Kind,
ScaleRefAPIVersion: mapping.GroupVersionKind.GroupVersion().String(),
}, nil
Expand Down Expand Up @@ -240,7 +243,7 @@ func (o *AutoscaleOptions) Run() error {
return fmt.Errorf("cannot autoscale a %v: %v", mapping.GroupVersionKind.Kind, err)
}

generator, err := o.generatorFunc(info.Name, mapping)
generator, err := o.generatorFunc(o.Name, info.Name, mapping)
if err != nil {
return err
}
Expand Down