Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix path for the error when attempting to mutate managedBy #527

Merged
merged 3 commits into from
Apr 19, 2024

Conversation

mimowo
Copy link
Contributor

@mimowo mimowo commented Apr 18, 2024

Fix for the path in error which I discovered wrong during manual e2e testing.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 18, 2024
@mimowo
Copy link
Contributor Author

mimowo commented Apr 18, 2024

/cc @danielvegamyhre

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 18, 2024
Copy link

netlify bot commented Apr 18, 2024

Deploy Preview for kubernetes-sigs-jobset canceled.

Name Link
🔨 Latest commit 749cbea
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-jobset/deploys/66221ca86591d20008dd9306

@kannon92
Copy link
Contributor

/lgtm

/assign @danielvegamyhre @ahg-g

We should backport this to 0.5.0.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 18, 2024
Copy link
Contributor

@danielvegamyhre danielvegamyhre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this @mimowo!

assert.True(t, strings.Contains(err.Error(), tc.want.Error()))
} else {
assert.Nil(t, err)
if diff := cmp.Diff(tc.want, err, cmpopts.IgnoreFields(field.Error{}, "BadValue")); diff != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to ignore the BadValue field here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to ignore, tentatively I ignored it because I got a bigger diff for the test case: "replicated_jobs_are_immutable", and it wasn't asserted before:

            - 		BadValue: string(""),
            + 		BadValue: []v1alpha2.ReplicatedJob{
            + 			{
            + 				Name:     "test-jobset-replicated-job-0",
            + 				Template: v1.JobTemplateSpec{Spec: v1.JobSpec{...}},
            + 				Replicas: 2,
            + 			},
            + 			{
            + 				Name:     "test-jobset-replicated-job-1",
            + 				Template: v1.JobTemplateSpec{Spec: v1.JobSpec{...}},
            + 				Replicas: 1,
            + 			},
            + 		},

I'm happy either way, WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last commit pushed contains validation of the BadValue. PTAL.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think the bad value can be helpful to see what value was mutated in the immutable construct, so it's easier to find where the mutation is coming from in the code and fix it.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 19, 2024
@@ -228,7 +228,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"))...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can try cherry-picking this but this PR seems to be two in one.

We have a bug fix (which is useful!) and some test cleanup. I'll see if I can get both into but I would usually suggest leaving cleanups out of a bug fix.

Copy link
Contributor Author

@mimowo mimowo Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test changes are in order to assert on the error path. Previously path was ignored in the test. I think this is a good practice to accompany each change with a test in the same PR.

One thing potentially optional is asserting on the "BadValue", but it raised a question, so I added: #527 (comment)

@kannon92
Copy link
Contributor

/lgtm

Cherry-pick seems fine but just a suggestion for next time.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 19, 2024
@mimowo mimowo changed the title Fix path for the error when mutating managedBy Fix path for the error when attempting to mutate managedBy Apr 19, 2024
@danielvegamyhre
Copy link
Contributor

/approve

Thanks!

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: danielvegamyhre, mimowo

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 19, 2024
@k8s-ci-robot k8s-ci-robot merged commit 2f11239 into kubernetes-sigs:main Apr 19, 2024
12 checks passed
k8s-ci-robot added a commit that referenced this pull request Apr 21, 2024
…pstream-release-0.5

Automated cherry pick of #527: Fix path for the error when mutating managedBy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants