Skip to content

Commit

Permalink
Merge pull request #2226 from gauravkghildiyal/cel-validation
Browse files Browse the repository at this point in the history
Introduce validations through CEL for Gateway and GatewayClass.
  • Loading branch information
k8s-ci-robot committed Jul 27, 2023
2 parents 7aabadb + 2210ded commit 3ae9fa7
Show file tree
Hide file tree
Showing 10 changed files with 831 additions and 0 deletions.
11 changes: 11 additions & 0 deletions apis/v1beta1/gateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ type GatewaySpec struct {
// +listMapKey=name
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:MaxItems=64
// +kubebuilder:validation:XValidation:message="tls must be set for protocols ['HTTPS', 'TLS']",rule="self.all(l, l.protocol in ['HTTPS', 'TLS'] ? has(l.tls) : true)"
// +kubebuilder:validation:XValidation:message="tls must be empty for protocols ['HTTP', 'TCP', 'UDP']",rule="self.all(l, l.protocol in ['HTTP', 'TCP', 'UDP'] ? !has(l.tls) : true)"
// +kubebuilder:validation:XValidation:message="hostname must be empty for protocols ['TCP', 'UDP']",rule="self.all(l, l.protocol in ['TCP', 'UDP'] ? (!has(l.hostname) || l.hostname == '') : true)"
// +kubebuilder:validation:XValidation:message="Listener name must be unique within the Gateway",rule="self.all(l1, self.exists_one(l2, l1.name == l2.name))"
// +kubebuilder:validation:XValidation:message="Combination of port, protocol and hostname must be unique for each listener",rule="self.all(l1, self.exists_one(l2, l1.port == l2.port && l1.protocol == l2.protocol && (has(l1.hostname) && has(l2.hostname) ? l1.hostname == l2.hostname : true)))"
Listeners []Listener `json:"listeners"`

// Infrastructure defines infrastructure level attributes about this Gateway instance.
Expand Down Expand Up @@ -151,6 +156,8 @@ type GatewaySpec struct {
//
// +optional
// +kubebuilder:validation:MaxItems=16
// +kubebuilder:validation:XValidation:message="IPAddress values must be unique",rule="self.all(a1, a1.type == 'IPAddress' ? self.exists_one(a2, a2.type == a1.type && a2.value == a1.value) : true )"
// +kubebuilder:validation:XValidation:message="Hostname values must be unique",rule="self.all(a1, a1.type == 'Hostname' ? self.exists_one(a2, a2.type == a1.type && a2.value == a1.value) : true )"
Addresses []GatewayAddress `json:"addresses,omitempty"`
}

Expand Down Expand Up @@ -361,6 +368,8 @@ const (
)

// GatewayTLSConfig describes a TLS configuration.
//
// +kubebuilder:validation:XValidation:message="certificateRefs must be set and not empty when TLSModeType is Terminate",rule="self.mode == 'Terminate' ? size(self.certificateRefs) > 0 : true"
type GatewayTLSConfig struct {
// Mode defines the TLS behavior for the TLS session initiated by the client.
// There are two possible modes:
Expand Down Expand Up @@ -526,6 +535,8 @@ type RouteGroupKind struct {
}

// GatewayAddress describes an address that can be bound to a Gateway.
//
// +kubebuilder:validation:XValidation:message="Hostname value must only contain valid characters (matching ^(\\*\\.)?[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$)",rule="self.type == 'Hostname' ? self.value.matches('^(\\\\*\\\\.)?[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$'): true"
type GatewayAddress struct {
// Type of the address.
//
Expand Down
2 changes: 2 additions & 0 deletions apis/v1beta1/gatewayclass_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ type GatewayClassSpec struct {
// This field is not mutable and cannot be empty.
//
// Support: Core
//
// +kubebuilder:validation:XValidation:message="Value is immutable",rule="self == oldSelf"
ControllerName GatewayController `json:"controllerName"`

// ParametersRef is a reference to a resource that contains the configuration
Expand Down

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

68 changes: 68 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.

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

68 changes: 68 additions & 0 deletions config/crd/standard/gateway.networking.k8s.io_gateways.yaml

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

Loading

0 comments on commit 3ae9fa7

Please sign in to comment.