Skip to content

Commit

Permalink
Tightening validation + adding basic validation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robscott committed Aug 12, 2021
1 parent f573729 commit 61654fb
Show file tree
Hide file tree
Showing 25 changed files with 353 additions and 183 deletions.
16 changes: 4 additions & 12 deletions apis/v1alpha2/gateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ type Listener struct {
// within a Gateway.
//
// Support: Core
//
// +kubebuilder:validation:MaxLength=253
Name string `json:"name"`
Name SectionName `json:"name"`

// Hostname specifies the virtual hostname to match for protocol types that
// define this concept. When unspecified, "", or `*`, all hostnames are
Expand Down Expand Up @@ -450,14 +448,10 @@ type RouteGroupKind struct {
//
// +optional
// +kubebuilder:default=gateway.networking.k8s.io
// +kubebuilder:validation:MaxLength=253
Group *string `json:"group,omitempty"`
Group *Group `json:"group,omitempty"`

// Kind is the kind of the Route.
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
Kind string `json:"kind"`
Kind Kind `json:"kind"`
}

// GatewayAddress describes an address that can be bound to a Gateway.
Expand Down Expand Up @@ -658,9 +652,7 @@ type ListenerStatus struct {
// Name is the name of the Listener. If the Gateway has more than one
// Listener present, each ListenerStatus MUST specify a name. The names of
// ListenerStatus objects MUST be unique within a Gateway.
//
// +kubebuilder:validation:MaxLength=253
Name string `json:"name"`
Name SectionName `json:"name"`

// SupportedKinds is the list indicating the Kinds supported by this
// listener. When this is not specified on the Listener, this MUST represent
Expand Down
19 changes: 5 additions & 14 deletions apis/v1alpha2/gatewayclass_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ type GatewayClassSpec struct {
// and PATH is a valid HTTP path as defined by RFC 3986.
//
// Support: Core
//
// +kubebuilder:validation:MaxLength=253
Controller string `json:"controller"`
Controller GatewayController `json:"controller"`

// ParametersRef is a reference to a resource that contains the configuration
// parameters corresponding to the GatewayClass. This is optional if the
Expand All @@ -83,7 +81,6 @@ type GatewayClassSpec struct {

// Description helps describe a GatewayClass with more details.
//
//
// +kubebuilder:validation:MaxLength=64
// +optional
Description *string `json:"description,omitempty"`
Expand All @@ -93,15 +90,10 @@ type GatewayClassSpec struct {
// configuration resource within the cluster.
type ParametersReference struct {
// Group is the group of the referent.
//
// +kubebuilder:validation:MaxLength=253
Group string `json:"group"`
Group Group `json:"group"`

// Kind is kind of the referent.
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
Kind string `json:"kind"`
Kind Kind `json:"kind"`

// Name is the name of the referent.
//
Expand All @@ -111,6 +103,7 @@ type ParametersReference struct {

// Scope represents if the referent is a Cluster or Namespace scoped resource.
// This may be set to "Cluster" or "Namespace".
//
// +kubebuilder:validation:Enum=Cluster;Namespace
// +kubebuilder:default=Cluster
// +optional
Expand All @@ -120,10 +113,8 @@ type ParametersReference struct {
// This field is required when scope is set to "Namespace" and ignored when
// scope is set to "Cluster".
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
// +optional
Namespace *string `json:"namespace,omitempty"`
Namespace *Namespace `json:"namespace,omitempty"`
}

// GatewayClassConditionType is the type for status conditions on
Expand Down
32 changes: 21 additions & 11 deletions apis/v1alpha2/httproute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ type HTTPPathMatch struct {
//
// +optional
// +kubebuilder:default="/"
// +kubebuilder:validation:Pattern=`^[A-Za-z0-9/\-._~%!$&'()*+,;=:]+$`
Value *string `json:"value,omitempty"`
}

Expand All @@ -318,6 +319,13 @@ const (
HeaderMatchImplementationSpecific HeaderMatchType = "ImplementationSpecific"
)

// HTTPHeaderName is the name of an HTTP header.
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=256
// +kubebuilder:validation:Pattern=`^[-A-Za-z0-9]+$`
type HTTPHeaderName string

// HTTPHeaderMatch describes how to select a HTTP route by matching HTTP request
// headers.
type HTTPHeaderMatch struct {
Expand All @@ -344,10 +352,7 @@ type HTTPHeaderMatch struct {
// entries with an equivalent header name MUST be ignored. Due to the
// case-insensitivity of header names, "foo" and "Foo" are considered
// equivalent.
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=256
Name string `json:"name"`
Name HTTPHeaderName `json:"name"`

// Value is the value of HTTP Header to be matched.
//
Expand Down Expand Up @@ -453,13 +458,17 @@ type HTTPRouteMatch struct {
// ANDed together, meaning, a request must match all the specified headers
// to select the route.
//
// +listType=map
// +listMapKey=name
// +optional
Headers []HTTPHeaderMatch `json:"headers,omitempty"`

// QueryParams specifies HTTP query parameter matchers. Multiple match
// values are ANDed together, meaning, a request must match all the
// specified query parameters to select the route.
//
// +listType=map
// +listMapKey=name
// +optional
QueryParams []HTTPQueryParamMatch `json:"queryParams,omitempty"`

Expand Down Expand Up @@ -604,10 +613,7 @@ type HTTPHeader struct {
// entries with an equivalent header name MUST be ignored. Due to the
// case-insensitivity of header names, "foo" and "Foo" are considered
// equivalent.
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=256
Name string `json:"name"`
Name HTTPHeaderName `json:"name"`

// Value is the value of HTTP Header to be matched.
//
Expand Down Expand Up @@ -688,30 +694,34 @@ type HTTPRequestRedirect struct {
//
// +optional
// +kubebuilder:validation:Enum=HTTP;HTTPS

Protocol *string `json:"protocol,omitempty"`

// Hostname is the hostname to be used in the value of the `Location`
// header in the response.
// When empty, the hostname of the request is used.
//
// Support: Core
//
// +optional
Hostname *string `json:"hostname,omitempty"`
Hostname *Hostname `json:"hostname,omitempty"`

// Port is the port to be used in the value of the `Location`
// header in the response.
// When empty, port (if specified) of the request is used.
//
// Support: Extended
//
// +optional
Port *int `json:"port,omitempty"`
Port *PortNumber `json:"port,omitempty"`

// StatusCode is the HTTP status code to be used in response.
//
// Support: Core
//
// +optional
// +kubebuilder:default=302
// +kubebuilder:validation=301;302
// +kubebuilder:validation:Enum=301;302
StatusCode *int `json:"statusCode,omitempty"`
}

Expand Down
31 changes: 8 additions & 23 deletions apis/v1alpha2/object_reference_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,10 @@ package v1alpha2
// referrer.
type LocalObjectReference struct {
// Group is the group of the referent.
//
// +kubebuilder:validation:MaxLength=253
Group string `json:"group"`
Group Group `json:"group"`

// Kind is kind of the referent.
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
Kind string `json:"kind"`
Kind Kind `json:"kind"`

// Name is the name of the referent.
//
Expand All @@ -44,16 +39,13 @@ type ObjectReference struct {
//
// +optional
// +kubebuilder:default=""
// +kubebuilder:validation:MaxLength=253
Group *string `json:"group"`
Group *Group `json:"group"`

// Kind is kind of the referent.
//
// +optional
// +kubebuilder:default=Service
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
Kind *string `json:"kind"`
Kind *Kind `json:"kind"`

// Name is the name of the referent.
//
Expand All @@ -71,10 +63,8 @@ type ObjectReference struct {
//
// Support: Core
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
// +optional
Namespace *string `json:"namespace,omitempty"`
Namespace *Namespace `json:"namespace,omitempty"`
}

// BackendObjectReference defines how an ObjectReference that is
Expand All @@ -91,16 +81,13 @@ type BackendObjectReference struct {
//
// +optional
// +kubebuilder:default=""
// +kubebuilder:validation:MaxLength=253
Group *string `json:"group,omitempty"`
Group *Group `json:"group,omitempty"`

// Kind is kind of the referent.
//
// +optional
// +kubebuilder:default=Service
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
Kind *string `json:"kind,omitempty"`
Kind *Kind `json:"kind,omitempty"`

// Name is the name of the referent.
//
Expand All @@ -118,10 +105,8 @@ type BackendObjectReference struct {
//
// Support: Core
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
// +optional
Namespace *string `json:"namespace,omitempty"`
Namespace *Namespace `json:"namespace,omitempty"`

// Port specifies the destination port number to use for this resource.
// Port is required when the referent is a Kubernetes Service.
Expand Down
14 changes: 3 additions & 11 deletions apis/v1alpha2/policy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,10 @@ package v1alpha2
// for Gateway API.
type PolicyTargetReference struct {
// Group is the group of the target resource.
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
Group string `json:"group"`
Group Group `json:"group"`

// Kind is kind of the target resource.
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
Kind string `json:"kind"`
Kind Kind `json:"kind"`

// Name is the name of the target resource.
//
Expand All @@ -45,10 +39,8 @@ type PolicyTargetReference struct {
// namespace, it MUST only apply to traffic originating from the same
// namespace as the policy.
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
// +optional
Namespace *string `json:"namespace,omitempty"`
Namespace *Namespace `json:"namespace,omitempty"`

// ClassName is the name of the class this policy should apply to. When
// unspecified, the policy will apply to all classes that support it.
Expand Down
23 changes: 5 additions & 18 deletions apis/v1alpha2/referencepolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ type ReferencePolicyFrom struct {
// When empty, the "core" API group is inferred.
//
// Support: Core
//
// +kubebuilder:validation:MaxLength=253
Group string `json:"group"`
Group Group `json:"group"`

// Kind is the kind of the referent. Although implementations may support
// additional resources, the following Route types are part of the "Core"
Expand All @@ -101,18 +99,12 @@ type ReferencePolicyFrom struct {
// * TCPRoute
// * TLSRoute
// * UDPRoute
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
Kind string `json:"kind"`
Kind Kind `json:"kind"`

// Namespace is the namespace of the referent.
//
// Support: Core
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
Namespace string `json:"namespace,omitempty"`
Namespace Namespace `json:"namespace,omitempty"`
}

// ReferencePolicyTo describes what Kinds are allowed as targets of the
Expand All @@ -122,17 +114,12 @@ type ReferencePolicyTo struct {
// When empty, the "core" API group is inferred.
//
// Support: Core
//
// +kubebuilder:validation:MaxLength=253
Group string `json:"group"`
Group Group `json:"group"`

// Kind is the kind of the referent. Although implementations may support
// additional resources, the following types are part of the "Core"
// support level for this field:
//
// * Service
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
Kind string `json:"kind"`
Kind Kind `json:"kind"`
}
Loading

0 comments on commit 61654fb

Please sign in to comment.