Skip to content

Commit

Permalink
Merge pull request #534 from kannon92/automated-cherry-pick-of-#527-u…
Browse files Browse the repository at this point in the history
…pstream-release-0.5

Automated cherry pick of #527: Fix path for the error when mutating managedBy
  • Loading branch information
k8s-ci-robot authored Apr 21, 2024
2 parents cb44e54 + b37189a commit 3a2ae4d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/webhooks/jobset_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (j *jobSetWebhook) ValidateUpdate(ctx context.Context, old, newObj runtime.
}
// Note that SucccessPolicy and failurePolicy are made immutable via CEL.
errs := apivalidation.ValidateImmutableField(mungedSpec.ReplicatedJobs, oldJS.Spec.ReplicatedJobs, field.NewPath("spec").Child("replicatedJobs"))
errs = append(errs, apivalidation.ValidateImmutableField(mungedSpec.ManagedBy, oldJS.Spec.ManagedBy, field.NewPath("spec").Child("labels").Key("managedBy"))...)
errs = append(errs, apivalidation.ValidateImmutableField(mungedSpec.ManagedBy, oldJS.Spec.ManagedBy, field.NewPath("spec").Child("managedBy"))...)
return nil, errs.ToAggregate()
}

Expand Down
49 changes: 44 additions & 5 deletions pkg/webhooks/jobset_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,26 @@ func TestValidateUpdate(t *testing.T) {
},
},
},
{
name: "managedBy is immutable",
js: &jobset.JobSet{
ObjectMeta: validObjectMeta,
Spec: jobset.JobSetSpec{
ManagedBy: ptr.To("example.com/new"),
ReplicatedJobs: validReplicatedJobs,
},
},
oldJs: &jobset.JobSet{
ObjectMeta: validObjectMeta,
Spec: jobset.JobSetSpec{
ManagedBy: ptr.To("example.com/old"),
ReplicatedJobs: validReplicatedJobs,
},
},
want: field.ErrorList{
field.Invalid(field.NewPath("spec").Child("managedBy"), ptr.To("example.com/new"), "field is immutable"),
}.ToAggregate(),
},
{
name: "replicated jobs are immutable",
js: &jobset.JobSet{
Expand Down Expand Up @@ -1006,7 +1026,28 @@ func TestValidateUpdate(t *testing.T) {
ReplicatedJobs: validReplicatedJobs,
},
},
want: fmt.Errorf("field is immutable"),
want: field.ErrorList{
field.Invalid(field.NewPath("spec").Child("replicatedJobs"), []jobset.ReplicatedJob{
{
Name: "test-jobset-replicated-job-0",
Replicas: 2,
Template: batchv1.JobTemplateSpec{
Spec: batchv1.JobSpec{
Parallelism: ptr.To[int32](2),
},
},
},
{
Name: "test-jobset-replicated-job-1",
Replicas: 1,
Template: batchv1.JobTemplateSpec{
Spec: batchv1.JobSpec{
Parallelism: ptr.To[int32](1),
},
},
},
}, "field is immutable"),
}.ToAggregate(),
},
}

Expand All @@ -1018,10 +1059,8 @@ func TestValidateUpdate(t *testing.T) {
newObj := tc.js.DeepCopyObject()
oldObj := tc.oldJs.DeepCopyObject()
_, err = webhook.ValidateUpdate(context.TODO(), oldObj, newObj)
if tc.want != nil {
assert.True(t, strings.Contains(err.Error(), tc.want.Error()))
} else {
assert.Nil(t, err)
if diff := cmp.Diff(tc.want, err); diff != "" {
t.Errorf("ValidateResources() mismatch (-want +got):\n%s", diff)
}
})
}
Expand Down

0 comments on commit 3a2ae4d

Please sign in to comment.