Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #16086 #16312

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions pkg/kubectl/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down