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

🌱 Add field.Path aggregation for Machine webhook #6368

Merged
merged 1 commit into from
Apr 6, 2022

Conversation

Jont828
Copy link
Contributor

@Jont828 Jont828 commented Apr 1, 2022

What this PR does / why we need it: Update usage of field.Path in Machine webhook as part of an effort to make core webhook validation more consistent.

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 #6249

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 1, 2022
@Jont828 Jont828 changed the title 🌱Add field.Path aggregation for Machine webhook 🌱 Add field.Path aggregation for Machine webhook Apr 1, 2022
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Apr 1, 2022
@Jont828
Copy link
Contributor Author

Jont828 commented Apr 1, 2022

/assign @killianmuldoon

@Jont828
Copy link
Contributor Author

Jont828 commented Apr 1, 2022

@killianmuldoon I followed the basic idea of #6322. Are these the changes we want to see?

Copy link
Contributor

@killianmuldoon killianmuldoon left a comment

Choose a reason for hiding this comment

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

Looking good - one tiny change to make the ClusterName field change forbidden rather than invalid.

Thanks @Jont828

@@ -126,13 +127,14 @@ func (m *Machine) validate(old *Machine) error {
if old != nil && old.Spec.ClusterName != m.Spec.ClusterName {
allErrs = append(
allErrs,
field.Invalid(field.NewPath("spec", "clusterName"), m.Spec.ClusterName, "field is immutable"),
// Should this be field.Forbidden?
field.Invalid(specPath.Child("clusterName"), m.Spec.ClusterName, "field is immutable"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Good idea to change this to field.Forbidden

@Jont828
Copy link
Contributor Author

Jont828 commented Apr 4, 2022

@killianmuldoon Just added the field.Forbbidden change. How does this look now?

@@ -126,13 +127,13 @@ func (m *Machine) validate(old *Machine) error {
if old != nil && old.Spec.ClusterName != m.Spec.ClusterName {
allErrs = append(
allErrs,
field.Invalid(field.NewPath("spec", "clusterName"), m.Spec.ClusterName, "field is immutable"),
field.Forbidden(specPath.Child("clusterName"), "spec.clusterName is immutable"),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can leave the message the same here as the path will be part of the message elsewhere.

Suggested change
field.Forbidden(specPath.Child("clusterName"), "spec.clusterName is immutable"),
field.Forbidden(specPath.Child("clusterName"), "field is immutable"),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@killianmuldoon Sounds good, just squashed and pushed.

Copy link
Contributor

@killianmuldoon killianmuldoon left a comment

Choose a reason for hiding this comment

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

/lgtm

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

@fabriziopandini fabriziopandini left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fabriziopandini

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 6, 2022
@k8s-ci-robot k8s-ci-robot merged commit 5cc8e57 into kubernetes-sigs:main Apr 6, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.2 milestone Apr 6, 2022
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/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve consistency of errors returned from core webhooks
4 participants