Skip to content

Commit ddc3065

Browse files
rosa: use CEL validation for versions
The webhooks we had were only giving us a nice error message on top of the parsing validation, and we can get all of that benefit by just using a CEL matcher and a custom error message. Not having to deploy and run webhooks simplifies things for us a sizeable amount and makes local testing much easier, as well. Signed-off-by: Steve Kuznetsov <[email protected]>
1 parent c1975bb commit ddc3065

9 files changed

+11
-265
lines changed

config/crd/bases/controlplane.cluster.x-k8s.io_rosacontrolplanes.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,11 @@ spec:
286286
supportRoleARN:
287287
type: string
288288
version:
289-
description: Openshift version, for example "4.14.5".
289+
description: OpenShift semantic version, for example "4.14.5".
290290
type: string
291+
x-kubernetes-validations:
292+
- message: version must be a valid semantic version
293+
rule: self.matches('^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$')
291294
workerRoleARN:
292295
type: string
293296
required:

config/crd/bases/infrastructure.cluster.x-k8s.io_rosamachinepools.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ spec:
9898
description: Version specifies the penshift version of the nodes associated
9999
with this machinepool. ROSAControlPlane version is used if not set.
100100
type: string
101+
x-kubernetes-validations:
102+
- message: version must be a valid semantic version
103+
rule: self.matches('^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$')
101104
required:
102105
- nodePoolName
103106
type: object

config/webhook/manifests.yaml

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -201,28 +201,6 @@ webhooks:
201201
resources:
202202
- awsmanagedmachinepools
203203
sideEffects: None
204-
- admissionReviewVersions:
205-
- v1
206-
- v1beta1
207-
clientConfig:
208-
service:
209-
name: webhook-service
210-
namespace: system
211-
path: /mutate-infrastructure-cluster-x-k8s-io-v1beta2-rosamachinepool
212-
failurePolicy: Fail
213-
matchPolicy: Equivalent
214-
name: default.rosamachinepool.infrastructure.cluster.x-k8s.io
215-
rules:
216-
- apiGroups:
217-
- infrastructure.cluster.x-k8s.io
218-
apiVersions:
219-
- v1beta2
220-
operations:
221-
- CREATE
222-
- UPDATE
223-
resources:
224-
- rosamachinepools
225-
sideEffects: None
226204
- admissionReviewVersions:
227205
- v1
228206
- v1beta1
@@ -289,28 +267,6 @@ webhooks:
289267
resources:
290268
- awsmanagedcontrolplanes
291269
sideEffects: None
292-
- admissionReviewVersions:
293-
- v1
294-
- v1beta1
295-
clientConfig:
296-
service:
297-
name: webhook-service
298-
namespace: system
299-
path: /mutate-controlplane-cluster-x-k8s-io-v1beta2-rosacontrolplane
300-
failurePolicy: Fail
301-
matchPolicy: Equivalent
302-
name: default.rosacontrolplanes.controlplane.cluster.x-k8s.io
303-
rules:
304-
- apiGroups:
305-
- controlplane.cluster.x-k8s.io
306-
apiVersions:
307-
- v1beta2
308-
operations:
309-
- CREATE
310-
- UPDATE
311-
resources:
312-
- rosacontrolplanes
313-
sideEffects: None
314270
---
315271
apiVersion: admissionregistration.k8s.io/v1
316272
kind: ValidatingWebhookConfiguration
@@ -537,28 +493,6 @@ webhooks:
537493
resources:
538494
- awsmanagedmachinepools
539495
sideEffects: None
540-
- admissionReviewVersions:
541-
- v1
542-
- v1beta1
543-
clientConfig:
544-
service:
545-
name: webhook-service
546-
namespace: system
547-
path: /validate-infrastructure-cluster-x-k8s-io-v1beta2-rosamachinepool
548-
failurePolicy: Fail
549-
matchPolicy: Equivalent
550-
name: validation.rosamachinepool.infrastructure.cluster.x-k8s.io
551-
rules:
552-
- apiGroups:
553-
- infrastructure.cluster.x-k8s.io
554-
apiVersions:
555-
- v1beta2
556-
operations:
557-
- CREATE
558-
- UPDATE
559-
resources:
560-
- rosamachinepools
561-
sideEffects: None
562496
- admissionReviewVersions:
563497
- v1
564498
- v1beta1
@@ -625,25 +559,3 @@ webhooks:
625559
resources:
626560
- awsmanagedcontrolplanes
627561
sideEffects: None
628-
- admissionReviewVersions:
629-
- v1
630-
- v1beta1
631-
clientConfig:
632-
service:
633-
name: webhook-service
634-
namespace: system
635-
path: /validate-controlplane-cluster-x-k8s-io-v1beta2-rosacontrolplane
636-
failurePolicy: Fail
637-
matchPolicy: Equivalent
638-
name: validation.rosacontrolplanes.controlplane.cluster.x-k8s.io
639-
rules:
640-
- apiGroups:
641-
- controlplane.cluster.x-k8s.io
642-
apiVersions:
643-
- v1beta2
644-
operations:
645-
- CREATE
646-
- UPDATE
647-
resources:
648-
- rosacontrolplanes
649-
sideEffects: None

controlplane/rosa/api/v1beta2/rosacontrolplane_types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ type RosaControlPlaneSpec struct { //nolint: maligned
4949
// The AWS Region the cluster lives in.
5050
Region *string `json:"region"`
5151

52-
// Openshift version, for example "4.14.5".
52+
// OpenShift semantic version, for example "4.14.5".
53+
// +kubebuilder:validation:XValidation:rule=`self.matches('^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$')`, message="version must be a valid semantic version"
5354
Version string `json:"version"`
5455

5556
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.

controlplane/rosa/api/v1beta2/rosacontrolplane_webhook.go

Lines changed: 0 additions & 81 deletions
This file was deleted.

controlplane/rosa/api/v1beta2/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exp/api/v1beta2/rosamachinepool_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type RosaMachinePoolSpec struct {
3737
// ROSAControlPlane version is used if not set.
3838
//
3939
// +optional
40+
// +kubebuilder:validation:XValidation:rule=`self.matches('^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$')`, message="version must be a valid semantic version"
4041
Version string `json:"version,omitempty"`
4142

4243
// AvailabilityZone is an optinal field specifying the availability zone where instances of this machine pool should run

exp/api/v1beta2/rosamachinepool_webhook.go

Lines changed: 0 additions & 83 deletions
This file was deleted.

main.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -254,16 +254,6 @@ func main() {
254254
setupLog.Error(err, "unable to create controller", "controller", "ROSAMachinePool")
255255
os.Exit(1)
256256
}
257-
258-
if err := (&rosacontrolplanev1.ROSAControlPlane{}).SetupWebhookWithManager(mgr); err != nil {
259-
setupLog.Error(err, "unable to create webhook", "webhook", "ROSAControlPlane")
260-
os.Exit(1)
261-
}
262-
263-
if err := (&expinfrav1.ROSAMachinePool{}).SetupWebhookWithManager(mgr); err != nil {
264-
setupLog.Error(err, "unable to create webhook", "webhook", "ROSAMachinePool")
265-
os.Exit(1)
266-
}
267257
}
268258

269259
// +kubebuilder:scaffold:builder

0 commit comments

Comments
 (0)