From 9d1838fb647b2d9fcf35f1f20bf2dd9c4b35239f Mon Sep 17 00:00:00 2001 From: Mike Danese Date: Thu, 17 Sep 2015 15:58:04 -0700 Subject: [PATCH] only allow updates of parrallelism in jobspec --- pkg/apis/experimental/validation/validation.go | 17 ++++++++++++++++- pkg/registry/job/etcd/etcd_test.go | 9 +++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/pkg/apis/experimental/validation/validation.go b/pkg/apis/experimental/validation/validation.go index 00651eb6395..c85b7ebdd41 100644 --- a/pkg/apis/experimental/validation/validation.go +++ b/pkg/apis/experimental/validation/validation.go @@ -315,6 +315,21 @@ func ValidateJobSpec(spec *experimental.JobSpec) errs.ValidationErrorList { func ValidateJobUpdate(oldJob, job *experimental.Job) errs.ValidationErrorList { allErrs := errs.ValidationErrorList{} allErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&oldJob.ObjectMeta, &job.ObjectMeta).Prefix("metadata")...) - allErrs = append(allErrs, ValidateJobSpec(&job.Spec).Prefix("spec")...) + allErrs = append(allErrs, ValidateJobSpecUpdate(oldJob.Spec, job.Spec).Prefix("spec")...) + return allErrs +} + +func ValidateJobSpecUpdate(oldSpec, spec experimental.JobSpec) errs.ValidationErrorList { + allErrs := errs.ValidationErrorList{} + allErrs = append(allErrs, ValidateJobSpec(&spec)...) + if !api.Semantic.DeepEqual(oldSpec.Completions, spec.Completions) { + allErrs = append(allErrs, errs.NewFieldInvalid("completions", spec.Completions, "field is immutable")) + } + if !api.Semantic.DeepEqual(oldSpec.Selector, spec.Selector) { + allErrs = append(allErrs, errs.NewFieldInvalid("selector", spec.Selector, "field is immutable")) + } + if !api.Semantic.DeepEqual(oldSpec.Template, spec.Template) { + allErrs = append(allErrs, errs.NewFieldInvalid("template", "[omitted]", "field is immutable")) + } return allErrs } diff --git a/pkg/registry/job/etcd/etcd_test.go b/pkg/registry/job/etcd/etcd_test.go index 2f04c1fa6b3..8f3587902c0 100644 --- a/pkg/registry/job/etcd/etcd_test.go +++ b/pkg/registry/job/etcd/etcd_test.go @@ -89,14 +89,14 @@ func TestCreate(t *testing.T) { func TestUpdate(t *testing.T) { storage, fakeClient := newStorage(t) test := registrytest.New(t, fakeClient, storage.Etcd) - completions := 2 + two := 2 test.TestUpdate( // valid validNewJob(), // updateFunc func(obj runtime.Object) runtime.Object { object := obj.(*experimental.Job) - object.Spec.Completions = &completions + object.Spec.Parallelism = &two return object }, // invalid updateFunc @@ -105,6 +105,11 @@ func TestUpdate(t *testing.T) { object.Spec.Selector = map[string]string{} return object }, + func(obj runtime.Object) runtime.Object { + object := obj.(*experimental.Job) + object.Spec.Completions = &two + return object + }, ) }