kubectl scale: Add dry-run prefix to indicate result is not applied

Currently, if user executes `kubectl scale --dry-run`, output has no
indicator showing that this is not applied in reality.

This PR adds dry run suffix to the output as well as more integration
tests to verify it.
This commit is contained in:
Arda Güçlü
2022-12-02 16:27:18 +03:00
parent 13be899b42
commit 76ee3788cc
2 changed files with 34 additions and 5 deletions

View File

@@ -144,16 +144,18 @@ func (o *ScaleOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st
if err != nil {
return err
}
o.dryRunStrategy, err = cmdutil.GetDryRunStrategy(cmd)
if err != nil {
return err
}
cmdutil.PrintFlagsWithDryRunStrategy(o.PrintFlags, o.dryRunStrategy)
printer, err := o.PrintFlags.ToPrinter()
if err != nil {
return err
}
o.PrintObj = printer.PrintObj
o.dryRunStrategy, err = cmdutil.GetDryRunStrategy(cmd)
if err != nil {
return err
}
dynamicClient, err := f.DynamicClient()
if err != nil {
return err
@@ -238,7 +240,10 @@ func (o *ScaleOptions) RunScale() error {
for _, info := range infos {
mapping := info.ResourceMapping()
if o.dryRunStrategy == cmdutil.DryRunClient {
return o.PrintObj(info.Object, o.Out)
if err := o.PrintObj(info.Object, o.Out); err != nil {
return err
}
continue
}
if err := o.scaler.Scale(info.Namespace, info.Name, uint(o.Replicas), precondition, retry, waitForReplicas, mapping.Resource, o.dryRunStrategy == cmdutil.DryRunServer); err != nil {