Add support for MatchExpressions #5201
Conversation
api/v1alpha1/policy_helpers.go
Outdated
There was a problem hiding this comment.
Note: empty MatchLabels and and empty MatchExpressions will match everything
There was a problem hiding this comment.
Was this previous behavior with MatchLabels? if not, let's add a release note for a breaking change.
Also, in general, let's document these semantics in the top-level struct.
What's the behavior if both are set? If this is not allowed, maybe we should:
- Enforce it with CEL.
- Move to a new GW-API-like structure where we have a Match type and then the match value
type: LabelSelector
matchLabels:
- foo: bar
- bar:foo
There was a problem hiding this comment.
Was this previous behavior with MatchLabels? if not, let's add a release note for a breaking change.
Yeah - nil/empty set matches everything - see ref
What's the behavior if both are set? If this is not allowed, maybe we should:
They can be used in conjunction with each other - like a regular metav1.LabelSelector. This is similar behaviour to the namespaceSelector on various k8s types.
You can see it in the parsing logic here - https://github.com/kubernetes/apimachinery/blob/a19f1f813776bd4a90401b63a96e07ed847f88d0/pkg/apis/meta/v1/helpers.go#L36
internal/gatewayapi/helpers.go
Outdated
There was a problem hiding this comment.
I didn't see a validation phase after cel but before translation. So for now if we can't parse the selector we match nothing.
There was a problem hiding this comment.
Can you open a follow-up issue so that we don't forget this? If users get trapped in this, it's going to be hard for them to figure out why their change isn't working. So, we should report it somewhere, probably at the resource's status ideally.
internal/gatewayapi/helpers.go
Outdated
There was a problem hiding this comment.
I also didn't see an opportunity to 'cache' the parsing here - if there's a way to do that with envoy gateway code (like some in memory temporal state) let me know
e7fddef to
14f003d
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #5201 +/- ##
=======================================
Coverage 67.98% 67.99%
=======================================
Files 212 212
Lines 33328 33338 +10
=======================================
+ Hits 22659 22667 +8
Misses 9298 9298
- Partials 1371 1373 +2 ☔ View full report in Codecov by Sentry. |
|
thanks @dprotaso, the API looks good, can you also add an e2e to make sure this works |
or at least a translator test. Besides that - looks good. |
Do you have a preference for which resource to do an e2e test with? Any thoughts on this comment? |
|
Weird |
558c0ef to
e624497
Compare
|
I'll add a bad selector test as well |
|
So one thing I realized - if the Thus to report an error to the user we'd need a top-level condition on all the policies. Let me know what you want me to do. |
|
An alternative would be to create cel expressions and hope they never let in any bad selectors to the parse call (still and edge case) |
|
hey @dprotaso can you fix the lint issues |
623ccb5 to
80c2d92
Compare
|
rebased and fixed indentation |
52ade3f to
cc1d764
Compare
cc1d764 to
41d100f
Compare
api/v1alpha1/policy_helpers.go
Outdated
There was a problem hiding this comment.
I'm not sure if it's safe to add omitempty here. like what if a user upgrade -> create something with empty MatchLabels -> downgrade?
I don't know if EG team usually thinks about such scenarios, but at k/k, we do.
There was a problem hiding this comment.
Wouldn't this scenario be fine? eg. a nil map is still a valid map
There was a problem hiding this comment.
I'm not sure how openapi's required would behave with nil map.
There was a problem hiding this comment.
ah good point - also these APIs are marked alpha - so I wonder if there even is a guarantee that downgrades work
There was a problem hiding this comment.
Yeah, so I see it as more about the rule on this project; whether/how much we consider downgrade scenarios.
But, I believe, at least ideally, we should care the downgrading scenario for alpha APIs as well. Especially this change's blast radius could (i.e., we need to check) be terrible since we're not sure how kube-apiserver behaves with CRD update (in our case, version downgrade) that puts required on the existing field, while there're some existing resources that have empty on the field.
The obvious safer way here is to introduce this change at v1alpha2. (but, again, I'd defer to how other maintainers think and how we define the policy within the project)
There was a problem hiding this comment.
thanks for raising this concern @sanposhiho
loosening validation is fine here, would be great to guarantee the downgrade case, and deal with CRD and Image version mismatch, since the API is alpha its fine if we cannot support that
There was a problem hiding this comment.
Sure, then let's go with this current change and future changes for alpha APIs as well.
But, we need to watch out, generally speaking, some changes at CRD could break kube-apiserver layer (like you wouldn't be able to operate resources) when reviewing this kind of API changes.
41d100f to
faac600
Compare
|
e2e is failing, and so is DCO @dprotaso |
faac600 to
16fe877
Compare
Signed-off-by: Dave Protasowski <dprotaso@gmail.com>
Signed-off-by: Dave Protasowski <dprotaso@gmail.com>
Signed-off-by: Dave Protasowski <dprotaso@gmail.com>
Signed-off-by: Dave Protasowski <dprotaso@gmail.com>
Signed-off-by: Dave Protasowski <dprotaso@gmail.com>
Signed-off-by: Dave Protasowski <dprotaso@gmail.com>
Signed-off-by: Dave Protasowski <dprotaso@gmail.com>
Signed-off-by: Dave Protasowski <dprotaso@gmail.com>
Signed-off-by: Dave Protasowski <dprotaso@gmail.com>
16fe877 to
76e5731
Compare
Signed-off-by: Dave Protasowski <dprotaso@gmail.com>
542de7e to
863905c
Compare
|
fixed DCO e2e test failure seems unrelated now |
Signed-off-by: Arko Dasgupta <arkodg@users.noreply.github.com>
What type of PR is this?
This features extends
TargetSelectorto support match expressionsThis affects the following types that embed TargetSelector
BackendTrafficPolicySpec
ClientTrafficPolicySpec
EnvoyExtensionPolicySpec
PolicyTargetReferences
SecurityPolicySpec
What this PR does / why we need it:
This provides further flexibility in matching resources
Which issue(s) this PR fixes:
N/A
Release Notes: Yes