pkg/iptables: remove nil rules from list on error
Previously, when `deleteFromIndex` exited early due to an error, nil rules would be left in the controller's list of rules, which could provoke a panic on the next reconciliation. This commit ensures that nil rules are removed before an early exit. Fixes: #51 Signed-off-by: Lucas Servén Marín <lserven@gmail.com>
This commit is contained in:
parent
b188abf0b6
commit
9b19bbe69c
@ -280,6 +280,7 @@ func (c *Controller) deleteFromIndex(i int, rules *[]Rule) error {
|
|||||||
}
|
}
|
||||||
for j := i; j < len(*rules); j++ {
|
for j := i; j < len(*rules); j++ {
|
||||||
if err := (*rules)[j].Delete(c.client((*rules)[j].Proto())); err != nil {
|
if err := (*rules)[j].Delete(c.client((*rules)[j].Proto())); err != nil {
|
||||||
|
*rules = append((*rules)[:i], (*rules)[j:]...)
|
||||||
return fmt.Errorf("failed to delete rule: %v", err)
|
return fmt.Errorf("failed to delete rule: %v", err)
|
||||||
}
|
}
|
||||||
(*rules)[j] = nil
|
(*rules)[j] = nil
|
||||||
|
Loading…
Reference in New Issue
Block a user