Skip to content

cleanup: Use CEL format.dns1123Subdomain() for hostname validation #4450

@rostislavbobo

Description

@rostislavbobo

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions