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,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++