Repository navigation
[Bug] Reject invalid Volcano gang scheduling configuration in StormService webhook - #2629
Conversation
…rvice webhook Signed-off-by: Alex Jia <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces validation for Volcano scheduling strategies within the StormService webhook, ensuring configurations like minMember and minTaskMember are valid and mutually exclusive when defined at both the RoleSet and Role levels. It also includes comprehensive unit tests to verify these validation rules. Feedback on the changes suggests adding a nil check on the old object during updates to prevent potential nil pointer dereference panics, and setting taskMembersValid to false when a task name is invalid to avoid misleading validation errors regarding the sum of task members.
| oldStormService, ok := oldObj.(*orchestrationv1alpha1.StormService) | ||
| if !ok || !equality.Semantic.DeepEqual(oldStormService.Spec.Template.Spec, stormService.Spec.Template.Spec) { |
There was a problem hiding this comment.
To prevent potential nil pointer dereference panics (e.g., if oldObj is a typed nil pointer, where the type assertion succeeds but the value is nil), we should explicitly check if oldStormService is nil before accessing its fields.
| oldStormService, ok := oldObj.(*orchestrationv1alpha1.StormService) | |
| if !ok || !equality.Semantic.DeepEqual(oldStormService.Spec.Template.Spec, stormService.Spec.Template.Spec) { | |
| oldStormService, ok := oldObj.(*orchestrationv1alpha1.StormService) | |
| if !ok || oldStormService == nil || !equality.Semantic.DeepEqual(oldStormService.Spec.Template.Spec, stormService.Spec.Template.Spec) { |
| if !taskNames.Has(key) { | ||
| allErrs = append(allErrs, field.Invalid(keyPath, key, | ||
| fmt.Sprintf("must match a role name; valid names are: %s", strings.Join(sets.List(taskNames), ", ")))) | ||
| } |
There was a problem hiding this comment.
If a minTaskMember key does not match any valid role name, the task member configuration is invalid. We should set taskMembersValid = false to prevent triggering the subsequent minMember sum validation error, which would otherwise include the invalid key's value in the sum and produce a confusing error message.
| if !taskNames.Has(key) { | |
| allErrs = append(allErrs, field.Invalid(keyPath, key, | |
| fmt.Sprintf("must match a role name; valid names are: %s", strings.Join(sets.List(taskNames), ", ")))) | |
| } | |
| if !taskNames.Has(key) { | |
| taskMembersValid = false | |
| allErrs = append(allErrs, field.Invalid(keyPath, key, | |
| fmt.Sprintf("must match a role name; valid names are: %s", strings.Join(sets.List(taskNames), ", ")))) | |
| } |
googs1025
left a comment
There was a problem hiding this comment.
plz also add integration test case : in test/integration/webhook
There was a problem hiding this comment.
Pull request overview
Adds webhook validation to reject invalid Volcano gang scheduling configurations on StormService RoleSet templates, returning aggregated Invalid errors with precise field paths. Update-time validation is intended to be “ratcheted” so pre-existing invalid objects can still receive metadata-only updates (e.g., finalizer removal).
Changes:
- Validate Volcano gang scheduling fields (
minMember,minTaskMembervalues/keys, andminMembervsminTaskMembersum) and reject invalid configs viaapierrors.NewInvalid. - Reject mixed RoleSet-level and Role-level
schedulingStrategyas mutually exclusive. - Add unit tests covering each rule and the update ratcheting behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/webhook/stormservice_webhook.go | Adds scheduling strategy validation and update-time ratcheting logic. |
| pkg/webhook/stormservice_webhook_test.go | Adds unit tests for validation rules and update behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| // Re-validate the scheduling strategy only when the RoleSet template changed. Objects that | ||
| // predate this validation must keep accepting metadata-only updates, in particular the | ||
| // controller's finalizer removal, or they could never be deleted. | ||
| oldStormService, ok := oldObj.(*orchestrationv1alpha1.StormService) | ||
| if !ok || !equality.Semantic.DeepEqual(oldStormService.Spec.Template.Spec, stormService.Spec.Template.Spec) { | ||
| if err := validateStormServiceSchedulingStrategy(stormService); err != nil { | ||
| return nil, err | ||
| } | ||
| } |
just added |
9f20d14 to
55acdee
Compare
Signed-off-by: Alex Jia <[email protected]>
55acdee to
8582d6b
Compare
|
|
||
| // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type | ||
| func (r *StormServiceCustomDefaulter) ValidateUpdate(_ context.Context, _, newObj runtime.Object) (admission.Warnings, error) { | ||
| func (r *StormServiceCustomDefaulter) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { |
There was a problem hiding this comment.
Maybe we can narrow this update-time ratcheting check instead of comparing the whole Template.Spec.
I don't think we should skip scheduling validation on update completely, because a user could create a valid StormService and later update it into an invalid Volcano gang config. But comparing the whole template seems broader than this validation needs: sidecar defaulting or unrelated role/template changes could make an old object fail the new validation even when the scheduling config was not touched.
Would it be better to rerun validateStormServiceSchedulingStrategy only when the fields it depends on changed, e.g. the RoleSet-level schedulingStrategy, role names, or each role's schedulingStrategy?
There was a problem hiding this comment.
Makes sense, just updated to re run the scheduling validation only when the RoleSet-level strategy, a role name, or a role's strategy changes. Unrelated template changes and sidecar injection no longer trigger it, and editing a valid object into an invalid gang config is still rejected.
Signed-off-by: Alex Jia <[email protected]>
googs1025
left a comment
There was a problem hiding this comment.
LGTM. thanks for this fix
Pull Request Description
The StormService webhook now rejects Volcano gang scheduling configurations that the controller or Volcano cannot accept, instead of silently accepting them:
volcanoSchedulingStrategy.minMembermust be greater than 0.minTaskMembervalue must be greater than 0.minTaskMemberkey must match a role name (for a Role-level strategy, only that role's own name).minMembermust not be smaller than the sum ofminTaskMembervalues, since Volcano skips all per-task checks otherwise.spec.template.spec.schedulingStrategyandroles[].schedulingStrategycannot be set together; the controller treats them as mutually exclusive.All violations are returned in one
Invaliderror with field paths. On update, the check only runs when the RoleSet template changed, so objects created before this validation can still be updated and deleted.Testing: unit tests in
pkg/webhook/stormservice_webhook_test.gocover every rule and the update ratcheting;golangci-lintandgo build ./...pass.Related Issues
Resolves: #2619 scope 1
Important: Before submitting, please complete the description above and review the checklist below.
Contribution Guidelines (Expand for Details)
We appreciate your contribution to aibrix! To ensure a smooth review process and maintain high code quality, please adhere to the following guidelines:
Pull Request Title Format
Your PR title should start with one of these prefixes to indicate the nature of the change:
[Bug]: Corrections to existing functionality[CI]: Changes to build process or CI pipeline[Docs]: Updates or additions to documentation[API]: Modifications to aibrix's API or interface[CLI]: Changes or additions to the Command Line Interface[Misc]: For changes not covered above (use sparingly)Note: For changes spanning multiple categories, use multiple prefixes in order of importance.
Submission Checklist
By submitting this PR, you confirm that you've read these guidelines and your changes align with the project's contribution standards.