-
Notifications
You must be signed in to change notification settings - Fork 512
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 initial set of CEL validations for HTTPRoute #2253
Add initial set of CEL validations for HTTPRoute #2253
Conversation
27f092f
to
a8ea615
Compare
|
/check-cla |
a8ea615
to
79f800e
Compare
79f800e
to
adb94d2
Compare
@jpbetz Offered some really GREAT insights into the problems we're facing.
|
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.
Thanks @gauravkghildiyal, this is really great! A few small nits, but overall both the validation and corresponding tests look remarkably thorough.
@@ -91,6 +91,8 @@ type SecretObjectReference struct { | |||
// References to objects with invalid Group and Kind are not valid, and must | |||
// be rejected by the implementation, with appropriate Conditions set | |||
// on the containing object. | |||
// | |||
// +kubebuilder:validation:XValidation:message="Must have port for Service reference",rule="((!has(self.group) || size(self.group) == 0) && (!has(self.kind) || self.kind == 'Service')) ? has(self.port) : true" |
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.
Nit: In my experimenting I thought that defaults applied before CEL validation so it may be possible to simplify this. With that said, I could also be remembering wrong here. In any case this is not a blocker.
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.
Yes you are absolutely right! Sorry didn't notice the defaults. Appreciate the closer look :)
}, | ||
}, | ||
{ | ||
name: "invalid because multipler filters are repeated", |
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.
name: "invalid because multipler filters are repeated", | |
name: "invalid because multiple filters are repeated", |
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.
Thanks! Changed.
}, | ||
}, | ||
{ | ||
name: "valie ReplacePrefixMatch", |
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.
name: "valie ReplacePrefixMatch", | |
name: "valid ReplacePrefixMatch", |
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.
Thanks! Changed
- message: filter.RequestHeaderModifier must be nil | ||
if the HTTPRouteFilter.Type is not RequestHeaderModifier |
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 don't think we've been very consistent with this, but we should try to match the upstream pattern here where field names/paths match what a user would see when using YAML. For example, look at the core validation here: https://github.com/kubernetes/kubernetes/blob/2c6c4566eff972d6c1320b5f8ad795f88c822d09/pkg/apis/core/validation/validation.go#L1041-L1045.
This comment applies throughout the PR, but will not repeat it everywhere to reduce noise.
- message: filter.RequestHeaderModifier must be nil | |
if the HTTPRouteFilter.Type is not RequestHeaderModifier | |
- message: filter.requestHeaderModifier must be nil | |
if the HTTPRouteFilter.Type is not RequestHeaderModifier |
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.
Sure can do! I've changed all such occurrences. The places which are still kept capitalized have the intent of referring to the enum (like RequestRedirect
) instead of the field (requestRedirect
). If in some place, the intent is not clear enough, I can try and reframe the statement.
adb94d2
to
a20f261
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.
Appreciate the thorough reviews!
}, | ||
}, | ||
{ | ||
name: "valie ReplacePrefixMatch", |
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.
Thanks! Changed
}, | ||
}, | ||
{ | ||
name: "invalid because multipler filters are repeated", |
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.
Thanks! Changed.
@@ -91,6 +91,8 @@ type SecretObjectReference struct { | |||
// References to objects with invalid Group and Kind are not valid, and must | |||
// be rejected by the implementation, with appropriate Conditions set | |||
// on the containing object. | |||
// | |||
// +kubebuilder:validation:XValidation:message="Must have port for Service reference",rule="((!has(self.group) || size(self.group) == 0) && (!has(self.kind) || self.kind == 'Service')) ? has(self.port) : true" |
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.
Yes you are absolutely right! Sorry didn't notice the defaults. Appreciate the closer look :)
- message: filter.RequestHeaderModifier must be nil | ||
if the HTTPRouteFilter.Type is not RequestHeaderModifier |
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.
Sure can do! I've changed all such occurrences. The places which are still kept capitalized have the intent of referring to the enum (like RequestRedirect
) instead of the field (requestRedirect
). If in some place, the intent is not clear enough, I can try and reframe the statement.
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.
Thanks @gauravkghildiyal!
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: gauravkghildiyal, robscott 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 |
What type of PR is this?
/kind feature
What this PR does / why we need it:
Add initial set of CEL validations for HTTPRoute.
This includes most (but not all) of the HTTPRoute validations offered by the webhook.
What remains?
Only 2 kinds of validations remain.
The validations which have not been ported along with the reason and details are available in https://github.com/gauravkghildiyal/gateway-api/blob/pending-httproute-validations/apis/v1beta1/validation/httproute.go. All validations which were successfully ported have been removed from this file.
1 "Namespace" is a reserved word in CEL.
Since namespace is a reserved word, a validation that involves a field named

namespace
seems to getting rejected. We need to figure out if there is a way around this.2 Estimated cost limit exceeds threshold
CEL attempts to estimate the runtime cost of a validation. Validations that require O(n^2) algorithms on larger cardinality fields end up crossing the allowed threshold. One such place is within
[]gatewayv1b1.HTTPHeaderMatch
where we want to ensure unique (case-insensitive) header names.Which issue(s) this PR fixes:
Fixes #
Does this PR introduce a user-facing change?: