-
Notifications
You must be signed in to change notification settings - Fork 947
fix(k8s): validate shardTaskPatches early and unblock finalizer on deletion #1049
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,36 @@ func (s *DefaultTaskSchedulingStrategy) NeedTaskScheduling() bool { | |
| return s.Spec.TaskTemplate != nil | ||
| } | ||
|
|
||
| // ValidateShardTaskPatches checks that every shardTaskPatch can be successfully | ||
| // merged into a zero-value TaskTemplateSpec. It returns the first error encountered, | ||
| // including the patch index and the raw patch bytes to aid diagnosis. | ||
| func (s *DefaultTaskSchedulingStrategy) ValidateShardTaskPatches() error { | ||
| if len(s.Spec.ShardTaskPatches) == 0 { | ||
| return nil | ||
| } | ||
| // Zero-value base: we check structural correctness in isolation, not against any | ||
| // specific user template, so a bad patch is caught even when TaskTemplate is nil. | ||
| zeroBytes, err := json.Marshal(&sandboxv1alpha1.TaskTemplateSpec{}) | ||
| if err != nil { | ||
| return fmt.Errorf("batchsandbox: failed to marshal zero TaskTemplateSpec: %w", err) | ||
| } | ||
| for i, patch := range s.Spec.ShardTaskPatches { | ||
|
ashishpatel26 marked this conversation as resolved.
|
||
| // Truncate patch in error messages to avoid persisting large blobs in status conditions. | ||
| patchSummary := patch.Raw | ||
| if len(patchSummary) > 200 { | ||
| patchSummary = append(patchSummary[:200], []byte("...(truncated)")...) | ||
|
Comment on lines
+59
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For any patch whose raw JSON is longer than about 214 bytes, Useful? React with 👍 / 👎. |
||
| } | ||
| modified, mergeErr := strategicpatch.StrategicMergePatch(zeroBytes, patch.Raw, &sandboxv1alpha1.TaskTemplateSpec{}) | ||
| if mergeErr != nil { | ||
| return fmt.Errorf("batchsandbox: shardTaskPatches[%d] failed schema validation: patch %s, err %w", i, patchSummary, mergeErr) | ||
| } | ||
| if err = json.Unmarshal(modified, &sandboxv1alpha1.TaskTemplateSpec{}); err != nil { | ||
| return fmt.Errorf("batchsandbox: shardTaskPatches[%d] produced invalid TaskTemplateSpec: patch %s, err %w", i, patchSummary, err) | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // GenerateTaskSpecs generates task specifications for all replicas. | ||
| func (s *DefaultTaskSchedulingStrategy) GenerateTaskSpecs() ([]*api.Task, error) { | ||
| ret := make([]*api.Task, *s.Spec.Replicas) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.