Skip to content

Commit 53e45c8

Browse files
authored
[NPM] better error handling and cache building (#848)
* [NPM] better error handling and cache building * using const for label operations * tests correction to discard non-exists delete op * cleaning up some stale code * fixing some port issues * Addressing some comments * Addressing some comments * Addressing some comments * fixing a missed ns- prefix while deleting from ns ipset * fixing a missed ns- prefix while deleting from ns ipset * resducing complexity when pod ip changes * Adding some test validations * Adding some test validations * Adding some test validations * removing more unsed fields * removing redundant checks * Adding improvement of podinformer * removing the deepcopy logic * streamlining some redudant log messages * moving a comment
1 parent d816931 commit 53e45c8

File tree

8 files changed

+337
-212
lines changed

8 files changed

+337
-212
lines changed

npm/ipsm/ipsm.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,20 +188,24 @@ func (ipsMgr *IpsetManager) DeleteFromList(listName string, setName string) erro
188188
exists, _ := ipsMgr.SetExists(setName)
189189

190190
// if set does not exist, then return because the ipset call will fail due to set not existing
191+
// TODO make sure these are info and not errors, use NPmErr
191192
if !exists {
192-
return fmt.Errorf("Set [%s] does not exist when attempting to delete from list [%s]", setName, listName)
193+
metrics.SendErrorLogAndMetric(util.IpsmID, "Set [%s] does not exist when attempting to delete from list [%s]", setName, listName)
194+
return nil
193195
}
194196

195197
//Check if list being added exists in the listmap, if it exists we don't care about the set type
196198
exists, listtype := ipsMgr.SetExists(listName)
197199

198200
// if set does not exist, then return because the ipset call will fail due to set not existing
199201
if !exists {
200-
return fmt.Errorf("Set [%s] does not exist when attempting to add to list [%s]", setName, listName)
202+
metrics.SendErrorLogAndMetric(util.IpsmID, "Set [%s] does not exist when attempting to add to list [%s]", setName, listName)
203+
return nil
201204
}
202205

203206
if listtype != util.IpsetSetListFlag {
204-
return fmt.Errorf("Set [%s] is of the wrong type when attempting to delete list [%s], actual type [%s]", setName, listName, listtype)
207+
metrics.SendErrorLogAndMetric(util.IpsmID, "Set [%s] is of the wrong type when attempting to delete list [%s], actual type [%s]", setName, listName, listtype)
208+
return nil
205209
}
206210

207211
if _, exists := ipsMgr.ListMap[listName]; !exists {
@@ -552,7 +556,6 @@ func (ipsMgr *IpsetManager) DestroyNpmIpsets() error {
552556
return nil
553557
}
554558

555-
log.Logf("{DestroyNpmIpsets} Reply from command %s executed is %s", cmdName+" "+cmdArgs, reply)
556559
re := regexp.MustCompile("Name: (" + util.AzureNpmPrefix + "\\d+)")
557560
ipsetRegexSlice := re.FindAllSubmatch(reply, -1)
558561

npm/ipsm/ipsm_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,12 @@ func TestDeleteFromList(t *testing.T) {
138138
}
139139

140140
// Delete set from list and validate set is not in list anymore.
141-
if err := ipsMgr.DeleteFromList(listName, "nonexistentsetname"); err == nil {
141+
if err := ipsMgr.DeleteFromList(listName, "nonexistentsetname"); err != nil {
142142
t.Errorf("TestDeleteFromList failed @ ipsMgr.DeleteFromList %v", err)
143143
}
144144

145145
// Delete set from list, but list isn't of list type
146-
if err := ipsMgr.DeleteFromList(setName, setName); err == nil {
146+
if err := ipsMgr.DeleteFromList(setName, setName); err != nil {
147147
t.Errorf("TestDeleteFromList failed @ ipsMgr.DeleteFromList %v", err)
148148
}
149149

0 commit comments

Comments
 (0)