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: linodevpc: add validating admission webhook on create #321

Merged
merged 5 commits into from
May 22, 2024

Conversation

cbzzz
Copy link
Contributor

@cbzzz cbzzz commented May 15, 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/linodevpc resources on creation.

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

Field Validation(s)
.spec.region - Valid region
- VPC supported
.spec.Subnets[].Label - 1..64 characters
- Unique among the VPC’s Subnets
- Can only contain ASCII letters, numbers, and hyphens (-)
- No two consecutive hyphens (--).
.spec.Subnets[].IPv4 - IPv4 range in CIDR canonical form
- Range belongs to a private address space as defined in RFC1918
- Prefix length: 1-29
- No overlap with Linode Instance Private IPv4 Address feature
- No overlap with other Subnets on the same VPC

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:
gopkg.in/addrs.v1 da 🐐 no 🧢 frfr 🙏
go4.org/netipx da 🐐 no 🧢 frfr 🙏

TODOs:

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

Testing:

  1. Create an invalid LinodeVPC resource:
$ kubectl apply -f - <<EOF
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: LinodeVPC
metadata:
    name: test
spec:
  region: us-east
  subnets:
  - label: "---"
    ipv4: 192.168.128.0/24
  - ipv4: 9.9.9.9
EOF

The LinodeVPC "test" is invalid:
* spec.region: Invalid value: "us-east": no capability: VPCs
* spec.Subnets[0].Label: Invalid value: "---": cannot contain two consecutive hyphens (--)
* spec.Subnets[0].IPv4: Invalid value: "192.168.128.0/24": range must not overlap with [192.168.128.0/17]
* spec.Subnets[1].Label: Invalid value: "": 1..64 characters
* spec.Subnets[1].IPv4: Invalid value: "9.9.9.9": must be IPv4 range in CIDR canonical form

Copy link

codecov bot commented May 15, 2024

Codecov Report

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

Project coverage is 66.30%. Comparing base (4c9281b) to head (d5c0497).

Files Patch % Lines
api/v1alpha1/linodevpc_webhook.go 84.67% 17 Missing and 2 partials ⚠️
cmd/main.go 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #321      +/-   ##
==========================================
+ Coverage   65.22%   66.30%   +1.08%     
==========================================
  Files          33       34       +1     
  Lines        2010     2140     +130     
==========================================
+ Hits         1311     1419     +108     
- Misses        639      659      +20     
- Partials       60       62       +2     

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

@AshleyDumaine AshleyDumaine self-requested a review May 20, 2024 14:58
eljohnson92
eljohnson92 previously approved these changes May 22, 2024
cbzzz added 5 commits May 22, 2024 12:40
Scaffold a validating admission webhook for the LinodeVPC resource
with Kubebuider via the command:
kubebuilder create webhook --group infrastructure --version v1alpha1 --kind LinodeVPC --programmatic-validation
@cbzzz cbzzz merged commit 87a2c65 into main May 22, 2024
10 checks passed
@cbzzz cbzzz deleted the feat.webhook.vpc branch May 22, 2024 16:53
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.

None yet

2 participants