From 74e63c8f0005c9d8504be072aa60e6b5455b7176 Mon Sep 17 00:00:00 2001 From: Gustav Westling Date: Tue, 2 Oct 2018 21:56:57 +0200 Subject: [PATCH] Fix dry-run output in kubectl apply --prune Makes dry-run output match what would happen when running in non dry-run mode. Objects would only get added to visitedUids if running in non dry-run mode. visitedUids is used by prune() to know if an action should be taked on the item or not. Fixes #67863 --- pkg/kubectl/cmd/apply/apply.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/kubectl/cmd/apply/apply.go b/pkg/kubectl/cmd/apply/apply.go index 4f1e3d6d040..08919f23b2b 100644 --- a/pkg/kubectl/cmd/apply/apply.go +++ b/pkg/kubectl/cmd/apply/apply.go @@ -389,13 +389,14 @@ func (o *ApplyOptions) Run() error { return cmdutil.AddSourceToErr("creating", info.Source, err) } info.Refresh(obj, true) - metadata, err := meta.Accessor(info.Object) - if err != nil { - return err - } - visitedUids.Insert(string(metadata.GetUID())) } + metadata, err := meta.Accessor(info.Object) + if err != nil { + return err + } + visitedUids.Insert(string(metadata.GetUID())) + count++ if printObject { @@ -410,12 +411,13 @@ func (o *ApplyOptions) Run() error { return printer.PrintObj(info.Object, o.Out) } - if !o.DryRun { - metadata, err := meta.Accessor(info.Object) - if err != nil { - return err - } + metadata, err := meta.Accessor(info.Object) + if err != nil { + return err + } + visitedUids.Insert(string(metadata.GetUID())) + if !o.DryRun { annotationMap := metadata.GetAnnotations() if _, ok := annotationMap[corev1.LastAppliedConfigAnnotation]; !ok { fmt.Fprintf(o.ErrOut, warningNoLastAppliedConfigAnnotation, o.cmdBaseName) @@ -443,8 +445,6 @@ func (o *ApplyOptions) Run() error { info.Refresh(patchedObject, true) - visitedUids.Insert(string(metadata.GetUID())) - if string(patchBytes) == "{}" && !printObject { count++