Skip to content

Commit c7070cc

Browse files
ymesikadavidjumani
authored andcommitted
Add support for CORS configuration in TrafficPolicy and in HTTPRoute (kgateway-dev#11252)
Signed-off-by: Yossi Mesika <[email protected]>
1 parent 5acc634 commit c7070cc

36 files changed

+16264
-11935
lines changed

.github/workflows/pr-kubernetes-tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
# May 19, 2025: ~18 minutes
4040
- cluster-name: 'cluster-three'
4141
go-test-args: '-v -timeout=25m'
42-
go-test-run-regex: '^TestKgateway$$/^Deployer$$|^TestKgateway$$/^RouteDelegation$$|^TestKgateway$$/^Lambda$$|^TestKgateway$$/^AccessLog$$|^TestKgateway$$/^LocalRateLimit$$'
42+
go-test-run-regex: '^TestKgateway$$/^Deployer$$|^TestKgateway$$/^RouteDelegation$$|^TestKgateway$$/^Lambda$$|^TestKgateway$$/^AccessLog$$|^TestKgateway$$/^LocalRateLimit$$|^TestKgateway$$/^Cors$$'
4343
localstack: 'true'
4444
# May 19, 2025: ~20 minutes
4545
- cluster-name: 'cluster-four'

api/applyconfiguration/api/v1alpha1/corspolicy.go

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/applyconfiguration/api/v1alpha1/trafficpolicyspec.go

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/applyconfiguration/internal/internal.go

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/applyconfiguration/utils.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha1/traffic_policy_types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ type TrafficPolicySpec struct {
6868
// This controls the rate at which requests are allowed to be processed.
6969
// +optional
7070
RateLimit *RateLimit `json:"rateLimit,omitempty"`
71+
72+
// Cors specifies the CORS configuration for the policy.
73+
// +optional
74+
Cors *CorsPolicy `json:"cors,omitempty"`
7175
}
7276

7377
// TransformationPolicy config is used to modify envoy behavior at a route level.
@@ -333,3 +337,8 @@ type RateLimitDescriptorEntryGeneric struct {
333337
// +required
334338
Value string `json:"value"`
335339
}
340+
341+
type CorsPolicy struct {
342+
// +kubebuilder:pruning:PreserveUnknownFields
343+
*gwv1.HTTPCORSFilter `json:",inline"`
344+
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

install/helm/kgateway-crds/templates/gateway.kgateway.dev_trafficpolicies.yaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,66 @@ spec:
273273
- CHAT_STREAMING
274274
type: string
275275
type: object
276+
cors:
277+
properties:
278+
allowCredentials:
279+
enum:
280+
- true
281+
type: boolean
282+
allowHeaders:
283+
items:
284+
maxLength: 256
285+
minLength: 1
286+
pattern: ^[A-Za-z0-9!#$%&'*+\-.^_\x60|~]+$
287+
type: string
288+
maxItems: 64
289+
type: array
290+
x-kubernetes-list-type: set
291+
allowMethods:
292+
items:
293+
enum:
294+
- GET
295+
- HEAD
296+
- POST
297+
- PUT
298+
- DELETE
299+
- CONNECT
300+
- OPTIONS
301+
- TRACE
302+
- PATCH
303+
- '*'
304+
type: string
305+
maxItems: 9
306+
type: array
307+
x-kubernetes-list-type: set
308+
x-kubernetes-validations:
309+
- message: AllowMethods cannot contain '*' alongside other methods
310+
rule: '!(''*'' in self && self.size() > 1)'
311+
allowOrigins:
312+
items:
313+
maxLength: 253
314+
minLength: 1
315+
pattern: ^(([^:/?#]+):)(//([^/?#]*))([^?#]*)(\?([^#]*))?(#(.*))?
316+
type: string
317+
maxItems: 64
318+
type: array
319+
x-kubernetes-list-type: set
320+
exposeHeaders:
321+
items:
322+
maxLength: 256
323+
minLength: 1
324+
pattern: ^[A-Za-z0-9!#$%&'*+\-.^_\x60|~]+$
325+
type: string
326+
maxItems: 64
327+
type: array
328+
x-kubernetes-list-type: set
329+
maxAge:
330+
default: 5
331+
format: int32
332+
minimum: 1
333+
type: integer
334+
type: object
335+
x-kubernetes-preserve-unknown-fields: true
276336
extAuth:
277337
properties:
278338
contextExtensions:

0 commit comments

Comments
 (0)