-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor iptables module to prepare for nftables implementation #1865
Refactor iptables module to prepare for nftables implementation #1865
Conversation
There is now a trafficmngr package that declares the TrafficManager interface. This will allow us to have multiple implementation to manage NATing and forwarding the traffic.
4518c2c
to
2d46bb0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good! I have one suggestion
type TrafficManager interface { | ||
CreateIP4Chain(table, chain string) | ||
CreateIP6Chain(table, chain string) | ||
MasqRules(cluster_cidrs []ip.IP4Net, lease *lease.Lease) []IPTablesRule | ||
MasqIP6Rules(cluster_cidrs []ip.IP6Net, lease *lease.Lease) []IPTablesRule | ||
ForwardRules(flannelNetwork string) []IPTablesRule | ||
SetupAndEnsureIP4Tables(getRules func() []IPTablesRule, resyncPeriod int) | ||
SetupAndEnsureIP6Tables(getRules func() []IPTablesRule, resyncPeriod int) | ||
DeleteIP4Tables(rules []IPTablesRule) error | ||
DeleteIP6Tables(rules []IPTablesRule) error | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the change but taking advantage of it, I think we can refactor code a little bit. I think it is possible to simplify this interface and have only:
- ForwardRulesToAccept (which would be called here: https://github.com/flannel-io/flannel/blob/master/main.go#L356-L362 and would hide most of that code)
- AddMasqRules (which would be called here https://github.com/flannel-io/flannel/blob/master/main.go#L340-L390 and would hide most of that code)
Then, the rest of the calls (recycle, which ends up calling Delete; CreateIPChain...) can be private functions inside the implementation of iptables or nftables. That would also make main.go
a bit cleaner. Right now we are even defining functions https://github.com/flannel-io/flannel/blob/master/main.go#L356-L362 which I find very ugly.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree
I was planning to do that in another PR to keep things readable :-)
I can do it in one PR if you prefer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's also fine for me
Description
This PR creates a trafficmngr package which declares the TrafficManager interface.
This interface holds the currently used chains and rules management functions for the iptables module.
This will allow us to also provide an nftables-based implementation of this interface.
Todos
Release Note