add validation test case for immutable completions on indexed jobs when AllowElasticIndexedJobs is false

This commit is contained in:
Daniel Vega-Myhre 2023-02-23 21:05:03 +00:00
parent 15077a0f28
commit 8d31da4599
2 changed files with 18 additions and 3 deletions

View File

@ -935,6 +935,22 @@ func TestValidateJobUpdate(t *testing.T) {
Field: "spec.completions",
},
},
"immutable completions for indexed job when AllowElasticIndexedJobs is false": {
old: batch.Job{
ObjectMeta: metav1.ObjectMeta{Name: "abc", Namespace: metav1.NamespaceDefault},
Spec: batch.JobSpec{
Selector: validGeneratedSelector,
Template: validPodTemplateSpecForGenerated,
},
},
update: func(job *batch.Job) {
job.Spec.Completions = pointer.Int32Ptr(1)
},
err: &field.Error{
Type: field.ErrorTypeInvalid,
Field: "spec.completions",
},
},
"immutable selector": {
old: batch.Job{
ObjectMeta: metav1.ObjectMeta{Name: "abc", Namespace: metav1.NamespaceDefault},

View File

@ -184,11 +184,10 @@ func validationOptionsForJob(newJob, oldJob *batch.Job) batchvalidation.JobValid
notStarted := oldJob.Status.StartTime == nil
opts.AllowMutableSchedulingDirectives = utilfeature.DefaultFeatureGate.Enabled(features.JobMutableNodeSchedulingDirectives) &&
suspended && notStarted
// Elastic indexed jobs (mutable completions iff updated parallelism == updated completions)
opts.AllowElasticIndexedJobs = utilfeature.DefaultFeatureGate.Enabled(features.ElasticIndexedJob)
}
// Elastic indexed jobs (mutable completions iff updated parallelism == updated completions)
opts.AllowElasticIndexedJobs = utilfeature.DefaultFeatureGate.Enabled(features.ElasticIndexedJob)
return opts
}