From 8d31da4599f67e94498217fe43724acd6c8c0ef2 Mon Sep 17 00:00:00 2001 From: Daniel Vega-Myhre Date: Thu, 23 Feb 2023 21:05:03 +0000 Subject: [PATCH] add validation test case for immutable completions on indexed jobs when AllowElasticIndexedJobs is false --- pkg/apis/batch/validation/validation_test.go | 16 ++++++++++++++++ pkg/registry/batch/job/strategy.go | 5 ++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/pkg/apis/batch/validation/validation_test.go b/pkg/apis/batch/validation/validation_test.go index 4d1c9d97209..9fe06fada50 100644 --- a/pkg/apis/batch/validation/validation_test.go +++ b/pkg/apis/batch/validation/validation_test.go @@ -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}, diff --git a/pkg/registry/batch/job/strategy.go b/pkg/registry/batch/job/strategy.go index e0b3d8104fd..4d485a06428 100644 --- a/pkg/registry/batch/job/strategy.go +++ b/pkg/registry/batch/job/strategy.go @@ -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 }