Skip to content

Commit

Permalink
Fix dry-run output in kubectl apply --prune
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zegl committed Nov 11, 2018
1 parent 8307fb2 commit 74e63c8
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions pkg/kubectl/cmd/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -443,8 +445,6 @@ func (o *ApplyOptions) Run() error {

info.Refresh(patchedObject, true)

visitedUids.Insert(string(metadata.GetUID()))

if string(patchBytes) == "{}" && !printObject {
count++

Expand Down

0 comments on commit 74e63c8

Please sign in to comment.