From 72a0a7c1d5e6acbb84a09a9c3f066097a8e20e97 Mon Sep 17 00:00:00 2001 From: Dhairya Arora Date: Sat, 5 Oct 2024 22:28:19 +0530 Subject: [PATCH] add basic validation for time duration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Basic validation for time duration can be done using kubebuilder markers to match the pattern "^(([1-9][0-9]*(\\.[0-9]+)?|0?\\.[0-9]+)(ns|us|µs|ms|s|m|h))+$", Signed-off-by: Dhairya Arora --- api/v1beta1/cluster_types.go | 6 ++++++ config/crd/bases/cluster.x-k8s.io_clusters.yaml | 3 +++ 2 files changed, 9 insertions(+) diff --git a/api/v1beta1/cluster_types.go b/api/v1beta1/cluster_types.go index d51fecb2924d..8b2f318c2ea1 100644 --- a/api/v1beta1/cluster_types.go +++ b/api/v1beta1/cluster_types.go @@ -153,17 +153,23 @@ type ControlPlaneTopology struct { // NodeDrainTimeout is the total amount of time that the controller will spend on draining a node. // The default value is 0, meaning that the node can be drained without any time limitations. // NOTE: NodeDrainTimeout is different from `kubectl drain --timeout` + // +kubebuilder:validation:Pattern="^(([1-9][0-9]*(\\.[0-9]+)?|0?\\.[0-9]+)(ns|us|µs|ms|s|m|h))+$" + // +kubebuilder:validation:Type:=string // +optional NodeDrainTimeout *metav1.Duration `json:"nodeDrainTimeout,omitempty"` // NodeVolumeDetachTimeout is the total amount of time that the controller will spend on waiting for all volumes // to be detached. The default value is 0, meaning that the volumes can be detached without any time limitations. + // +kubebuilder:validation:Pattern="^(([1-9][0-9]*(\\.[0-9]+)?|0?\\.[0-9]+)(ns|us|µs|ms|s|m|h))+$" + // +kubebuilder:validation:Type:=string // +optional NodeVolumeDetachTimeout *metav1.Duration `json:"nodeVolumeDetachTimeout,omitempty"` // NodeDeletionTimeout defines how long the controller will attempt to delete the Node that the Machine // hosts after the Machine is marked for deletion. A duration of 0 will retry deletion indefinitely. // Defaults to 10 seconds. + // +kubebuilder:validation:Pattern="^(([1-9][0-9]*(\\.[0-9]+)?|0?\\.[0-9]+)(ns|us|µs|ms|s|m|h))+$" + // +kubebuilder:validation:Type:=string // +optional NodeDeletionTimeout *metav1.Duration `json:"nodeDeletionTimeout,omitempty"` diff --git a/config/crd/bases/cluster.x-k8s.io_clusters.yaml b/config/crd/bases/cluster.x-k8s.io_clusters.yaml index f8cc44b0464d..7fcc8ba13149 100644 --- a/config/crd/bases/cluster.x-k8s.io_clusters.yaml +++ b/config/crd/bases/cluster.x-k8s.io_clusters.yaml @@ -1086,17 +1086,20 @@ spec: NodeDeletionTimeout defines how long the controller will attempt to delete the Node that the Machine hosts after the Machine is marked for deletion. A duration of 0 will retry deletion indefinitely. Defaults to 10 seconds. + pattern: ^(([1-9][0-9]*(\.[0-9]+)?|0?\.[0-9]+)(ns|us|µs|ms|s|m|h))+$ type: string nodeDrainTimeout: description: |- NodeDrainTimeout is the total amount of time that the controller will spend on draining a node. The default value is 0, meaning that the node can be drained without any time limitations. NOTE: NodeDrainTimeout is different from `kubectl drain --timeout` + pattern: ^(([1-9][0-9]*(\.[0-9]+)?|0?\.[0-9]+)(ns|us|µs|ms|s|m|h))+$ type: string nodeVolumeDetachTimeout: description: |- NodeVolumeDetachTimeout is the total amount of time that the controller will spend on waiting for all volumes to be detached. The default value is 0, meaning that the volumes can be detached without any time limitations. + pattern: ^(([1-9][0-9]*(\.[0-9]+)?|0?\.[0-9]+)(ns|us|µs|ms|s|m|h))+$ type: string replicas: description: |-