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:
Lucas Servén Marín 2020-05-11 22:50:01 +02:00
parent b188abf0b6
commit 9b19bbe69c
No known key found for this signature in database
GPG Key ID: 586FEAF680DA74AD

View File

@ -280,6 +280,7 @@ func (c *Controller) deleteFromIndex(i int, rules *[]Rule) error {
}
for j := i; j < len(*rules); j++ {
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)
}
(*rules)[j] = nil