Merge pull request #105980 from ahg-g/ahg-mutable

Make job pod template annotations and labels mutable for suspended jobs that never started
This commit is contained in:
Kubernetes Prow Robot
2021-10-29 13:15:23 -07:00
committed by GitHub
2 changed files with 68 additions and 0 deletions

View File

@@ -647,6 +647,72 @@ func TestValidateJobUpdate(t *testing.T) {
AllowMutableSchedulingDirectives: true,
},
},
"immutable annotations": {
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.Template.Annotations = map[string]string{"foo": "baz"}
},
err: &field.Error{
Type: field.ErrorTypeInvalid,
Field: "spec.template",
},
},
"mutable annotations": {
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.Template.Annotations = map[string]string{"foo": "baz"}
},
opts: JobValidationOptions{
AllowMutableSchedulingDirectives: true,
},
},
"immutable labels": {
old: batch.Job{
ObjectMeta: metav1.ObjectMeta{Name: "abc", Namespace: metav1.NamespaceDefault},
Spec: batch.JobSpec{
Selector: validGeneratedSelector,
Template: validPodTemplateSpecForGenerated,
},
},
update: func(job *batch.Job) {
newLabels := getValidGeneratedSelector().MatchLabels
newLabels["bar"] = "baz"
job.Spec.Template.Labels = newLabels
},
err: &field.Error{
Type: field.ErrorTypeInvalid,
Field: "spec.template",
},
},
"mutable labels": {
old: batch.Job{
ObjectMeta: metav1.ObjectMeta{Name: "abc", Namespace: metav1.NamespaceDefault},
Spec: batch.JobSpec{
Selector: validGeneratedSelector,
Template: validPodTemplateSpecForGenerated,
},
},
update: func(job *batch.Job) {
newLabels := getValidGeneratedSelector().MatchLabels
newLabels["bar"] = "baz"
job.Spec.Template.Labels = newLabels
},
opts: JobValidationOptions{
AllowMutableSchedulingDirectives: true,
},
},
}
ignoreValueAndDetail := cmpopts.IgnoreFields(field.Error{}, "BadValue", "Detail")
for k, tc := range cases {