From 68a87e8d32f385cd3ead4e3a45e036fe1ac78b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arda=20G=C3=BC=C3=A7l=C3=BC?= Date: Fri, 2 Dec 2022 16:27:18 +0300 Subject: [PATCH] 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. Kubernetes-commit: 76ee3788ccbac9003e3f24de9000ebd91c27611f --- pkg/cmd/scale/scale.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/cmd/scale/scale.go b/pkg/cmd/scale/scale.go index 2aaa99191..1f1f0a531 100644 --- a/pkg/cmd/scale/scale.go +++ b/pkg/cmd/scale/scale.go @@ -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 {