-
Notifications
You must be signed in to change notification settings - Fork 3.4k
pkg/labels: print all leaf CIDRs, not just the last one. #28224
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
Conversation
33919a5
to
4829b40
Compare
/test |
4829b40
to
bb33022
Compare
/test |
Confirmed that this works as expected:
|
bb33022
to
b72b0fb
Compare
Rebased, refactored to use a real data structure. This improves performance over the existing, incorrect method as well as my previous naive attempt:
This reduces time from 167µs to 108µs. Fewer allocs, too. |
b72b0fb
to
e49753d
Compare
Code golf: got it even faster :-)
|
e49753d
to
9945ca0
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.
Needs a rebase but otherwise LGTM. Nice one 🚀
We might consider adding |
This package implemented a single function and caused import loops. So, just move it up a level to get rid of the loop. Signed-off-by: Casey Callendrello <cdc@isovalent.com>
When printing Labels (e.g. by `cilium identity list`), CIDR labels are de-expanded to only show the relevant ones. For example, the CIDR label 1.1.1.0/24 is under-the-hood expanded to 0.0.0.0/0, 0.0.0.0/1, ..., 1.1.1.0/23, 1.1.1.0/24. Then, when the identity is printed for human consumption, the CIDR labels are de-expanded. However, this code did not anticipate a single identity having multiple "leaf" CIDR labels. So, change the printing logic to output all interesting CIDRs. This adds a small utility datatype to efficiently prune a tree of cidrs to the leaves. It winds up being about 30% faster than the original, incorrect version. Signed-off-by: Casey Callendrello <cdc@isovalent.com>
9945ca0
to
6967cf1
Compare
/test |
Is anyone still planning to tackle the backports for |
Downgrading the v1.13 label to |
When printing Labels (e.g. by
cilium identity list
), CIDR labels are de-expanded to only show the relevant ones. For example, the CIDR label1.1.1.0/24
is under-the-hood expanded to0.0.0.0/0, 0.0.0.0/1, ..., 1.1.0.0/23, 1.1.1.0/24
. Then, when the identity is printed for human consumption, the CIDR labels are de-expanded. However, this code did not anticipate a single identity having multiple "leaf" CIDR labels.So, change the printing logic to output all interesting CIDRs. This adds a O(N^2) check, but given that N is never over ~100, it shouldn't be an issue.
Note that this output is only for human consumption; it is not persisted or used as an API.