diff --git a/npm/ipsm/ipsm.go b/npm/ipsm/ipsm.go index 9b566ecd4f..6b73e65eb7 100644 --- a/npm/ipsm/ipsm.go +++ b/npm/ipsm/ipsm.go @@ -616,22 +616,22 @@ func (ipsMgr *IpsetManager) DestroyNpmIpsets() error { operationFlag: util.IpsetFlushFlag, set: ipsetName, } - _, flushError := ipsMgr.run(flushEntry) + _, err := ipsMgr.run(flushEntry) + if err != nil { + metrics.SendErrorLogAndMetric(util.IpsmID, "{DestroyNpmIpsets} Error: failed to flush ipset %s", ipsetName) + } + } + for _, ipsetName := range ipsetLists { deleteEntry := &ipsEntry{ operationFlag: util.IpsetDestroyFlag, set: ipsetName, } - _, destroyError := ipsMgr.run(deleteEntry) - - if flushError != nil { - metrics.SendErrorLogAndMetric(util.IpsmID, "{DestroyNpmIpsets} Error: failed to flush ipset %s", ipsetName) - } - if destroyError != nil { + _, err := ipsMgr.run(deleteEntry) + if err != nil { destroyFailureCount++ metrics.SendErrorLogAndMetric(util.IpsmID, "{DestroyNpmIpsets} Error: failed to destroy ipset %s", ipsetName) - } - if flushError == nil || destroyError == nil { + } else { metrics.RemoveAllEntriesFromIPSet(ipsetName) } } diff --git a/npm/ipsm/ipsm_test.go b/npm/ipsm/ipsm_test.go index 9aeff2c5c3..0788f458af 100644 --- a/npm/ipsm/ipsm_test.go +++ b/npm/ipsm/ipsm_test.go @@ -530,8 +530,8 @@ func TestDestroyNpmIpsets(t *testing.T) { {Cmd: []string{"ipset", "-N", "-exist", util.GetHashedName(testSet2Name), "nethash"}}, {Cmd: []string{"ipset", "list"}, Stdout: ipsetListStdout}, {Cmd: []string{"ipset", "-F", "-exist", testSet1Name}}, - {Cmd: []string{"ipset", "-X", "-exist", testSet1Name}}, {Cmd: []string{"ipset", "-F", "-exist", testSet2Name}}, + {Cmd: []string{"ipset", "-X", "-exist", testSet1Name}}, {Cmd: []string{"ipset", "-X", "-exist", testSet2Name}}, }