fix(helm): should not fail when delete got not found error, and add a unit test for this case

Signed-off-by: dayeguilaiye <979014041@qq.com>
pull/12299/head
dayeguilaiye 1 year ago
parent 3ef1532a7f
commit 3367e4adb8

@ -447,7 +447,9 @@ func (c *Client) Update(original, target ResourceList, force bool) (*Result, err
}
if err := deleteResource(info, metav1.DeletePropagationBackground); err != nil {
c.Log("Failed to delete %q, err: %s", info.ObjectName(), err)
updateErrors = append(updateErrors, err.Error())
if !apierrors.IsNotFound(err) {
updateErrors = append(updateErrors, err.Error())
}
continue
}
res.Deleted = append(res.Deleted, info)

@ -101,7 +101,7 @@ func newTestClient(t *testing.T) *Client {
}
func TestUpdate(t *testing.T) {
listA := newPodList("starfish", "otter", "squid")
listA := newPodList("starfish", "otter", "squid", "notfound")
listB := newPodList("starfish", "otter", "dolphin")
listC := newPodList("starfish", "otter", "dolphin")
listB.Items[0].Spec.Containers[0].Ports = []v1.ContainerPort{{Name: "https", ContainerPort: 443}}
@ -151,6 +151,11 @@ func TestUpdate(t *testing.T) {
return newResponse(200, &listB.Items[1])
case p == "/namespaces/default/pods/squid" && m == "GET":
return newResponse(200, &listB.Items[2])
case p == "/namespaces/default/pods/notfound" && m == "GET":
return newResponse(200, &listA.Items[3])
case p == "/namespaces/default/pods/notfound" && m == "DELETE":
// got the item when GET, but not found when DELETE, it should not fail
return newResponse(404, notFoundBody())
default:
t.Fatalf("unexpected request: %s %s", req.Method, req.URL.Path)
return nil, nil
@ -202,6 +207,8 @@ func TestUpdate(t *testing.T) {
"/namespaces/default/pods:POST",
"/namespaces/default/pods/squid:GET",
"/namespaces/default/pods/squid:DELETE",
"/namespaces/default/pods/notfound:GET",
"/namespaces/default/pods/notfound:DELETE",
}
if len(expectedActions) != len(actions) {
t.Fatalf("unexpected number of requests, expected %d, got %d", len(expectedActions), len(actions))

Loading…
Cancel
Save