kubectl scale: Use visitor only once
`kubectl scale` calls visitor two times. Second call fails when the piped input is passed by returning an `error: no objects passed to scale` error. This PR uses the result of first visitor and fixes that piped input problem. In addition to that, this PR also adds new scale test to verify. Kubernetes-commit: 13be899b422a1f68c38e3a9c9d88831db709a32d
This commit is contained in:
parent
9be4b0942e
commit
0eb2f03176
|
|
@ -209,13 +209,10 @@ func (o *ScaleOptions) RunScale() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
infos := []*resource.Info{}
|
infos, err := r.Infos()
|
||||||
r.Visit(func(info *resource.Info, err error) error {
|
if err != nil {
|
||||||
if err == nil {
|
return err
|
||||||
infos = append(infos, info)
|
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
if len(o.ResourceVersion) != 0 && len(infos) > 1 {
|
if len(o.ResourceVersion) != 0 && len(infos) > 1 {
|
||||||
return fmt.Errorf("cannot use --resource-version with multiple resources")
|
return fmt.Errorf("cannot use --resource-version with multiple resources")
|
||||||
|
|
@ -234,17 +231,16 @@ func (o *ScaleOptions) RunScale() error {
|
||||||
waitForReplicas = scale.NewRetryParams(1*time.Second, o.Timeout)
|
waitForReplicas = scale.NewRetryParams(1*time.Second, o.Timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
counter := 0
|
if len(infos) == 0 {
|
||||||
err = r.Visit(func(info *resource.Info, err error) error {
|
return fmt.Errorf("no objects passed to scale")
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
counter++
|
|
||||||
|
|
||||||
|
for _, info := range infos {
|
||||||
mapping := info.ResourceMapping()
|
mapping := info.ResourceMapping()
|
||||||
if o.dryRunStrategy == cmdutil.DryRunClient {
|
if o.dryRunStrategy == cmdutil.DryRunClient {
|
||||||
return o.PrintObj(info.Object, o.Out)
|
return o.PrintObj(info.Object, o.Out)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := o.scaler.Scale(info.Namespace, info.Name, uint(o.Replicas), precondition, retry, waitForReplicas, mapping.Resource, o.dryRunStrategy == cmdutil.DryRunServer); err != nil {
|
if err := o.scaler.Scale(info.Namespace, info.Name, uint(o.Replicas), precondition, retry, waitForReplicas, mapping.Resource, o.dryRunStrategy == cmdutil.DryRunServer); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -263,14 +259,12 @@ func (o *ScaleOptions) RunScale() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return o.PrintObj(info.Object, o.Out)
|
err := o.PrintObj(info.Object, o.Out)
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if counter == 0 {
|
|
||||||
return fmt.Errorf("no objects passed to scale")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue