Skip to content
This repository was archived by the owner on Apr 20, 2024. It is now read-only.

Commit 2b60cc5

Browse files
authored
Merge pull request #23 from aojea/mangle
use mangle table for iptables-legacy to be compatible with other comp…
2 parents 6f3f221 + 9625336 commit 2b60cc5

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

cmd/main.go

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
"os"
99
"os/signal"
10+
"time"
1011

1112
"github.com/aojea/kube-netpol/pkg/networkpolicy"
1213
"github.com/prometheus/client_golang/prometheus/promhttp"
@@ -88,4 +89,6 @@ func main() {
8889
case <-ctx.Done():
8990
}
9091

92+
// grace period to cleanup resources
93+
time.Sleep(5 * time.Second)
9194
}

pkg/networkpolicy/controller.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,13 @@ func (c *Controller) syncIptablesRules() {
382382
queueRule = append(queueRule, "--queue-bypass")
383383
}
384384

385-
if err := c.ipt.InsertUnique("filter", "FORWARD", 1, queueRule...); err != nil {
385+
// kube-proxy install the reject rules for Services with Endpoints on the FORWARD hook
386+
// nfqueue either accepts or drops https://netfilter-devel.vger.kernel.narkive.com/dGk9ZPzK/nfqueue-target-with-treat-accept-as-continue
387+
// We can append the rule after the kube-proxy ones, but that will always depend on the order of the components
388+
// to be installed so it will be racy.
389+
// Since nftables does not seem to have that problem and we only offer iptables-legacy for backwards compatibility
390+
// use the mangle table that happens before for filtering.
391+
if err := c.ipt.InsertUnique("mangle", "FORWARD", 1, queueRule...); err != nil {
386392
klog.Infof("error syncing iptables rule %v", err)
387393
}
388394
}
@@ -393,7 +399,7 @@ func (c *Controller) cleanIptablesRules() {
393399
queueRule = append(queueRule, "--queue-bypass")
394400
}
395401

396-
if err := c.ipt.Delete("filter", "FORWARD", queueRule...); err != nil {
402+
if err := c.ipt.Delete("mangle", "FORWARD", queueRule...); err != nil {
397403
klog.Infof("error deleting iptables rule %v", err)
398404
}
399405
}

0 commit comments

Comments
 (0)