Skip to content

Commit bba74db

Browse files
authored
[release-0.8] fix: handle nil Completions in coordinator validation (#935)
* fix: handle nil Completions in coordinator validation * fixup! fix: handle nil Completions in coordinator validation * fixup! fix: handle nil Completions in coordinator validation
1 parent c51aef3 commit bba74db

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

pkg/webhooks/jobset_webhook.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,9 @@ func validateCoordinator(js *jobset.JobSet) error {
375375
return fmt.Errorf("coordinator job index %d is invalid for replicatedJob %s", js.Spec.Coordinator.JobIndex, replicatedJob.Name)
376376
}
377377

378-
// Validate job is using indexed completion mode.
379-
if replicatedJob.Template.Spec.CompletionMode == nil || *replicatedJob.Template.Spec.CompletionMode != batchv1.IndexedCompletion {
380-
return fmt.Errorf("job for coordinator pod must be indexed completion mode")
378+
// Validate job is using indexed completion mode and completions number is set.
379+
if replicatedJob.Template.Spec.CompletionMode == nil || replicatedJob.Template.Spec.Completions == nil || *replicatedJob.Template.Spec.CompletionMode != batchv1.IndexedCompletion {
380+
return fmt.Errorf("job for coordinator pod must be indexed completion mode, and completions number must be set")
381381
}
382382

383383
// Validate Pod index.

pkg/webhooks/jobset_webhook_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,46 @@ func TestValidateCreate(t *testing.T) {
14031403
fmt.Errorf("coordinator replicatedJob fake-rjob does not exist"),
14041404
),
14051405
},
1406+
{
1407+
name: "coordinator replicated job missing completions",
1408+
js: &jobset.JobSet{
1409+
ObjectMeta: validObjectMeta,
1410+
Spec: jobset.JobSetSpec{
1411+
Coordinator: &jobset.Coordinator{
1412+
ReplicatedJob: "replicatedjob-a",
1413+
JobIndex: 0,
1414+
PodIndex: 0,
1415+
},
1416+
ReplicatedJobs: []jobset.ReplicatedJob{
1417+
{
1418+
Name: "replicatedjob-a",
1419+
Replicas: 2,
1420+
Template: batchv1.JobTemplateSpec{
1421+
Spec: batchv1.JobSpec{
1422+
CompletionMode: ptr.To(batchv1.IndexedCompletion),
1423+
Parallelism: ptr.To(int32(2)),
1424+
},
1425+
},
1426+
},
1427+
{
1428+
Name: "replicatedjob-b",
1429+
Replicas: 2,
1430+
Template: batchv1.JobTemplateSpec{
1431+
Spec: batchv1.JobSpec{
1432+
CompletionMode: ptr.To(batchv1.IndexedCompletion),
1433+
Completions: ptr.To(int32(2)),
1434+
Parallelism: ptr.To(int32(2)),
1435+
},
1436+
},
1437+
},
1438+
},
1439+
SuccessPolicy: &jobset.SuccessPolicy{},
1440+
},
1441+
},
1442+
want: errors.Join(
1443+
fmt.Errorf("job for coordinator pod must be indexed completion mode, and completions number must be set"),
1444+
),
1445+
},
14061446
{
14071447
name: "coordinator job index invalid",
14081448
js: &jobset.JobSet{

0 commit comments

Comments
 (0)