Skip to content

Commit

Permalink
Validate prefix length of DNS subdomain in label and anootaion keys
Browse files Browse the repository at this point in the history
Signed-off-by: Norwin Schnyder <norwin.schnyder+github@gmail.com>
  • Loading branch information
snorwin committed Aug 21, 2024
1 parent 28e6f1e commit cdc8e22
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apis/v1/gateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ type GatewayInfrastructure struct {
// +optional
// +kubebuilder:validation:MaxProperties=8
// +kubebuilder:validation:XValidation:message="Label keys must be in the form of an optional DNS subdomain prefix followed by a required name segment of up to 63 characters.",rule="self.all(key, key.matches(r\"\"\"^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$\"\"\"))"
// +kubebuilder:validation:XValidation:message="If specified, the label key's prefix must be a DNS subdomain not longer than 253 characters in total.",rule="self.all(key, key.split(\"/\")[0].size() < 253)"
Labels map[LabelKey]LabelValue `json:"labels,omitempty"`

// Annotations that SHOULD be applied to any resources created in response to this Gateway.
Expand All @@ -698,6 +699,7 @@ type GatewayInfrastructure struct {
// +optional
// +kubebuilder:validation:MaxProperties=8
// +kubebuilder:validation:XValidation:message="Annotation keys must be in the form of an optional DNS subdomain prefix followed by a required name segment of up to 63 characters.",rule="self.all(key, key.matches(r\"\"\"^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$\"\"\"))"
// +kubebuilder:validation:XValidation:message="If specified, the annotation key's prefix must be a DNS subdomain not longer than 253 characters in total.",rule="self.all(key, key.split(\"/\")[0].size() < 253)"
Annotations map[AnnotationKey]AnnotationValue `json:"annotations,omitempty"`

// ParametersRef is a reference to a resource that contains the configuration
Expand Down
12 changes: 12 additions & 0 deletions config/crd/experimental/gateway.networking.k8s.io_gateways.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cdc8e22

Please sign in to comment.