Skip to content

Commit 4b65d8a

Browse files
committed
Tightening validation + adding basic validation tests
1 parent f573729 commit 4b65d8a

25 files changed

+346
-186
lines changed

apis/v1alpha2/gateway_types.go

+4-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
@@ -450,14 +448,10 @@ type RouteGroupKind struct {
450448
//
451449
// +optional
452450
// +kubebuilder:default=gateway.networking.k8s.io
453-
// +kubebuilder:validation:MaxLength=253
454-
Group *string `json:"group,omitempty"`
451+
Group *Group `json:"group,omitempty"`
455452

456453
// Kind is the kind of the Route.
457-
//
458-
// +kubebuilder:validation:MinLength=1
459-
// +kubebuilder:validation:MaxLength=253
460-
Kind string `json:"kind"`
454+
Kind Kind `json:"kind"`
461455
}
462456

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

665657
// SupportedKinds is the list indicating the Kinds supported by this
666658
// 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

+21-11
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ type HTTPPathMatch struct {
298298
//
299299
// +optional
300300
// +kubebuilder:default="/"
301+
// +kubebuilder:validation:MaxLength=1024
301302
Value *string `json:"value,omitempty"`
302303
}
303304

@@ -318,6 +319,13 @@ const (
318319
HeaderMatchImplementationSpecific HeaderMatchType = "ImplementationSpecific"
319320
)
320321

322+
// HTTPHeaderName is the name of an HTTP header.
323+
//
324+
// +kubebuilder:validation:MinLength=1
325+
// +kubebuilder:validation:MaxLength=256
326+
// +kubebuilder:validation:Pattern=`^[-A-Za-z0-9]+$`
327+
type HTTPHeaderName string
328+
321329
// HTTPHeaderMatch describes how to select a HTTP route by matching HTTP request
322330
// headers.
323331
type HTTPHeaderMatch struct {
@@ -344,10 +352,7 @@ type HTTPHeaderMatch struct {
344352
// entries with an equivalent header name MUST be ignored. Due to the
345353
// case-insensitivity of header names, "foo" and "Foo" are considered
346354
// equivalent.
347-
//
348-
// +kubebuilder:validation:MinLength=1
349-
// +kubebuilder:validation:MaxLength=256
350-
Name string `json:"name"`
355+
Name HTTPHeaderName `json:"name"`
351356

352357
// Value is the value of HTTP Header to be matched.
353358
//
@@ -453,13 +458,17 @@ type HTTPRouteMatch struct {
453458
// ANDed together, meaning, a request must match all the specified headers
454459
// to select the route.
455460
//
461+
// +listType=map
462+
// +listMapKey=name
456463
// +optional
457464
Headers []HTTPHeaderMatch `json:"headers,omitempty"`
458465

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

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

612618
// Value is the value of HTTP Header to be matched.
613619
//
@@ -688,30 +694,34 @@ type HTTPRequestRedirect struct {
688694
//
689695
// +optional
690696
// +kubebuilder:validation:Enum=HTTP;HTTPS
697+
691698
Protocol *string `json:"protocol,omitempty"`
699+
692700
// Hostname is the hostname to be used in the value of the `Location`
693701
// header in the response.
694702
// When empty, the hostname of the request is used.
695703
//
696704
// Support: Core
697705
//
698706
// +optional
699-
Hostname *string `json:"hostname,omitempty"`
707+
Hostname *Hostname `json:"hostname,omitempty"`
708+
700709
// Port is the port to be used in the value of the `Location`
701710
// header in the response.
702711
// When empty, port (if specified) of the request is used.
703712
//
704713
// Support: Extended
705714
//
706715
// +optional
707-
Port *int `json:"port,omitempty"`
716+
Port *PortNumber `json:"port,omitempty"`
717+
708718
// StatusCode is the HTTP status code to be used in response.
709719
//
710720
// Support: Core
711721
//
712722
// +optional
713723
// +kubebuilder:default=302
714-
// +kubebuilder:validation=301;302
724+
// +kubebuilder:validation:Enum=301;302
715725
StatusCode *int `json:"statusCode,omitempty"`
716726
}
717727

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)