mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 02:09:56 +00:00
only allow updates of parrallelism in jobspec
This commit is contained in:
parent
e7d4426158
commit
9d1838fb64
@ -315,6 +315,21 @@ func ValidateJobSpec(spec *experimental.JobSpec) errs.ValidationErrorList {
|
|||||||
func ValidateJobUpdate(oldJob, job *experimental.Job) errs.ValidationErrorList {
|
func ValidateJobUpdate(oldJob, job *experimental.Job) errs.ValidationErrorList {
|
||||||
allErrs := errs.ValidationErrorList{}
|
allErrs := errs.ValidationErrorList{}
|
||||||
allErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&oldJob.ObjectMeta, &job.ObjectMeta).Prefix("metadata")...)
|
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
|
return allErrs
|
||||||
}
|
}
|
||||||
|
@ -89,14 +89,14 @@ func TestCreate(t *testing.T) {
|
|||||||
func TestUpdate(t *testing.T) {
|
func TestUpdate(t *testing.T) {
|
||||||
storage, fakeClient := newStorage(t)
|
storage, fakeClient := newStorage(t)
|
||||||
test := registrytest.New(t, fakeClient, storage.Etcd)
|
test := registrytest.New(t, fakeClient, storage.Etcd)
|
||||||
completions := 2
|
two := 2
|
||||||
test.TestUpdate(
|
test.TestUpdate(
|
||||||
// valid
|
// valid
|
||||||
validNewJob(),
|
validNewJob(),
|
||||||
// updateFunc
|
// updateFunc
|
||||||
func(obj runtime.Object) runtime.Object {
|
func(obj runtime.Object) runtime.Object {
|
||||||
object := obj.(*experimental.Job)
|
object := obj.(*experimental.Job)
|
||||||
object.Spec.Completions = &completions
|
object.Spec.Parallelism = &two
|
||||||
return object
|
return object
|
||||||
},
|
},
|
||||||
// invalid updateFunc
|
// invalid updateFunc
|
||||||
@ -105,6 +105,11 @@ func TestUpdate(t *testing.T) {
|
|||||||
object.Spec.Selector = map[string]string{}
|
object.Spec.Selector = map[string]string{}
|
||||||
return object
|
return object
|
||||||
},
|
},
|
||||||
|
func(obj runtime.Object) runtime.Object {
|
||||||
|
object := obj.(*experimental.Job)
|
||||||
|
object.Spec.Completions = &two
|
||||||
|
return object
|
||||||
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user