-
Notifications
You must be signed in to change notification settings - Fork 834
feat(operator): Add validation for required containers in replicatedJobs #2722
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
Changes from all commits
cff6790
0efd0f8
6f849f0
0797125
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -18,6 +18,7 @@ package webhooks | |||||||||
|
||||||||||
import ( | ||||||||||
"context" | ||||||||||
"fmt" | ||||||||||
|
||||||||||
apiruntime "k8s.io/apimachinery/pkg/runtime" | ||||||||||
"k8s.io/apimachinery/pkg/util/sets" | ||||||||||
|
@@ -34,7 +35,16 @@ import ( | |||||||||
) | ||||||||||
|
||||||||||
const ( | ||||||||||
rJobReplicasErrorMsg = "always must be 1" | ||||||||||
rJobReplicasErrorMsg = "always must be 1" | ||||||||||
rJobContainerNamesErrorMsg = "must contain the required container for the ancestor: %s" | ||||||||||
) | ||||||||||
|
||||||||||
var ( | ||||||||||
expectedContainerNames = map[string]string{ | ||||||||||
constants.AncestorTrainer: constants.Node, | ||||||||||
constants.ModelInitializer: constants.ModelInitializer, | ||||||||||
constants.DatasetInitializer: constants.DatasetInitializer, | ||||||||||
} | ||||||||||
) | ||||||||||
|
||||||||||
type TrainingRuntimeWebhook struct { | ||||||||||
|
@@ -67,18 +77,35 @@ func validateReplicatedJobs(rJobs []jobsetv1alpha2.ReplicatedJob) field.ErrorLis | |||||||||
Child("replicatedJobs") | ||||||||||
var allErrs field.ErrorList | ||||||||||
for idx, rJob := range rJobs { | ||||||||||
if rJob.Name == constants.Launcher && rJob.Replicas != 1 { | ||||||||||
allErrs = append(allErrs, field.Invalid(rJobsPath.Index(idx).Child("replicas"), rJob.Replicas, rJobReplicasErrorMsg)) | ||||||||||
} | ||||||||||
|
||||||||||
if rJob.Template.Labels == nil { | ||||||||||
continue | ||||||||||
} | ||||||||||
|
||||||||||
if labelAncestor, ok := rJob.Template.Labels[constants.LabelTrainJobAncestor]; ok && ancestors.Has(labelAncestor) && rJob.Replicas != 1 { | ||||||||||
allErrs = append(allErrs, field.Invalid(rJobsPath.Index(idx).Child("replicas"), rJob.Replicas, rJobReplicasErrorMsg)) | ||||||||||
if labelAncestor, ok := rJob.Template.Labels[constants.LabelTrainJobAncestor]; ok && ancestors.Has(labelAncestor) { | ||||||||||
if rJob.Replicas != 1 { | ||||||||||
allErrs = append(allErrs, field.Invalid(rJobsPath.Index(idx).Child("replicas"), rJob.Replicas, rJobReplicasErrorMsg)) | ||||||||||
} | ||||||||||
|
||||||||||
// Validate replicated job contains the required containers. | ||||||||||
// Mapping of the ancestor labels to the containers: | ||||||||||
// 1. dataset-initializer - dataset-initializer | ||||||||||
// 2. model-initializer - model-initializer | ||||||||||
// 3. trainer - node | ||||||||||
hasRequiredContainer := false | ||||||||||
for _, container := range rJob.Template.Spec.Template.Spec.Containers { | ||||||||||
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. I wonder how difficult that would be to implement this validation in CEL? 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. Hmm. These fields are defined in JobSetSpec: trainer/pkg/apis/trainer/v1alpha1/trainingruntime_types.go Lines 132 to 134 in 467322a
I'm not sure whether can we reference the container name in it (detecting corresponding label) and verify its value. In the contrast, I think webhook is more convenient and do not need to change the API by adding something like:
|
||||||||||
if container.Name == expectedContainerNames[labelAncestor] { | ||||||||||
hasRequiredContainer = true | ||||||||||
break | ||||||||||
} | ||||||||||
} | ||||||||||
if !hasRequiredContainer { | ||||||||||
allErrs = append(allErrs, field.Invalid( | ||||||||||
rJobsPath.Index(idx).Child("template").Child("spec").Child("template").Child("spec").Child("containers"), | ||||||||||
rJob.Template.Spec.Template.Spec.Containers, | ||||||||||
fmt.Sprintf(rJobContainerNamesErrorMsg, labelAncestor), | ||||||||||
)) | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
} | ||||||||||
return allErrs | ||||||||||
} | ||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.