-
Notifications
You must be signed in to change notification settings - Fork 262
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 CEL rules to Workload #2008
Add CEL rules to Workload #2008
Conversation
Hi @IrvingMg. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
✅ Deploy Preview for kubernetes-sigs-kueue canceled.
|
7e75cde
to
eb974eb
Compare
/ok-to-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.
/lgtm
LGTM label has been added. Git tree hash: 7f9bd6f6022944ae873a72fa9ea393f4f55c5dab
|
apis/kueue/v1beta1/workload_types.go
Outdated
@@ -336,6 +359,11 @@ const ( | |||
// +kubebuilder:resource:shortName={wl} | |||
|
|||
// Workload is the Schema for the workloads API | |||
// +kubebuilder:validation:XValidation:rule="has(self.spec) && has(self.status) && has(self.status.conditions) && self.status.conditions.exists(c, c.type == 'QuotaReserved' && c.status == 'True') && has(self.status.admission) ? size(self.spec.podSets) == size(self.status.admission.podSetAssignments) : true", message="podSetAssignments must have the same number of podSets as the spec" |
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.
spec and status always exist. Apply the same for all rules.
.conditions.exist
should already cover for has
, I would think.
// +kubebuilder:validation:XValidation:rule="has(self.spec) && has(self.status) && has(self.status.conditions) && self.status.conditions.exists(c, c.type == 'QuotaReserved' && c.status == 'True') && has(self.status.admission) ? size(self.spec.podSets) == size(self.status.admission.podSetAssignments) : true", message="podSetAssignments must have the same number of podSets as the spec" | |
// +kubebuilder:validation:XValidation:rule="self.status.conditions.exists(c, c.type == 'QuotaReserved' && c.status == 'True') && has(self.status.admission) ? size(self.spec.podSets) == size(self.status.admission.podSetAssignments) : true", message="podSetAssignments must have the same number of podSets as the spec" |
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.
Dropping has(self.status)
check causes most of the workload tests to fail due to unexisting status
field. For example this is one of the test cases which fails when skipping the status check.
An alternative could be using CEL optional types, that way we can leave just has(oldSelf.?status.conditions)
. However, optional types require Kubernetes 1.29.
Maybe we can just remove the spec
checks for now and for status
add this issue to #1986?
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.
Interesting. I guess it's because of the omitempty
for status. But yes, let's drop has(self.spec)
and has (self.status.conditions)
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've removed has(self.spec)
successfully, however, it seems we still need has (self.status.conditions)
since self.status.conditions.exists()
returns the error no such key: conditions
when conditions are empty.
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.
Ah gotcha.
I still see has(oldSelf.spec)
, however.
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 updated rules without the spec check should be visible now :)
apis/kueue/v1beta1/workload_types.go
Outdated
@@ -336,6 +359,11 @@ const ( | |||
// +kubebuilder:resource:shortName={wl} | |||
|
|||
// Workload is the Schema for the workloads API | |||
// +kubebuilder:validation:XValidation:rule="has(self.spec) && has(self.status) && has(self.status.conditions) && self.status.conditions.exists(c, c.type == 'QuotaReserved' && c.status == 'True') && has(self.status.admission) ? size(self.spec.podSets) == size(self.status.admission.podSetAssignments) : true", message="podSetAssignments must have the same number of podSets as the spec" |
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.
Interesting. I guess it's because of the omitempty
for status. But yes, let's drop has(self.spec)
and has (self.status.conditions)
PodSets( | ||
*testing.MakePodSet("first", 1).Obj(), | ||
*testing.MakePodSet("second", 1).Obj(), | ||
). |
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.
Why not pass the admission check through the wrapper?
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.
Since we're using the function workload.SetAdmissionCheckState()
, I haven´t found a wrapper that returns a kueue.AdmissionCheckState
. As I see in other cases, to set an admission check state, we pass the object directly as an argument.
0573521
to
38d9750
Compare
/test pull-kueue-test-e2e-main-1-29 |
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.
/lgtm
/approve
Thanks!
LGTM label has been added. Git tree hash: 3eb6bcc3ce5cdd6e75f5292102b96fe8d69ba42a
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alculquicondor, IrvingMg 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 |
* Add CEL rules to Workload * Remove workload defaulter * Remove test cases validated by CEL rules * Update test descriptions * Refactoring integration tests * Restore validateAdmissionUpdate function * Restore defaulting for minCount * Simplify error checks * Update workload cel rules * Restore podSets immutability validation via webhook
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
It replaces some of the validations executed by webhooks for the Workload type with CRD validation rules.
Which issue(s) this PR fixes:
Fixes #463
Special notes for your reviewer:
Only validation rules with a cost within the API server limits have been added.
Does this PR introduce a user-facing change?