Skip to content

Commit 72a0a7c

Browse files
add basic validation for time duration
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 <[email protected]>
1 parent 9569cd6 commit 72a0a7c

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

api/v1beta1/cluster_types.go

+6
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,23 @@ type ControlPlaneTopology struct {
153153
// NodeDrainTimeout is the total amount of time that the controller will spend on draining a node.
154154
// The default value is 0, meaning that the node can be drained without any time limitations.
155155
// NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
156+
// +kubebuilder:validation:Pattern="^(([1-9][0-9]*(\\.[0-9]+)?|0?\\.[0-9]+)(ns|us|µs|ms|s|m|h))+$"
157+
// +kubebuilder:validation:Type:=string
156158
// +optional
157159
NodeDrainTimeout *metav1.Duration `json:"nodeDrainTimeout,omitempty"`
158160

159161
// NodeVolumeDetachTimeout is the total amount of time that the controller will spend on waiting for all volumes
160162
// to be detached. The default value is 0, meaning that the volumes can be detached without any time limitations.
163+
// +kubebuilder:validation:Pattern="^(([1-9][0-9]*(\\.[0-9]+)?|0?\\.[0-9]+)(ns|us|µs|ms|s|m|h))+$"
164+
// +kubebuilder:validation:Type:=string
161165
// +optional
162166
NodeVolumeDetachTimeout *metav1.Duration `json:"nodeVolumeDetachTimeout,omitempty"`
163167

164168
// NodeDeletionTimeout defines how long the controller will attempt to delete the Node that the Machine
165169
// hosts after the Machine is marked for deletion. A duration of 0 will retry deletion indefinitely.
166170
// Defaults to 10 seconds.
171+
// +kubebuilder:validation:Pattern="^(([1-9][0-9]*(\\.[0-9]+)?|0?\\.[0-9]+)(ns|us|µs|ms|s|m|h))+$"
172+
// +kubebuilder:validation:Type:=string
167173
// +optional
168174
NodeDeletionTimeout *metav1.Duration `json:"nodeDeletionTimeout,omitempty"`
169175

config/crd/bases/cluster.x-k8s.io_clusters.yaml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)