diff --git a/pkg/kube/client.go b/pkg/kube/client.go index 795ebb388..8a295000e 100644 --- a/pkg/kube/client.go +++ b/pkg/kube/client.go @@ -211,8 +211,11 @@ func (c *Client) Update(original, target ResourceList, force bool) (*Result, err originalInfo := original.Get(info) if originalInfo == nil { - kind := info.Mapping.GroupVersionKind.Kind - return errors.Errorf("no %s with the name %q found", kind, info.Name) + if hasResourcePolicyKeep(c, info) { + c.Log("Resource %q not found in current manifest, skip update due to annotation [%s=%s]", info.Name, ResourcePolicyAnno, KeepPolicy) + return nil + } + return errors.Errorf("Cannot update the resource %q, was not found in current manifest", info.Name) } if err := updateResource(c, info, originalInfo.Object, force); err != nil { @@ -239,11 +242,7 @@ func (c *Client) Update(original, target ResourceList, force bool) (*Result, err c.Log("Unable to get obj %q, err: %s", info.Name, err) continue } - annotations, err := metadataAccessor.Annotations(info.Object) - if err != nil { - c.Log("Unable to get annotations on %q, err: %s", info.Name, err) - } - if annotations != nil && annotations[ResourcePolicyAnno] == KeepPolicy { + if hasResourcePolicyKeep(c, info) { c.Log("Skipping delete of %q due to annotation [%s=%s]", info.Name, ResourcePolicyAnno, KeepPolicy) continue } @@ -256,6 +255,14 @@ func (c *Client) Update(original, target ResourceList, force bool) (*Result, err return res, nil } +func hasResourcePolicyKeep(c *Client, info *resource.Info) bool { + annotations, err := metadataAccessor.Annotations(info.Object) + if err != nil { + c.Log("Unable to get annotations on %q, err: %s", info.Name, err) + } + return annotations != nil && annotations[ResourcePolicyAnno] == KeepPolicy +} + // Delete deletes Kubernetes resources specified in the resources list. It will // attempt to delete all resources even if one or more fail and collect any // errors. All successfully deleted items will be returned in the `Deleted`