-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add net.cidr_merge function to produce smallest possible list of CIDRs #2713
Add net.cidr_merge function to produce smallest possible list of CIDRs #2713
Conversation
b3699f1
to
9032a8f
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.
Implementation looks good 👍
Just one comment on the tests
topdown/cidr_test.go
Outdated
@@ -44,3 +46,133 @@ func TestNetCIDRExpandCancellation(t *testing.T) { | |||
} | |||
|
|||
} | |||
|
|||
func TestBuiltinNetCIDRMerge(t *testing.T) { |
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 think with our newer externalized topdown test we should change these to be in https://github.com/open-policy-agent/opa/tree/master/test/cases/testdata (see https://github.com/open-policy-agent/opa/blob/master/test/cases/testdata/helloworld/test-helloworld-1.yaml for instructions)
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.
Tests updated to newer format.
9032a8f
to
7e0d4c8
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.
Two minor comments. Other than that LGTM.
ast/builtins.go
Outdated
Name: "net.cidr_merge", | ||
Decl: types.NewFunction( | ||
types.Args( | ||
types.NewArray(nil, types.NewAny(types.S)), |
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.
Is there any reason we can't accept a set of strings as well?
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 was wondering about that, seems like it would be easy enough to add later if anyone needed it too
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.
Updated the builtin to accept set of strings.
- note: netcidrmerge/cidr single subnet | ||
modules: | ||
- | | ||
package generated |
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.
The generated
package was just used for migrating the existing tests. We can just use something a bit more human-friendly for new tests write (e.g., package test
).
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.
It would be worthwhile to add a test case that provides IPs as inputs (not CIDRs) as the function should support both.
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.
Updated package name to test
and added test cases that include IPs.
…t of CIDRs This commit adds a new builtin to merge adjacent subnets and return the smallest possible list of CIDRs. To help with computing CIDR blocks between two IP networks, an implemetation from https://github.com/cilium/cilium is leveraged. Fixes: open-policy-agent#2692 Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
7e0d4c8
to
5cd2c3e
Compare
This commit adds a new builtin to merge adjacent subnets and return the
smallest possible list of CIDRs.
To help with computing CIDR blocks between two
IP networks, an implemetation from https://github.com/cilium/cilium
is leveraged.
Fixes: #2692
Signed-off-by: Ashutosh Narkar anarkar4387@gmail.com