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

🐛 Handle a nil mutator by returning an error, not panicking #10951

Merged

Conversation

dlipovetsky
Copy link
Contributor

@dlipovetsky dlipovetsky commented Jul 26, 2024

What this PR does / why we need it:
I discovered that the applyMutators function panics if one of the mutators is nil. I updated the function to return an error on any nil mutator.

The first commit adds unit tests, one of which confirms that applyMutators panics if a the mutators slice contains a nil mutator.

The second commit fixes the issue.

The third commit fixes a test that passes a nil mutator. The call is incorrect, but the test has never failed, because it enables dry-run, and that does not exercise the mutators.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

/kind bug
/area clusterctl

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. area/clusterctl Issues or PRs related to clusterctl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jul 26, 2024
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 26, 2024
@dlipovetsky dlipovetsky force-pushed the fix-applymutators-nil-mutator branch from d8a84bf to b6573a2 Compare July 26, 2024 20:15
@dlipovetsky dlipovetsky changed the title 🐛 Fix applymutators nil mutator 🐛 Do not apply a nil mutator Jul 26, 2024
The call is incorrect, but the test does not fail, because it enables
dry-run, and that does not exercise the mutators.
@dlipovetsky dlipovetsky force-pushed the fix-applymutators-nil-mutator branch from b6573a2 to e143580 Compare July 26, 2024 21:22
@dlipovetsky dlipovetsky changed the title 🐛 Do not apply a nil mutator 🐛 Handle a nil mutator by returning an error, not panicking Jul 26, 2024
Copy link
Member

@sivchari sivchari left a comment

Choose a reason for hiding this comment

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

Looks good to me. Left some nits.

cmd/clusterctl/client/cluster/mover.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/mover_test.go Outdated Show resolved Hide resolved
@@ -2408,3 +2408,48 @@ func TestWaitReadyForMove(t *testing.T) {
})
}
}

func Test_applyMutators(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

How about using t. Parallel?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not a bad suggestion, but I'd rather not, because
(a) There's no measurable decrease in time for this specific test, and
(b) relatively few tests across the repo use it.

@dlipovetsky
Copy link
Contributor Author

Thanks for reviewing, @sivchari!

@sbueringer
Copy link
Member

Thx!

/lgtm
/approve

Feel free to cherry-pick back further

/cherry-pick release-1.8

@k8s-infra-cherrypick-robot

@sbueringer: once the present PR merges, I will cherry-pick it on top of release-1.8 in a new PR and assign it to you.

In response to this:

Thx!

/lgtm
/approve

Feel free to cherry-pick back further

/cherry-pick release-1.8

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

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

LGTM label has been added.

Git tree hash: 432ec603f7bb8b278be9ba506c2b6c5b77b84ada

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sbueringer

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 Aug 1, 2024
@k8s-ci-robot k8s-ci-robot merged commit 3f21042 into kubernetes-sigs:main Aug 1, 2024
20 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.9 milestone Aug 1, 2024
@k8s-infra-cherrypick-robot

@sbueringer: new pull request created: #10981

In response to this:

Thx!

/lgtm
/approve

Feel free to cherry-pick back further

/cherry-pick release-1.8

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

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. area/clusterctl Issues or PRs related to clusterctl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. 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