Skip to content

Commit 42e0fe9

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 42e0fe9

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

api/v1beta1/cluster_types.go

+18
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

@@ -226,17 +232,23 @@ type MachineDeploymentTopology struct {
226232
// NodeDrainTimeout is the total amount of time that the controller will spend on draining a node.
227233
// The default value is 0, meaning that the node can be drained without any time limitations.
228234
// NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
235+
// +kubebuilder:validation:Pattern="^(([1-9][0-9]*(\\.[0-9]+)?|0?\\.[0-9]+)(ns|us|µs|ms|s|m|h))+$"
236+
// +kubebuilder:validation:Type:=string
229237
// +optional
230238
NodeDrainTimeout *metav1.Duration `json:"nodeDrainTimeout,omitempty"`
231239

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

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

@@ -303,17 +315,23 @@ type MachinePoolTopology struct {
303315
// NodeDrainTimeout is the total amount of time that the controller will spend on draining a node.
304316
// The default value is 0, meaning that the node can be drained without any time limitations.
305317
// NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
318+
// +kubebuilder:validation:Pattern="^(([1-9][0-9]*(\\.[0-9]+)?|0?\\.[0-9]+)(ns|us|µs|ms|s|m|h))+$"
319+
// +kubebuilder:validation:Type:=string
306320
// +optional
307321
NodeDrainTimeout *metav1.Duration `json:"nodeDrainTimeout,omitempty"`
308322

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

314330
// NodeDeletionTimeout defines how long the controller will attempt to delete the Node that the MachinePool
315331
// hosts after the MachinePool is marked for deletion. A duration of 0 will retry deletion indefinitely.
316332
// Defaults to 10 seconds.
333+
// +kubebuilder:validation:Pattern="^(([1-9][0-9]*(\\.[0-9]+)?|0?\\.[0-9]+)(ns|us|µs|ms|s|m|h))+$"
334+
// +kubebuilder:validation:Type:=string
317335
// +optional
318336
NodeDeletionTimeout *metav1.Duration `json:"nodeDeletionTimeout,omitempty"`
319337

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

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

0 commit comments

Comments
 (0)