feat: support plural targetRefs on policies#3581
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3581 +/- ##
==========================================
+ Coverage 68.17% 68.28% +0.11%
==========================================
Files 168 169 +1
Lines 20496 20557 +61
==========================================
+ Hits 13973 14038 +65
+ Misses 5513 5510 -3
+ Partials 1010 1009 -1 ☔ View full report in Codecov by Sentry. |
1fa49b4 to
ea5738c
Compare
|
/retest |
eb8cccc to
6285ffa
Compare
|
/retest |
api/v1alpha1/policy_helpers.go
Outdated
There was a problem hiding this comment.
wouldnt this need more fields so it can also incorporate Kind and Group ?
group: gateway.networking.k8s.io
kind: HTTPRoute
selector/matchLabels:
app: foo
There was a problem hiding this comment.
While it's possible to add this, I don't think it's needed.
The selector is checked only against routes and gateways anyways right now, and if a developer/admin wants to limit the matched policies to a specific kind it's possible to add the kind as a label.
There was a problem hiding this comment.
as a project, we've tried to use strongly typed fields as much as possible, my suggestion would be to provide a kind and group field here along with the labelSelector field
There was a problem hiding this comment.
I think a kind and group field as part of the target selector defeats the purpose here. If I add a kind and group field, then how would that work?
Let's say I want to attach to all of my routes (HTTPRoute, GRPCRoute, TLSRoute, and TCPRoute) to add some default setting. What do I specify in the kind field?
And, considering we enforce that the group field is always a single value using CEL, what should I as a user do with the group field? Fill it, and make sure it always matches the exactly one valid value? Leave it empty and assume that the default single value is being filled in?
There was a problem hiding this comment.
reg attaching to all xRoutes, 4 policies could be created per xRoute or 1 policy could be attached to the Gateway
There was a problem hiding this comment.
I think that since this API still needs some discussion, I will remove the targetSelector for now from the PR and keep only the plural targetRefs in this PR.
The target selectors can be done in a separate PR after the API has been designed and agreed upon.
charts/gateway-addons-helm/README.md
Outdated
There was a problem hiding this comment.
can you rebase ? the changes here are unintentional
There was a problem hiding this comment.
should we change this in a separate PR? It causes a lot of file changes.
There was a problem hiding this comment.
This change didn't cause the file changes. I explicitly chmod-ed the yaml files which were marked as executable so that they wouldn't be.
This change only makes sure that new files being added are created without the executable bit set.
6033d8e to
e8d3afb
Compare
|
Not sure why the docs-lint build step is not successful. It's got something to do with some other change? |
e8d3afb to
d51f777
Compare
|
/retest |
1 similar comment
|
/retest |
Signed-off-by: Lior Okman <[email protected]>
Signed-off-by: Lior Okman <[email protected]>
Signed-off-by: Lior Okman <[email protected]>
Signed-off-by: Lior Okman <[email protected]>
Signed-off-by: Lior Okman <[email protected]>
Signed-off-by: Lior Okman <[email protected]>
Signed-off-by: Lior Okman <[email protected]>
Signed-off-by: Lior Okman <[email protected]>
Signed-off-by: Lior Okman <[email protected]>
BackendTrafficPolicy, EnvoyExtensionPolicy, and SecurityPolicy Signed-off-by: Lior Okman <[email protected]>
Signed-off-by: Lior Okman <[email protected]>
Signed-off-by: Lior Okman <[email protected]>
agreement on how this API should look like. Signed-off-by: Lior Okman <[email protected]>
Signed-off-by: Lior Okman <[email protected]>
Signed-off-by: Lior Okman <[email protected]>
d51f777 to
174eafd
Compare
| // Map of Gateway to the routes attached to it | ||
| gatewayRouteMap := make(map[string]sets.Set[string]) | ||
|
|
||
| handledPolicies := make(map[types.NamespacedName]*egv1a1.BackendTrafficPolicy) |
There was a problem hiding this comment.
curious why we need this map ? if its being used to handle duplicates, any idea how we ended up with duplicates ?
There was a problem hiding this comment.
For example:
There's a gateway with 3 different routes. You create a single policy resource that targets two of those three routes with two different targetRef elements.
This map is a way to prevent the policy resource from being added twice to the res array.
There was a problem hiding this comment.
re-reading, its because we have multiple targetRefs, can we execute res = append(res, policy) right after
for _, currPolicy := range backendTrafficPolicies {
res = append(res, curPolicy)
....
and avoid extra memory
There was a problem hiding this comment.
It's not that simple. The code has two loops, the first handling the policies that target routes and the second handling the targets that target gateways. Once we have multiple targetRefs, it's possible for the same policy to target both a route and a different gateway.
The second loop needs to work on the same deep copy of the policy as the first loop, otherwise the status section of the policy is not correctly updated. If we do as you suggest in the first loop, then the second loop would need to go over all of the content of res and find the correct policy instance if its there. The easy way to do this is like the code does right now.
There was a problem hiding this comment.
ah thanks for explaining
do we want to support a policy targeting a Gateway and HTTPRoute at the same time ? does our library gracefully handle this case when it comes to defaults and overrides ?
There was a problem hiding this comment.
It's no different than two different policies targeting both the gateway and the route. The plural targetRefs is just a form of syntactic sugar.
| ancestorRefs := []gwapiv1a2.ParentReference{ | ||
| parent, | ||
| } | ||
| ancestorRefs := fixCurrentAncestorRefs(policy, parent) |
There was a problem hiding this comment.
nit: prefer
ancestorRefs := getAncestorRefs(policy)
ancestorRefs = append(ancestorRefs, parent)
simplifies reading the code w/o having to read the details in getAncestorRefs
Signed-off-by: Lior Okman <[email protected]>
|
/retest |
What this PR does / why we need it:
This PR adds support for plural
targetRefson the various policies.Which issue(s) this PR fixes:
Fixes #2999