generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 658
Open
Description
What would you like to be added:
Replace the regex hostnames variation with the native CEL library call, which is more readable and maintained upstream.
For example:
// +kubebuilder:validation:XValidation:message="Hostnames must be valid based on RFC-1123",rule="self.all(h, !h.contains('*') ? !format.dns1123Subdomain().validate(h).hasValue() : true )"
// +kubebuilder:validation:XValidation:message="Wildcards on hostnames must be the first label, and the rest of hostname must be valid based on RFC-1123",rule="self.all(h, h.contains('*') ? (h.startsWith('*.') && !format.dns1123Subdomain().validate(h.substring(2)).hasValue()) : true )"
Hostnames []Hostname `json:"hostnames,omitempty"`
Why this is needed:
Currently, we use a regex pattern in the CEL validation rules for TLSRoute (and potentially other resources) to validate hostnames against RFC-1123.
We previously attempted to use the built-in CEL function format.dns1123Subdomain(), but this caused failures in environments where the Kubernetes version or CEL libraries were older than v1.31 (see context in #4439 (comment)).
Metadata
Metadata
Assignees
Labels
No labels