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

feat: linodemachine: add validating admission webhook on create #291

Merged
merged 9 commits into from
May 15, 2024

Conversation

cbzzz
Copy link
Contributor

@cbzzz cbzzz commented Apr 29, 2024

What type of PR is this?
/kind feature

What this PR does / why we need it:
Adds a validating admission webhook for infrastructure.cluster.x-k8s.io/v1alpha1/linodemachine resources on creation.

This initial validation webhook validates the following LinodeMachine resource fields on object creation:

Field Validation(s)
.spec.region Valid region
.spec.type Valid instance type
.spec.osDisk .Size <= instance size
.spec.dataDisks - Keys are valid disk device slot and unique
- Length() <= 7
- Sum(.Size) <= instance size

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 #

Special notes for your reviewer:
Accompanied by #311 to isolate client refactoring changes: chore.clients...feat.webhook

TODOs:

  • squashed commits
  • includes documentation
  • adds unit tests
  • adds or updates e2e tests

Testing:

  1. Create an invalid LinodeMachine resource:
$ kubectl apply -f - <<EOF
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: LinodeMachine
metadata:
    name: test
spec:
    region: test
    type: g6-nanode-1
    osDisk:
      size: 100G
    dataDisks:
      sdb:
        size: 100G
EOF

The LinodeMachine "test" is invalid:
* spec.region: Not found: "test"
* spec.osDisk: Invalid value: "100G": sum disk sizes exceeds plan storage: 24600M

Scaffold a validating admission webhook for the LinodeMachine resource
with Kubebuider via the command:
kubebuilder create webhook --group infrastructure --version v1alpha1 --kind LinodeMachine --programmatic-validation
Use the latest 6th Generation Linode plans (announced in May 2018). The 5th
Generation plans are publicly deprecated.

See: https://www.linode.com/blog/linode/updated-linode-plans-new-larger-linodes/
Copy link

codecov bot commented Apr 29, 2024

Codecov Report

Attention: Patch coverage is 74.44444% with 23 lines in your changes are missing coverage. Please review.

Project coverage is 65.74%. Comparing base (c6faafa) to head (db3f44e).

❗ Current head db3f44e differs from pull request most recent head 3016eec. Consider uploading reports for the commit 3016eec to get more accurate results

Files Patch % Lines
api/v1alpha1/linodemachine_webhook.go 75.00% 17 Missing and 2 partials ⚠️
cmd/main.go 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #291      +/-   ##
==========================================
- Coverage   66.18%   65.74%   -0.44%     
==========================================
  Files          30       32       +2     
  Lines        1872     1962      +90     
==========================================
+ Hits         1239     1290      +51     
- Misses        575      612      +37     
- Partials       58       60       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Webhooks can be enabled or disabled by setting the `ENABLE_WEBHOOKS` environment
variable during deployment.
@cbzzz cbzzz mentioned this pull request May 8, 2024
4 tasks
@cbzzz cbzzz force-pushed the feat.webhook branch 9 times, most recently from 2db5e61 to db3f44e Compare May 13, 2024 15:27
@rahulait rahulait self-requested a review May 14, 2024 14:54
rahulait
rahulait previously approved these changes May 14, 2024
Copy link
Collaborator

@rahulait rahulait left a comment

Choose a reason for hiding this comment

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

Overall, the PR looks good to me.

@cbzzz cbzzz merged commit db9eeda into main May 15, 2024
9 of 10 checks passed
@cbzzz cbzzz deleted the feat.webhook branch May 15, 2024 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants