From 84d177b6d4abab6193dc05302ad54378a0d34aec Mon Sep 17 00:00:00 2001 From: SataQiu <1527062125@qq.com> Date: Sat, 6 Jun 2020 17:35:47 +0800 Subject: [PATCH] kubectl: fix the bug that kubectl autoscale does not honor --name flag Signed-off-by: SataQiu <1527062125@qq.com> --- .../src/k8s.io/kubectl/pkg/cmd/autoscale/autoscale.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/autoscale/autoscale.go b/staging/src/k8s.io/kubectl/pkg/cmd/autoscale/autoscale.go index a4c51faac39..1a56d2a1da7 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/autoscale/autoscale.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/autoscale/autoscale.go @@ -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 @@ -170,7 +170,10 @@ 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{ @@ -178,7 +181,7 @@ func (o *AutoscaleOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args MinReplicas: o.Min, MaxReplicas: o.Max, CPUPercent: o.CPUPercent, - ScaleRefName: name, + ScaleRefName: refName, ScaleRefKind: mapping.GroupVersionKind.Kind, ScaleRefAPIVersion: mapping.GroupVersionKind.GroupVersion().String(), }, nil @@ -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 }