Skip to content

Commit 9691e7f

Browse files
committed
Tightening validation + adding basic validation tests
1 parent b56d255 commit 9691e7f

32 files changed

+495
-178
lines changed

apis/v1alpha2/gateway_types.go

+5-12
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,7 @@ type Listener struct {
148148
// within a Gateway.
149149
//
150150
// Support: Core
151-
//
152-
// +kubebuilder:validation:MaxLength=253
153-
Name string `json:"name"`
151+
Name SectionName `json:"name"`
154152

155153
// Hostname specifies the virtual hostname to match for protocol types that
156154
// define this concept. When unspecified, "", or `*`, all hostnames are
@@ -322,6 +320,7 @@ type GatewayTLSConfig struct {
322320
// Support: Implementation-specific
323321
//
324322
// +optional
323+
// +kubebuilder:validation:MaxProperties=16
325324
Options map[string]string `json:"options,omitempty"`
326325
}
327326

@@ -414,14 +413,10 @@ type RouteGroupKind struct {
414413
//
415414
// +optional
416415
// +kubebuilder:default=gateway.networking.k8s.io
417-
// +kubebuilder:validation:MaxLength=253
418-
Group *string `json:"group,omitempty"`
416+
Group *Group `json:"group,omitempty"`
419417

420418
// Kind is the kind of the Route.
421-
//
422-
// +kubebuilder:validation:MinLength=1
423-
// +kubebuilder:validation:MaxLength=253
424-
Kind string `json:"kind"`
419+
Kind Kind `json:"kind"`
425420
}
426421

427422
// GatewayAddress describes an address that can be bound to a Gateway.
@@ -622,9 +617,7 @@ type ListenerStatus struct {
622617
// Name is the name of the Listener. If the Gateway has more than one
623618
// Listener present, each ListenerStatus MUST specify a name. The names of
624619
// ListenerStatus objects MUST be unique within a Gateway.
625-
//
626-
// +kubebuilder:validation:MaxLength=253
627-
Name string `json:"name"`
620+
Name SectionName `json:"name"`
628621

629622
// SupportedKinds is the list indicating the Kinds supported by this
630623
// listener. When this is not specified on the Listener, this MUST represent

apis/v1alpha2/gatewayclass_types.go

+5-14
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ type GatewayClassSpec struct {
6161
// and PATH is a valid HTTP path as defined by RFC 3986.
6262
//
6363
// Support: Core
64-
//
65-
// +kubebuilder:validation:MaxLength=253
66-
Controller string `json:"controller"`
64+
Controller GatewayController `json:"controller"`
6765

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

8482
// Description helps describe a GatewayClass with more details.
8583
//
86-
//
8784
// +kubebuilder:validation:MaxLength=64
8885
// +optional
8986
Description *string `json:"description,omitempty"`
@@ -93,15 +90,10 @@ type GatewayClassSpec struct {
9390
// configuration resource within the cluster.
9491
type ParametersReference struct {
9592
// Group is the group of the referent.
96-
//
97-
// +kubebuilder:validation:MaxLength=253
98-
Group string `json:"group"`
93+
Group Group `json:"group"`
9994

10095
// Kind is kind of the referent.
101-
//
102-
// +kubebuilder:validation:MinLength=1
103-
// +kubebuilder:validation:MaxLength=253
104-
Kind string `json:"kind"`
96+
Kind Kind `json:"kind"`
10597

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

112104
// Scope represents if the referent is a Cluster or Namespace scoped resource.
113105
// This may be set to "Cluster" or "Namespace".
106+
//
114107
// +kubebuilder:validation:Enum=Cluster;Namespace
115108
// +kubebuilder:default=Cluster
116109
// +optional
@@ -120,10 +113,8 @@ type ParametersReference struct {
120113
// This field is required when scope is set to "Namespace" and ignored when
121114
// scope is set to "Cluster".
122115
//
123-
// +kubebuilder:validation:MinLength=1
124-
// +kubebuilder:validation:MaxLength=253
125116
// +optional
126-
Namespace *string `json:"namespace,omitempty"`
117+
Namespace *Namespace `json:"namespace,omitempty"`
127118
}
128119

129120
// GatewayClassConditionType is the type for status conditions on

apis/v1alpha2/httproute_types.go

+28-11
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ type HTTPPathMatch struct {
262262
//
263263
// +optional
264264
// +kubebuilder:default="/"
265+
// +kubebuilder:validation:MaxLength=1024
265266
Value *string `json:"value,omitempty"`
266267
}
267268

@@ -282,6 +283,13 @@ const (
282283
HeaderMatchImplementationSpecific HeaderMatchType = "ImplementationSpecific"
283284
)
284285

286+
// HTTPHeaderName is the name of an HTTP header.
287+
//
288+
// +kubebuilder:validation:MinLength=1
289+
// +kubebuilder:validation:MaxLength=256
290+
// +kubebuilder:validation:Pattern=`^[A-Za-z0-9!#$%&'*+\-.^_\x60|~]+$`
291+
type HTTPHeaderName string
292+
285293
// HTTPHeaderMatch describes how to select a HTTP route by matching HTTP request
286294
// headers.
287295
type HTTPHeaderMatch struct {
@@ -314,10 +322,7 @@ type HTTPHeaderMatch struct {
314322
// Generally, proxies should follow the guidance from the RFC:
315323
// https://www.rfc-editor.org/rfc/rfc7230.html#section-3.2.2 regarding
316324
// processing a repeated header, with special handling for "Set-Cookie".
317-
//
318-
// +kubebuilder:validation:MinLength=1
319-
// +kubebuilder:validation:MaxLength=256
320-
Name string `json:"name"`
325+
Name HTTPHeaderName `json:"name"`
321326

322327
// Value is the value of HTTP Header to be matched.
323328
//
@@ -423,14 +428,20 @@ type HTTPRouteMatch struct {
423428
// ANDed together, meaning, a request must match all the specified headers
424429
// to select the route.
425430
//
431+
// +listType=map
432+
// +listMapKey=name
426433
// +optional
434+
// +kubebuilder:validation:MaxItems=16
427435
Headers []HTTPHeaderMatch `json:"headers,omitempty"`
428436

429437
// QueryParams specifies HTTP query parameter matchers. Multiple match
430438
// values are ANDed together, meaning, a request must match all the
431439
// specified query parameters to select the route.
432440
//
441+
// +listType=map
442+
// +listMapKey=name
433443
// +optional
444+
// +kubebuilder:validation:MaxItems=16
434445
QueryParams []HTTPQueryParamMatch `json:"queryParams,omitempty"`
435446

436447
// Method specifies HTTP method matcher.
@@ -574,10 +585,7 @@ type HTTPHeader struct {
574585
// entries with an equivalent header name MUST be ignored. Due to the
575586
// case-insensitivity of header names, "foo" and "Foo" are considered
576587
// equivalent.
577-
//
578-
// +kubebuilder:validation:MinLength=1
579-
// +kubebuilder:validation:MaxLength=256
580-
Name string `json:"name"`
588+
Name HTTPHeaderName `json:"name"`
581589

582590
// Value is the value of HTTP Header to be matched.
583591
//
@@ -604,6 +612,9 @@ type HTTPRequestHeaderFilter struct {
604612
// my-header: bar
605613
//
606614
// +optional
615+
// +listType=map
616+
// +listMapKey=name
617+
// +kubebuilder:validation:MaxItems=16
607618
Set []HTTPHeader `json:"set,omitempty"`
608619

609620
// Add adds the given header(s) (name, value) to the request
@@ -623,6 +634,9 @@ type HTTPRequestHeaderFilter struct {
623634
// my-header: bar
624635
//
625636
// +optional
637+
// +listType=map
638+
// +listMapKey=name
639+
// +kubebuilder:validation:MaxItems=16
626640
Add []HTTPHeader `json:"add,omitempty"`
627641

628642
// Remove the given header(s) from the HTTP request before the
@@ -659,29 +673,32 @@ type HTTPRequestRedirect struct {
659673
// +optional
660674
// +kubebuilder:validation:Enum=HTTP;HTTPS
661675
Protocol *string `json:"protocol,omitempty"`
676+
662677
// Hostname is the hostname to be used in the value of the `Location`
663678
// header in the response.
664679
// When empty, the hostname of the request is used.
665680
//
666681
// Support: Core
667682
//
668683
// +optional
669-
Hostname *string `json:"hostname,omitempty"`
684+
Hostname *Hostname `json:"hostname,omitempty"`
685+
670686
// Port is the port to be used in the value of the `Location`
671687
// header in the response.
672688
// When empty, port (if specified) of the request is used.
673689
//
674690
// Support: Extended
675691
//
676692
// +optional
677-
Port *int `json:"port,omitempty"`
693+
Port *PortNumber `json:"port,omitempty"`
694+
678695
// StatusCode is the HTTP status code to be used in response.
679696
//
680697
// Support: Core
681698
//
682699
// +optional
683700
// +kubebuilder:default=302
684-
// +kubebuilder:validation=301;302
701+
// +kubebuilder:validation:Enum=301;302
685702
StatusCode *int `json:"statusCode,omitempty"`
686703
}
687704

apis/v1alpha2/object_reference_types.go

+8-23
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,10 @@ package v1alpha2
2020
// referrer.
2121
type LocalObjectReference struct {
2222
// Group is the group of the referent.
23-
//
24-
// +kubebuilder:validation:MaxLength=253
25-
Group string `json:"group"`
23+
Group Group `json:"group"`
2624

2725
// Kind is kind of the referent.
28-
//
29-
// +kubebuilder:validation:MinLength=1
30-
// +kubebuilder:validation:MaxLength=253
31-
Kind string `json:"kind"`
26+
Kind Kind `json:"kind"`
3227

3328
// Name is the name of the referent.
3429
//
@@ -44,16 +39,13 @@ type ObjectReference struct {
4439
//
4540
// +optional
4641
// +kubebuilder:default=""
47-
// +kubebuilder:validation:MaxLength=253
48-
Group *string `json:"group"`
42+
Group *Group `json:"group"`
4943

5044
// Kind is kind of the referent.
5145
//
5246
// +optional
5347
// +kubebuilder:default=Service
54-
// +kubebuilder:validation:MinLength=1
55-
// +kubebuilder:validation:MaxLength=253
56-
Kind *string `json:"kind"`
48+
Kind *Kind `json:"kind"`
5749

5850
// Name is the name of the referent.
5951
//
@@ -71,10 +63,8 @@ type ObjectReference struct {
7163
//
7264
// Support: Core
7365
//
74-
// +kubebuilder:validation:MinLength=1
75-
// +kubebuilder:validation:MaxLength=253
7666
// +optional
77-
Namespace *string `json:"namespace,omitempty"`
67+
Namespace *Namespace `json:"namespace,omitempty"`
7868
}
7969

8070
// BackendObjectReference defines how an ObjectReference that is
@@ -91,16 +81,13 @@ type BackendObjectReference struct {
9181
//
9282
// +optional
9383
// +kubebuilder:default=""
94-
// +kubebuilder:validation:MaxLength=253
95-
Group *string `json:"group,omitempty"`
84+
Group *Group `json:"group,omitempty"`
9685

9786
// Kind is kind of the referent.
9887
//
9988
// +optional
10089
// +kubebuilder:default=Service
101-
// +kubebuilder:validation:MinLength=1
102-
// +kubebuilder:validation:MaxLength=253
103-
Kind *string `json:"kind,omitempty"`
90+
Kind *Kind `json:"kind,omitempty"`
10491

10592
// Name is the name of the referent.
10693
//
@@ -118,10 +105,8 @@ type BackendObjectReference struct {
118105
//
119106
// Support: Core
120107
//
121-
// +kubebuilder:validation:MinLength=1
122-
// +kubebuilder:validation:MaxLength=253
123108
// +optional
124-
Namespace *string `json:"namespace,omitempty"`
109+
Namespace *Namespace `json:"namespace,omitempty"`
125110

126111
// Port specifies the destination port number to use for this resource.
127112
// Port is required when the referent is a Kubernetes Service.

apis/v1alpha2/policy_types.go

+3-11
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,10 @@ package v1alpha2
2323
// for Gateway API.
2424
type PolicyTargetReference struct {
2525
// Group is the group of the target resource.
26-
//
27-
// +kubebuilder:validation:MinLength=1
28-
// +kubebuilder:validation:MaxLength=253
29-
Group string `json:"group"`
26+
Group Group `json:"group"`
3027

3128
// Kind is kind of the target resource.
32-
//
33-
// +kubebuilder:validation:MinLength=1
34-
// +kubebuilder:validation:MaxLength=253
35-
Kind string `json:"kind"`
29+
Kind Kind `json:"kind"`
3630

3731
// Name is the name of the target resource.
3832
//
@@ -45,10 +39,8 @@ type PolicyTargetReference struct {
4539
// namespace, it MUST only apply to traffic originating from the same
4640
// namespace as the policy.
4741
//
48-
// +kubebuilder:validation:MinLength=1
49-
// +kubebuilder:validation:MaxLength=253
5042
// +optional
51-
Namespace *string `json:"namespace,omitempty"`
43+
Namespace *Namespace `json:"namespace,omitempty"`
5244

5345
// ClassName is the name of the class this policy should apply to. When
5446
// unspecified, the policy will apply to all classes that support it.

apis/v1alpha2/referencepolicy_types.go

+5-18
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ type ReferencePolicyFrom struct {
8989
// When empty, the "core" API group is inferred.
9090
//
9191
// Support: Core
92-
//
93-
// +kubebuilder:validation:MaxLength=253
94-
Group string `json:"group"`
92+
Group Group `json:"group"`
9593

9694
// Kind is the kind of the referent. Although implementations may support
9795
// additional resources, the following Route types are part of the "Core"
@@ -101,18 +99,12 @@ type ReferencePolicyFrom struct {
10199
// * TCPRoute
102100
// * TLSRoute
103101
// * UDPRoute
104-
//
105-
// +kubebuilder:validation:MinLength=1
106-
// +kubebuilder:validation:MaxLength=253
107-
Kind string `json:"kind"`
102+
Kind Kind `json:"kind"`
108103

109104
// Namespace is the namespace of the referent.
110105
//
111106
// Support: Core
112-
//
113-
// +kubebuilder:validation:MinLength=1
114-
// +kubebuilder:validation:MaxLength=253
115-
Namespace string `json:"namespace,omitempty"`
107+
Namespace Namespace `json:"namespace,omitempty"`
116108
}
117109

118110
// ReferencePolicyTo describes what Kinds are allowed as targets of the
@@ -122,17 +114,12 @@ type ReferencePolicyTo struct {
122114
// When empty, the "core" API group is inferred.
123115
//
124116
// Support: Core
125-
//
126-
// +kubebuilder:validation:MaxLength=253
127-
Group string `json:"group"`
117+
Group Group `json:"group"`
128118

129119
// Kind is the kind of the referent. Although implementations may support
130120
// additional resources, the following types are part of the "Core"
131121
// support level for this field:
132122
//
133123
// * Service
134-
//
135-
// +kubebuilder:validation:MinLength=1
136-
// +kubebuilder:validation:MaxLength=253
137-
Kind string `json:"kind"`
124+
Kind Kind `json:"kind"`
138125
}

0 commit comments

Comments
 (0)