Ensure configuration fields use consistent validation patterns, appropriate data types, and proper bounds checking. This includes using correct regex patterns for duration fields, consistent type usage across similar fields, and implementing cross-field validation where relationships exist.
Ensure configuration fields use consistent validation patterns, appropriate data types, and proper bounds checking. This includes using correct regex patterns for duration fields, consistent type usage across similar fields, and implementing cross-field validation where relationships exist.
Key practices:
^[0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h)?$
instead of the complex ^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$
for duration fieldsptypes.Duration
consistently for timeout/duration configurations rather than mixing with time.Duration
+kubebuilder:validation:Minimum=0
and maximum bounds where applicableExample of proper duration field validation:
// DialTimeout is the amount of time to wait until a connection can be established.
// +kubebuilder:validation:Pattern="^[0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h)?$"
// +kubebuilder:validation:XIntOrString
DialTimeout *intstr.IntOrString `json:"dialTimeout,omitempty"`
This ensures configuration fields are validated consistently, preventing runtime errors and improving user experience with clear validation messages.
Enter the URL of a public GitHub repository