From adeb6f40c22fd001f42b1dd70c199e7ddf59c6e0 Mon Sep 17 00:00:00 2001 From: Hitoyoshi Ohta Date: Tue, 13 Feb 2024 13:34:44 +0900 Subject: [PATCH] Skip update when resource has keep policy and is not in original release Signed-off-by: Hitoyoshi Ohta --- pkg/kube/client.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/kube/client.go b/pkg/kube/client.go index 9df833a43..876bdbae9 100644 --- a/pkg/kube/client.go +++ b/pkg/kube/client.go @@ -417,6 +417,17 @@ func (c *Client) Update(original, target ResourceList, force bool) (*Result, err originalInfo := original.Get(info) if originalInfo == nil { + annotations, err := metadataAccessor.Annotations(info.Object) + if err != nil { + c.Log("Unable to get annotations on %q, err: %s", info.Name, err) + } + + // Since the target resource remains due to resource policy but is not in the original release + if annotations != nil && annotations[ResourcePolicyAnno] == KeepPolicy { + c.Log("Skipping update of %q due to annotation [%s=%s]", info.Name, ResourcePolicyAnno, KeepPolicy) + return nil + } + kind := info.Mapping.GroupVersionKind.Kind return errors.Errorf("no %s with the name %q found", kind, info.Name) }