Skip to content

Commit 6fefbac

Browse files
committed
fix: merged policy status
1 parent 689d266 commit 6fefbac

File tree

3 files changed

+205
-19
lines changed

3 files changed

+205
-19
lines changed

internal/gatewayapi/helpers.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -830,19 +830,22 @@ func getOverriddenAndMergedTargetsMessageForGateway(
830830
var overrideMessage, mergedMessage string
831831

832832
gwNN := utils.NamespacedName(targetContext.GatewayContext)
833+
// Initialize sets
834+
overrideRouteSet := sets.New[string]()
835+
mergedRouteSet := sets.New[string]()
833836

834837
// Get merged targets
835838
if gatewayPolicyMergedMap.Routes != nil {
836839
if sectionName == nil {
837-
// When sectionName is nil, retrieve routes from all listeners including Gateway-level ("")
840+
// When sectionName is nil, retrieve routes from all listeners
838841
if gatewayPolicyMergedMap.SectionIndex != nil && gatewayPolicyMergedMap.SectionIndex[gwNN] != nil {
839842
for _, listener := range gatewayPolicyMergedMap.SectionIndex[gwNN].UnsortedList() {
840843
listenerKey := NamespacedNameWithSection{
841844
NamespacedName: gwNN,
842845
SectionName: gwapiv1.SectionName(listener),
843846
}
844847
if routeSet, ok := gatewayPolicyMergedMap.Routes[listenerKey]; ok {
845-
mergedRoutes = append(mergedRoutes, routeSet.UnsortedList()...)
848+
mergedRouteSet.Insert(routeSet.UnsortedList()...)
846849
}
847850
}
848851
}
@@ -853,14 +856,7 @@ func getOverriddenAndMergedTargetsMessageForGateway(
853856
SectionName: *sectionName,
854857
}
855858
if routeSet, ok := gatewayPolicyMergedMap.Routes[listenerKey]; ok {
856-
mergedRoutes = routeSet.UnsortedList()
857-
}
858-
gwKey := NamespacedNameWithSection{
859-
NamespacedName: gwNN,
860-
SectionName: "",
861-
}
862-
if routeSet, ok := gatewayPolicyMergedMap.Routes[gwKey]; ok {
863-
mergedRoutes = routeSet.UnsortedList()
859+
mergedRouteSet.Insert(routeSet.UnsortedList()...)
864860
}
865861
}
866862
}
@@ -879,7 +875,7 @@ func getOverriddenAndMergedTargetsMessageForGateway(
879875
SectionName: gwapiv1.SectionName(listener),
880876
}
881877
if routeSet, ok := gatewayRouteMap.Routes[listenerKey]; ok {
882-
overrideRoutes = append(overrideRoutes, routeSet.UnsortedList()...)
878+
overrideRouteSet.Insert(routeSet.UnsortedList()...)
883879
}
884880
}
885881
}
@@ -890,21 +886,20 @@ func getOverriddenAndMergedTargetsMessageForGateway(
890886
SectionName: *sectionName,
891887
}
892888
if routeSet, ok := gatewayRouteMap.Routes[listenerKey]; ok {
893-
overrideRoutes = routeSet.UnsortedList()
889+
overrideRouteSet.Insert(routeSet.UnsortedList()...)
894890
}
895891
gwKey := NamespacedNameWithSection{
896892
NamespacedName: gwNN,
897893
SectionName: "",
898894
}
899895
if routeSet, ok := gatewayRouteMap.Routes[gwKey]; ok {
900-
overrideRoutes = append(overrideRoutes, routeSet.UnsortedList()...)
896+
overrideRouteSet.Insert(routeSet.UnsortedList()...)
901897
}
902898
}
903899
}
904900

901+
mergedRoutes = mergedRouteSet.UnsortedList()
905902
// Exclude merged routes from overridden routes
906-
mergedRouteSet := sets.New(mergedRoutes...)
907-
overrideRouteSet := sets.New(overrideRoutes...)
908903
overrideRoutes = overrideRouteSet.Difference(mergedRouteSet).UnsortedList()
909904

910905
if len(overrideListeners) > 0 {

internal/gatewayapi/testdata/backendtrafficpolicy-strategic-merge-section.in.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,22 @@ httpRoutes:
6060
backendRefs:
6161
- name: service-1
6262
port: 8080
63+
- apiVersion: gateway.networking.k8s.io/v1
64+
kind: HTTPRoute
65+
metadata:
66+
namespace: default
67+
name: httproute-2
68+
spec:
69+
parentRefs:
70+
- namespace: envoy-gateway
71+
name: gateway-1
72+
rules:
73+
- matches:
74+
- path:
75+
value: "/foo"
76+
backendRefs:
77+
- name: service-1
78+
port: 8080
6379
backendTrafficPolicies:
6480
- apiVersion: gateway.envoyproxy.io/v1alpha1
6581
kind: BackendTrafficPolicy
@@ -125,6 +141,19 @@ backendTrafficPolicies:
125141
sectionName: rule-2
126142
connection:
127143
bufferLimit: 200M
144+
- apiVersion: gateway.envoyproxy.io/v1alpha1
145+
kind: BackendTrafficPolicy
146+
metadata:
147+
namespace: default
148+
name: merged-policy-for-httproute-2
149+
spec:
150+
targetRef:
151+
group: gateway.networking.k8s.io
152+
kind: HTTPRoute
153+
name: httproute-2
154+
mergeType: StrategicMerge
155+
httpUpgrade:
156+
- type: "spdy/3.1"
128157
- apiVersion: gateway.envoyproxy.io/v1alpha1
129158
kind: BackendTrafficPolicy
130159
metadata:

internal/gatewayapi/testdata/backendtrafficpolicy-strategic-merge-section.out.yaml

Lines changed: 166 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,59 @@ backendTrafficPolicies:
7171
status: "True"
7272
type: Overridden
7373
controllerName: gateway.envoyproxy.io/gatewayclass-controller
74+
- apiVersion: gateway.envoyproxy.io/v1alpha1
75+
kind: BackendTrafficPolicy
76+
metadata:
77+
name: merged-policy-for-httproute-2
78+
namespace: default
79+
spec:
80+
httpUpgrade:
81+
- type: spdy/3.1
82+
mergeType: StrategicMerge
83+
targetRef:
84+
group: gateway.networking.k8s.io
85+
kind: HTTPRoute
86+
name: httproute-2
87+
status:
88+
ancestors:
89+
- ancestorRef:
90+
group: gateway.networking.k8s.io
91+
kind: Gateway
92+
name: gateway-1
93+
namespace: envoy-gateway
94+
sectionName: listener-1
95+
conditions:
96+
- lastTransitionTime: null
97+
message: Merged with policy envoy-gateway/policy-for-gateway-1
98+
reason: Merged
99+
status: "True"
100+
type: Merged
101+
controllerName: gateway.envoyproxy.io/gatewayclass-controller
102+
- ancestorRef:
103+
group: gateway.networking.k8s.io
104+
kind: Gateway
105+
name: gateway-1
106+
namespace: envoy-gateway
107+
sectionName: listener-2
108+
conditions:
109+
- lastTransitionTime: null
110+
message: Merged with policy envoy-gateway/policy-for-gateway-1-listener-2
111+
reason: Merged
112+
status: "True"
113+
type: Merged
114+
controllerName: gateway.envoyproxy.io/gatewayclass-controller
115+
- ancestorRef:
116+
group: gateway.networking.k8s.io
117+
kind: Gateway
118+
name: gateway-1
119+
namespace: envoy-gateway
120+
conditions:
121+
- lastTransitionTime: null
122+
message: Policy has been accepted.
123+
reason: Accepted
124+
status: "True"
125+
type: Accepted
126+
controllerName: gateway.envoyproxy.io/gatewayclass-controller
74127
- apiVersion: gateway.envoyproxy.io/v1alpha1
75128
kind: BackendTrafficPolicy
76129
metadata:
@@ -137,7 +190,7 @@ backendTrafficPolicies:
137190
type: Accepted
138191
- lastTransitionTime: null
139192
message: 'This policy is being merged by other backendTrafficPolicies for
140-
these routes: [default/grpcroute-1]'
193+
these routes: [default/grpcroute-1 default/httproute-2]'
141194
reason: Merged
142195
status: "True"
143196
type: Merged
@@ -173,7 +226,7 @@ backendTrafficPolicies:
173226
type: Accepted
174227
- lastTransitionTime: null
175228
message: 'This policy is being merged by other backendTrafficPolicies for
176-
these routes: [default/grpcroute-1 default/httproute-1]'
229+
these routes: [default/grpcroute-1 default/httproute-1 default/httproute-2]'
177230
reason: Merged
178231
status: "True"
179232
type: Merged
@@ -207,7 +260,7 @@ gateways:
207260
protocol: HTTP
208261
status:
209262
listeners:
210-
- attachedRoutes: 1
263+
- attachedRoutes: 2
211264
conditions:
212265
- lastTransitionTime: null
213266
message: Sending translated listener configuration to the data plane
@@ -230,7 +283,7 @@ gateways:
230283
kind: HTTPRoute
231284
- group: gateway.networking.k8s.io
232285
kind: GRPCRoute
233-
- attachedRoutes: 1
286+
- attachedRoutes: 2
234287
conditions:
235288
- lastTransitionTime: null
236289
message: Sending translated listener configuration to the data plane
@@ -330,6 +383,39 @@ httpRoutes:
330383
name: gateway-1
331384
namespace: envoy-gateway
332385
sectionName: listener-1
386+
- apiVersion: gateway.networking.k8s.io/v1
387+
kind: HTTPRoute
388+
metadata:
389+
name: httproute-2
390+
namespace: default
391+
spec:
392+
parentRefs:
393+
- name: gateway-1
394+
namespace: envoy-gateway
395+
rules:
396+
- backendRefs:
397+
- name: service-1
398+
port: 8080
399+
matches:
400+
- path:
401+
value: /foo
402+
status:
403+
parents:
404+
- conditions:
405+
- lastTransitionTime: null
406+
message: Route is accepted
407+
reason: Accepted
408+
status: "True"
409+
type: Accepted
410+
- lastTransitionTime: null
411+
message: Resolved all the Object references for the Route
412+
reason: ResolvedRefs
413+
status: "True"
414+
type: ResolvedRefs
415+
controllerName: gateway.envoyproxy.io/gatewayclass-controller
416+
parentRef:
417+
name: gateway-1
418+
namespace: envoy-gateway
333419
infraIR:
334420
envoy-gateway/gateway-1:
335421
proxy:
@@ -474,6 +560,44 @@ xdsIR:
474560
traffic:
475561
backendConnection:
476562
bufferLimit: 200000000
563+
- destination:
564+
metadata:
565+
kind: HTTPRoute
566+
name: httproute-2
567+
namespace: default
568+
name: httproute/default/httproute-2/rule/0
569+
settings:
570+
- addressType: IP
571+
endpoints:
572+
- host: 7.7.7.7
573+
port: 8080
574+
metadata:
575+
name: service-1
576+
namespace: default
577+
sectionName: "8080"
578+
name: httproute/default/httproute-2/rule/0/backend/0
579+
protocol: HTTP
580+
weight: 1
581+
hostname: '*'
582+
isHTTP2: false
583+
metadata:
584+
kind: HTTPRoute
585+
name: httproute-2
586+
namespace: default
587+
name: httproute/default/httproute-2/rule/0/match/0/*
588+
pathMatch:
589+
distinct: false
590+
name: ""
591+
prefix: /foo
592+
traffic:
593+
httpUpgrade:
594+
- type: spdy/3.1
595+
timeout:
596+
http:
597+
connectionIdleTimeout: 16s
598+
maxConnectionDuration: 17s
599+
tcp:
600+
connectTimeout: 15s
477601
- address: 0.0.0.0
478602
externalPort: 8082
479603
hostnames:
@@ -490,6 +614,44 @@ xdsIR:
490614
mergeSlashes: true
491615
port: 8082
492616
routes:
617+
- destination:
618+
metadata:
619+
kind: HTTPRoute
620+
name: httproute-2
621+
namespace: default
622+
name: httproute/default/httproute-2/rule/0
623+
settings:
624+
- addressType: IP
625+
endpoints:
626+
- host: 7.7.7.7
627+
port: 8080
628+
metadata:
629+
name: service-1
630+
namespace: default
631+
sectionName: "8080"
632+
name: httproute/default/httproute-2/rule/0/backend/0
633+
protocol: HTTP
634+
weight: 1
635+
hostname: '*'
636+
isHTTP2: false
637+
metadata:
638+
kind: HTTPRoute
639+
name: httproute-2
640+
namespace: default
641+
name: httproute/default/httproute-2/rule/0/match/0/*
642+
pathMatch:
643+
distinct: false
644+
name: ""
645+
prefix: /foo
646+
traffic:
647+
httpUpgrade:
648+
- type: spdy/3.1
649+
timeout:
650+
http:
651+
connectionIdleTimeout: 26s
652+
maxConnectionDuration: 27s
653+
tcp:
654+
connectTimeout: 25s
493655
- destination:
494656
metadata:
495657
kind: GRPCRoute

0 commit comments

Comments
 (0)