From 08b2275129eafd741bb49a746e4562498d30b0bc Mon Sep 17 00:00:00 2001 From: jackgr Date: Wed, 21 Oct 2015 19:18:28 -0700 Subject: [PATCH] Update annotation only if apply already called. --- pkg/kubectl/apply.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/kubectl/apply.go b/pkg/kubectl/apply.go index 8b77abbd1f2..35600fb043d 100644 --- a/pkg/kubectl/apply.go +++ b/pkg/kubectl/apply.go @@ -163,16 +163,25 @@ func GetModifiedConfiguration(info *resource.Info, annotate bool) ([]byte, error return modified, nil } +// If the last applied configuration annotation is already present, then // UpdateApplyAnnotation gets the modified configuration of the object, // without embedding it again, and then sets it on the object as the annotation. +// Otherwise, it does nothing. func UpdateApplyAnnotation(info *resource.Info) error { - modified, err := GetModifiedConfiguration(info, false) + original, err := GetOriginalConfiguration(info) if err != nil { return err } - if err := SetOriginalConfiguration(info, modified); err != nil { - return err + if len(original) > 0 { + modified, err := GetModifiedConfiguration(info, false) + if err != nil { + return err + } + + if err := SetOriginalConfiguration(info, modified); err != nil { + return err + } } return nil