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
This commit is contained in:
Gustav Westling 2018-10-02 21:56:57 +02:00
parent 8307fb2fb3
commit 74e63c8f00

View File

@ -389,12 +389,13 @@ func (o *ApplyOptions) Run() error {
return cmdutil.AddSourceToErr("creating", info.Source, err) return cmdutil.AddSourceToErr("creating", info.Source, err)
} }
info.Refresh(obj, true) info.Refresh(obj, true)
}
metadata, err := meta.Accessor(info.Object) metadata, err := meta.Accessor(info.Object)
if err != nil { if err != nil {
return err return err
} }
visitedUids.Insert(string(metadata.GetUID())) visitedUids.Insert(string(metadata.GetUID()))
}
count++ count++
@ -410,12 +411,13 @@ func (o *ApplyOptions) Run() error {
return printer.PrintObj(info.Object, o.Out) return printer.PrintObj(info.Object, o.Out)
} }
if !o.DryRun {
metadata, err := meta.Accessor(info.Object) metadata, err := meta.Accessor(info.Object)
if err != nil { if err != nil {
return err return err
} }
visitedUids.Insert(string(metadata.GetUID()))
if !o.DryRun {
annotationMap := metadata.GetAnnotations() annotationMap := metadata.GetAnnotations()
if _, ok := annotationMap[corev1.LastAppliedConfigAnnotation]; !ok { if _, ok := annotationMap[corev1.LastAppliedConfigAnnotation]; !ok {
fmt.Fprintf(o.ErrOut, warningNoLastAppliedConfigAnnotation, o.cmdBaseName) fmt.Fprintf(o.ErrOut, warningNoLastAppliedConfigAnnotation, o.cmdBaseName)
@ -443,8 +445,6 @@ func (o *ApplyOptions) Run() error {
info.Refresh(patchedObject, true) info.Refresh(patchedObject, true)
visitedUids.Insert(string(metadata.GetUID()))
if string(patchBytes) == "{}" && !printObject { if string(patchBytes) == "{}" && !printObject {
count++ count++