Skip to content

Commit

Permalink
Refine validation messages for requiring worker replica when elastic …
Browse files Browse the repository at this point in the history
…policy is used

Co-authored-by: ricardov1 <[email protected]>
Co-authored-by: alenawang <[email protected]>
  • Loading branch information
3 people committed Nov 4, 2024
1 parent 603bf22 commit fad6922
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions pkg/webhooks/pytorch/pytorchjob_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@ func validateSpec(spec trainingoperator.PyTorchJobSpec) (admission.Warnings, fie
var warnings admission.Warnings
if spec.ElasticPolicy != nil {
workerReplicaSpec, ok := spec.PyTorchReplicaSpecs[trainingoperator.PyTorchJobReplicaTypeWorker]
if !ok || (workerReplicaSpec.Replicas != nil && int(*workerReplicaSpec.Replicas) < 1) {
workerPath := specPath.Child("pytorchReplicaSpecs").Child("Worker")
allErrs = append(allErrs, field.Required(workerPath, "at least one worker must be configured if elastic policy is used"))
workerPath := specPath.Child("pytorchReplicaSpecs").Child("Worker")
if !ok {
allErrs = append(allErrs, field.Required(workerPath, "must be configured if elastic policy is used"))
} else if workerReplicaSpec.Replicas != nil && int(*workerReplicaSpec.Replicas) < 1 {
workerReplicasPath := workerPath.Child("replicas")
allErrs = append(allErrs, field.Forbidden(workerReplicasPath, "must be at least 1 if elastic policy is used"))
}
if spec.ElasticPolicy.NProcPerNode != nil {
elasticNProcPerNodePath := specPath.Child("elasticPolicy").Child("nProcPerNode")
Expand Down
4 changes: 2 additions & 2 deletions pkg/webhooks/pytorch/pytorchjob_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ func TestValidateV1PyTorchJob(t *testing.T) {
},
},
wantErr: field.ErrorList{
field.Required(field.NewPath("spec", "pytorchReplicaSpecs", "Worker"), "at least one worker must be configured if elastic policy is used"),
field.Required(field.NewPath("spec", "pytorchReplicaSpecs", "Worker"), "must be configured if elastic policy is used"),
},
},
"attempt to configure elasticPolicy when worker replicas is 0": {
Expand Down Expand Up @@ -417,7 +417,7 @@ func TestValidateV1PyTorchJob(t *testing.T) {
},
},
wantErr: field.ErrorList{
field.Required(field.NewPath("spec", "pytorchReplicaSpecs", "Worker"), "at least one worker must be configured if elastic policy is used"),
field.Forbidden(field.NewPath("spec", "pytorchReplicaSpecs", "Worker", "replicas"), "must be at least 1 if elastic policy is used"),
},
},
}
Expand Down

0 comments on commit fad6922

Please sign in to comment.