Skip to content

Commit 2d92716

Browse files
Add x-kubernetes-validations rule for overcommit < 1.0
1 parent 25185ae commit 2d92716

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

api/v1/hypervisor_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ type HypervisorSpec struct {
170170
// gradually adjusting the hypervisor capacity.
171171
//
172172
// +kubebuilder:validation:Optional
173+
//
174+
// It is validated that all overcommit ratios are greater than or equal to
175+
// 1.0, if specified. For this we don't need extra validating webhooks.
176+
// See: https://kubernetes.io/blog/2022/09/23/crd-validation-rules-beta/#crd-transition-rules
177+
// +kubebuilder:validation:XValidation:rule="self.all(e, e.value >= 1.0)",message="overcommit ratios must be >= 1.0"
173178
Overcommit map[corev1.ResourceName]float64 `json:"overcommit,omitempty"`
174179
}
175180

config/crd/bases/kvm.cloud.sap_hypervisors.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.19.0
6+
controller-gen.kubebuilder.io/version: v0.18.0
77
name: hypervisors.kvm.cloud.sap
88
spec:
99
group: kvm.cloud.sap
@@ -178,7 +178,14 @@ spec:
178178
If the overcommit ratio results in a fractional effective capacity,
179179
the effective capacity is expected to be rounded down. This allows
180180
gradually adjusting the hypervisor capacity.
181+
182+
It is validated that all overcommit ratios are greater than or equal to
183+
1.0, if specified. For this we don't need extra validating webhooks.
184+
See: https://kubernetes.io/blog/2022/09/23/crd-validation-rules-beta/#crd-transition-rules
181185
type: object
186+
x-kubernetes-validations:
187+
- message: overcommit ratios must be >= 1.0
188+
rule: self.all(e, e.value >= 1.0)
182189
reboot:
183190
default: false
184191
description: Reboot request an reboot after successful installation

0 commit comments

Comments
 (0)