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
|
||||
}
|
||||
|
||||
infos := []*resource.Info{}
|
||||
r.Visit(func(info *resource.Info, err error) error {
|
||||
if err == nil {
|
||||
infos = append(infos, info)
|
||||
infos, err := r.Infos()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
if len(o.ResourceVersion) != 0 && len(infos) > 1 {
|
||||
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)
|
||||
}
|
||||
|
||||
counter := 0
|
||||
err = r.Visit(func(info *resource.Info, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
if len(infos) == 0 {
|
||||
return fmt.Errorf("no objects passed to scale")
|
||||
}
|
||||
counter++
|
||||
|
||||
for _, info := range infos {
|
||||
mapping := info.ResourceMapping()
|
||||
if o.dryRunStrategy == cmdutil.DryRunClient {
|
||||
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 {
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
if counter == 0 {
|
||||
return fmt.Errorf("no objects passed to scale")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue