Skip to content

Commit a5607ee

Browse files
feat(api): support Replace mergeType in BTP and SP
Signed-off-by: mehara-rothila <rothilamehara22@gmail.com>
1 parent 04aadb9 commit a5607ee

17 files changed

Lines changed: 606 additions & 40 deletions

api/v1alpha1/backendtrafficpolicy_types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ type BackendTrafficPolicySpec struct {
5656
// This field cannot be set when targeting a parent resource (Gateway).
5757
// If unset, no merging occurs, and only the most specific configuration takes effect.
5858
//
59-
// +kubebuilder:validation:XValidation:rule="self != 'Replace'",message="Replace is not a valid MergeType for BackendTrafficPolicySpec"
6059
// +optional
6160
MergeType *MergeType `json:"mergeType,omitempty"`
6261

api/v1alpha1/securitypolicy_types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ type SecurityPolicySpec struct {
5959
// This field cannot be set when targeting a parent resource (Gateway).
6060
// If unset, no merging occurs, and only the most specific configuration takes effect.
6161
//
62-
// +kubebuilder:validation:XValidation:rule="self != 'Replace'",message="Replace is not a valid MergeType for SecurityPolicy"
6362
// +optional
6463
MergeType *MergeType `json:"mergeType,omitempty"`
6564

charts/gateway-crds-helm/templates/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,9 +1439,6 @@ spec:
14391439
This field cannot be set when targeting a parent resource (Gateway).
14401440
If unset, no merging occurs, and only the most specific configuration takes effect.
14411441
type: string
1442-
x-kubernetes-validations:
1443-
- message: Replace is not a valid MergeType for BackendTrafficPolicySpec
1444-
rule: self != 'Replace'
14451442
proxyProtocol:
14461443
description: ProxyProtocol enables the Proxy Protocol when communicating
14471444
with the backend.

charts/gateway-crds-helm/templates/generated/gateway.envoyproxy.io_securitypolicies.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5414,9 +5414,6 @@ spec:
54145414
This field cannot be set when targeting a parent resource (Gateway).
54155415
If unset, no merging occurs, and only the most specific configuration takes effect.
54165416
type: string
5417-
x-kubernetes-validations:
5418-
- message: Replace is not a valid MergeType for SecurityPolicy
5419-
rule: self != 'Replace'
54205417
oidc:
54215418
description: OIDC defines the configuration for the OpenID Connect
54225419
(OIDC) authentication.

charts/gateway-helm/charts/crds/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,9 +1438,6 @@ spec:
14381438
This field cannot be set when targeting a parent resource (Gateway).
14391439
If unset, no merging occurs, and only the most specific configuration takes effect.
14401440
type: string
1441-
x-kubernetes-validations:
1442-
- message: Replace is not a valid MergeType for BackendTrafficPolicySpec
1443-
rule: self != 'Replace'
14441441
proxyProtocol:
14451442
description: ProxyProtocol enables the Proxy Protocol when communicating
14461443
with the backend.

charts/gateway-helm/charts/crds/crds/generated/gateway.envoyproxy.io_securitypolicies.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5413,9 +5413,6 @@ spec:
54135413
This field cannot be set when targeting a parent resource (Gateway).
54145414
If unset, no merging occurs, and only the most specific configuration takes effect.
54155415
type: string
5416-
x-kubernetes-validations:
5417-
- message: Replace is not a valid MergeType for SecurityPolicy
5418-
rule: self != 'Replace'
54195416
oidc:
54205417
description: OIDC defines the configuration for the OpenID Connect
54215418
(OIDC) authentication.

internal/gatewayapi/backendtrafficpolicy.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,9 @@ func (t *Translator) translateBackendTrafficPolicyForRouteWithMerge(
884884
// Replace the rate limit in the merged features if successful
885885
tf.RateLimit = mergedRL
886886
}
887-
} else if policy.Spec.RateLimit == nil && parentPolicy.Spec.RateLimit != nil {
887+
} else if policy.Spec.RateLimit == nil &&
888+
parentPolicy.Spec.RateLimit != nil &&
889+
*policy.Spec.MergeType != egv1a1.Replace {
888890
// Case 2: Only gateway policy has rate limits - preserve gateway policy's rule names
889891
tfGW, _ := t.buildTrafficFeatures(parentPolicy)
890892
if tfGW != nil && tfGW.RateLimit != nil {
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
gateways:
2+
- apiVersion: gateway.networking.k8s.io/v1
3+
kind: Gateway
4+
metadata:
5+
namespace: envoy-gateway
6+
name: gateway-1
7+
spec:
8+
gatewayClassName: envoy-gateway-class
9+
listeners:
10+
- name: http
11+
protocol: HTTP
12+
port: 80
13+
allowedRoutes:
14+
namespaces:
15+
from: All
16+
- apiVersion: gateway.networking.k8s.io/v1
17+
kind: Gateway
18+
metadata:
19+
namespace: envoy-gateway
20+
name: gateway-2
21+
spec:
22+
gatewayClassName: envoy-gateway-class
23+
listeners:
24+
- name: http
25+
protocol: HTTP
26+
port: 80
27+
allowedRoutes:
28+
namespaces:
29+
from: All
30+
httpRoutes:
31+
- apiVersion: gateway.networking.k8s.io/v1
32+
kind: HTTPRoute
33+
metadata:
34+
namespace: default
35+
name: httproute-1
36+
spec:
37+
hostnames:
38+
- gateway.envoyproxy.io
39+
parentRefs:
40+
- namespace: envoy-gateway
41+
name: gateway-1
42+
sectionName: http
43+
- namespace: envoy-gateway
44+
name: gateway-2
45+
sectionName: http
46+
rules:
47+
- matches:
48+
- path:
49+
value: "/"
50+
backendRefs:
51+
- name: service-1
52+
port: 8080
53+
backendTrafficPolicies:
54+
- apiVersion: gateway.envoyproxy.io/v1alpha1
55+
kind: BackendTrafficPolicy
56+
metadata:
57+
namespace: envoy-gateway
58+
name: policy-for-gateway1
59+
spec:
60+
targetRef:
61+
group: gateway.networking.k8s.io
62+
kind: Gateway
63+
name: gateway-1
64+
timeout:
65+
tcp:
66+
connectTimeout: 15s
67+
http:
68+
connectionIdleTimeout: 16s
69+
maxConnectionDuration: 17s
70+
httpUpgrade:
71+
- type: websocket
72+
rateLimit:
73+
type: Global
74+
global:
75+
rules:
76+
- clientSelectors:
77+
- sourceCIDR:
78+
type: Distinct
79+
value: 0.0.0.0/0
80+
limit:
81+
requests: 5
82+
unit: Hour
83+
shared: true
84+
- clientSelectors:
85+
- headers:
86+
- name: x-user-id
87+
type: Exact
88+
value: one
89+
limit:
90+
requests: 5
91+
unit: Hour
92+
shared: true
93+
- apiVersion: gateway.envoyproxy.io/v1alpha1
94+
kind: BackendTrafficPolicy
95+
metadata:
96+
namespace: default
97+
name: policy-for-route
98+
spec:
99+
targetRef:
100+
group: gateway.networking.k8s.io
101+
kind: HTTPRoute
102+
name: httproute-1
103+
mergeType: Replace
104+
timeout:
105+
tcp:
106+
connectTimeout: 10s
107+
connection:
108+
bufferLimit: 100M
109+
httpUpgrade:
110+
- type: "spdy/3.1"

0 commit comments

Comments
 (0)