Просмотр исходного кода

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>
Lucas Servén Marín 6 лет назад
Родитель
Сommit
9b19bbe69c
1 измененных файлов с 1 добавлено и 0 удалено
  1. 1 0
      pkg/iptables/iptables.go

+ 1 - 0
pkg/iptables/iptables.go

@@ -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