Skip to content

Add admission webhook #241

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

Merged
merged 1 commit into from
Mar 11, 2021
Merged

Add admission webhook #241

merged 1 commit into from
Mar 11, 2021

Conversation

prksu
Copy link
Contributor

@prksu prksu commented Mar 6, 2021

What this PR does / why we need it:

Add support for adission webhook

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

Release note:

Support admission webhook

@k8s-ci-robot k8s-ci-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Mar 6, 2021
@k8s-ci-robot k8s-ci-robot requested review from cpanato and vincepri March 6, 2021 17:41
@k8s-ci-robot k8s-ci-robot added 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. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 6, 2021
@prksu
Copy link
Contributor Author

prksu commented Mar 6, 2021

/retest

@cpanato
Copy link
Member

cpanato commented Mar 7, 2021

i will take a look during the week, but looks great! great job!

/assign @timoreimann

@prksu
Copy link
Contributor Author

prksu commented Mar 9, 2021

/retest

Copy link
Contributor

@timoreimann timoreimann 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 the work 👏

A few questions on my end, primarily born out of lack of context I believe.

return apierrors.NewBadRequest(fmt.Sprintf("expected an DOCluster but got a %T", old))
}

if r.Spec.Region != oldDOCluster.Spec.Region {
Copy link
Contributor

Choose a reason for hiding this comment

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

The one case I can think of where changing the region might be helpful is when a wrong region was specified in the first place and you were trying to fix a reconcile that fails early on. Might not be worth considering though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

make sense. but I prefer to make the region immutable in some cases the user trying to change region in an existing cluster and then the next machine will be created in a different region from the other old machines.

how about make validation in the ValidateCreate that region must be valid do region? so it will reduce the failure because of the invalid region.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the idea to check if the region is a valid one. We should then use the regions endpoint to list all valid regions.

(Doesn't have to implemented in this PR.)

newDOMachineSpec := newDOMachine["spec"].(map[string]interface{})
oldDOMachineSpec := oldDOMachine["spec"].(map[string]interface{})

// allow changes to providerID
Copy link
Contributor

Choose a reason for hiding this comment

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

AFAICS, the provider ID is set from the (read-only) droplet ID. What's the use case for it to be allowed to change? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

afaik, it required for the controller to set the providerID kubernetes-sigs/cluster-api-provider-aws#1218 (comment) although, I also think if we can reject updating providerID only if it already set.

but can we leave it as is? and keeping an eye on the other providers on how they handle this. since it's not clearly documented yet what validations should be enforcing kubernetes-sigs/cluster-api-provider-aws#1218 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah you're right, I missed the fact that the provider ID is set by the CAPDO controller itself which constitutes an update.

Disallowing updates once the provider ID is set sounds reasonable. Happy to keep things the way you propose them in your PR for now though and see what consensus is made with regards to webhook validations.

allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "region"), r.Spec.Region, "field is immutable"))
}

if allErrs != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also prevent changes to the controlPlaneEndpoint field?

It consists of the IP address of the LB which is immutable once set, and the LB port which I don't think we allow updating right now?

(I did wonder at some point why those were spec fields in the first place as opposed to status ones, but maybe I'm missing some context 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.

+1

(I did wonder at some point why those were spec fields in the first place as opposed to status ones, but maybe I'm missing some context here...)

It's required by capi to identify the endpoint used to connect to the target’s cluster apiserver.
https://cluster-api.sigs.k8s.io/developer/architecture/controllers/cluster.html#infrastructure-provider

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, what why is the endppint part of the spec? AFAIU, CAPDO does not expect the user/operator to set or modify the field -- it's always the controller that does it. In that sense, a status field seems better?

(Definitely a side discussion since this isn't something we can change without CAPI approval.)

@timoreimann
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 11, 2021
@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: prksu, timoreimann

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 merged commit 0be5dfd into kubernetes-sigs:master Mar 11, 2021
@k8s-ci-robot k8s-ci-robot added this to the v0.4 milestone Mar 11, 2021
@prksu prksu deleted the webhook branch March 19, 2021 14:01
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. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for webhooks
4 participants