From e4a607bde5a7f0eb568f89acfb38f0717ea8fc6c Mon Sep 17 00:00:00 2001 From: Hao Zhou Date: Thu, 6 Feb 2025 05:22:22 +0000 Subject: [PATCH] retryOnConflict shouldnt' retry on NotFound --- pkg/ipamd/ipamd.go | 5 +++++ pkg/ipamd/ipamd_test.go | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/ipamd/ipamd.go b/pkg/ipamd/ipamd.go index 3ba394ec5e..9b9b07ccdb 100644 --- a/pkg/ipamd/ipamd.go +++ b/pkg/ipamd/ipamd.go @@ -2001,6 +2001,11 @@ func (c *IPAMContext) AnnotatePod(podName string, podNamespace string, key strin if err == nil && pod == nil { log.Warnf("get a nil pod for pod name %s and namespace %s", podName, podNamespace) } + // since the GetPod() error has been decorated, we have to check key words + // releasedIP is not empty meaning del path + if releasedIP != "" && err != nil && strings.Contains(err.Error(), "not found") { + return nil + } return err } diff --git a/pkg/ipamd/ipamd_test.go b/pkg/ipamd/ipamd_test.go index ef796ac2e4..deaa083f47 100644 --- a/pkg/ipamd/ipamd_test.go +++ b/pkg/ipamd/ipamd_test.go @@ -2295,8 +2295,7 @@ func TestAnnotatePod(t *testing.T) { // Test that delete on a non-existant pod fails without crashing err = mockContext.AnnotatePod("no-exist-name", "no-exist-namespace", "ip-address", "", ipTwo) - assert.Error(t, err) - assert.Equal(t, fmt.Errorf("error while trying to retrieve pod info: pods \"no-exist-name\" not found"), err) + assert.NoError(t, err) } func TestAddFeatureToCNINode(t *testing.T) {