From 4089fe0d03279475593031476916ae719783522c Mon Sep 17 00:00:00 2001 From: skydai Date: Tue, 1 Dec 2020 11:42:49 +0800 Subject: [PATCH] fix(pkg/kube/client.go): cannot upgrade release after upgrade release failed in a certain case In a certain case, if charts updates with add a new k8s resource, and upgrade release failed. The failed reason is upgrade other res ources failed excepet the n ew k8s resource. In this case, results cannot upgrade success anymore, it would throw an error like that " no %s with the name %q found"(release not found) Signed-off-by: skydai --- pkg/kube/client.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/pkg/kube/client.go b/pkg/kube/client.go index 795ebb388..b8b8bc7b7 100644 --- a/pkg/kube/client.go +++ b/pkg/kube/client.go @@ -211,8 +211,21 @@ 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) + c.Log("Warning: %s/%s is found in k8s, but not found in previous release info", info.Namespace, info.Name) + c.Log("Deleting %q in %s...", info.Name, info.Namespace) + if err := deleteResource(info); err != nil { + c.Log("Failed to delete %q, err: %s", info.Name, err) + return errors.Wrap(err, "Failed to delete resource") + } + res.Deleted = append(res.Deleted, info) + + if err := createResource(info); err != nil { + return errors.Wrap(err, "failed to create resource") + } + + // Append the created resource to the results + res.Created = append(res.Created, info) + return nil } if err := updateResource(c, info, originalInfo.Object, force); err != nil {