-
Notifications
You must be signed in to change notification settings - Fork 8
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
Support for loading all rules in one command #7
Support for loading all rules in one command #7
Conversation
f13c4a6
to
f6c6172
Compare
f6c6172
to
e10e126
Compare
@danwinship @aojea hoping to get your thoughts on this one. I could also reasonably see this functionality being exposed through a different function on the interface (e.g., |
if chain == "" { | ||
cmd = exec.CommandContext(ctx, nft.path, "--json", "list", "table", string(nft.family), nft.table) | ||
} else { | ||
cmd = exec.CommandContext(ctx, nft.path, "--json", "list", "chain", string(nft.family), nft.table, chain) | ||
} |
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.
this seems a bit of a stretch for an API, since now it list chains and rules based on a special input
I'm not quite familiar with the implementation, @danwinship should know better, but does the other generic methods in this file List(ctx context.Context, objectType string) ([]string, error)
or ListElements
do not solve the problem?
If not, should we add a new method?
The Though part of the reason I haven't yet is because I keep ending up not actually needing to use But anyway, I don't object to this patch
Right. IPTables kube-proxy sort of does this too (nftables kube-proxy doesn't yet), but it doesn't bother with actually looking at the rules, it just computes diffs between "what I assume the rules must look like based on my previous state" and "what I want the rules to look like based on my current state", and does a partial update based on that, and if it fails, it just overwrites everything, ensuring the expected state will be correct next time. I'm expecting to do it the same way in the nftables backend. (Of course, part of the reason iptables does it that way is because The other reason for not listing the rules is because it's sometimes hard to match up the rules as returned from |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: caseydavenport, danwinship The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@danwinship thanks!
Yeah, that's right - Calico hashes its own "canonical" representation of the rule and stores that in a comment, so it can read back the comments and compare hashes to determine if a rule matches what it expects without caring that the actual rule text returned may not match.
Yep, one of the things on my roadmap is to leverage maps more but for now I've largely been porting existing iptables patterns in order to get an MVP working quicker.
I am not immediately aware of a reason Calico would need that, but will let you know if that changes :) |
I've been working with knftables for prototyping Calico's nftables network policy implementation and have found it innefficient to list rules from each chain individually, where Calico usually wants to cache the full set of rules to more effeciently calculate diffs in future updates.
This change allows calls to
ListRules
without specifying a chain name to return the full set of rules in the table in a single call.