Skip to content

Commit 3c10b3b

Browse files
committed
fix
Signed-off-by: zirain <zirain2009@gmail.com>
1 parent 4973a42 commit 3c10b3b

8 files changed

Lines changed: 245 additions & 40 deletions

internal/gatewayapi/listener.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,29 @@ func (t *Translator) ProcessListeners(gateways []*GatewayContext, xdsIR resource
385385
t.checkOverlappingTLSConfig(gateways)
386386
}
387387

388+
// isListenerReady returns true if the listener is ready (Accepted=True and Programmed=True or no conditions yet).
389+
// A listener is not ready if it has Accepted=False or Programmed=False.
390+
func isListenerReady(listener *ListenerContext) bool {
391+
conditions := listener.GetConditions()
392+
393+
// No conditions yet means it will be set to ready during validation.
394+
if len(conditions) == 0 {
395+
return true
396+
}
397+
398+
// Check if Accepted=False or Programmed=False exists.
399+
for _, cond := range conditions {
400+
if cond.Type == string(gwapiv1.ListenerConditionAccepted) && cond.Status == metav1.ConditionFalse {
401+
return false
402+
}
403+
if cond.Type == string(gwapiv1.ListenerConditionProgrammed) && cond.Status == metav1.ConditionFalse {
404+
return false
405+
}
406+
}
407+
408+
return true
409+
}
410+
388411
// checkOverlappingTLSConfig checks for overlapping hostnames and certificates between listeners and sets
389412
// the `OverlappingTLSConfig` condition if there are overlapping hostnames or certificates.
390413
func (t *Translator) checkOverlappingTLSConfig(gateways []*GatewayContext) {
@@ -393,7 +416,7 @@ func (t *Translator) checkOverlappingTLSConfig(gateways []*GatewayContext) {
393416
httpsListeners := []*ListenerContext{}
394417
for _, gateway := range gateways {
395418
for _, listener := range gateway.listeners {
396-
if listener.Protocol == gwapiv1.HTTPSProtocolType {
419+
if listener.Protocol == gwapiv1.HTTPSProtocolType && isListenerReady(listener) {
397420
httpsListeners = append(httpsListeners, listener)
398421
}
399422
}
@@ -408,7 +431,7 @@ func (t *Translator) checkOverlappingTLSConfig(gateways []*GatewayContext) {
408431
for _, gateway := range gateways {
409432
httpsListeners := []*ListenerContext{}
410433
for _, listener := range gateway.listeners {
411-
if listener.Protocol == gwapiv1.HTTPSProtocolType {
434+
if listener.Protocol == gwapiv1.HTTPSProtocolType && isListenerReady(listener) {
412435
httpsListeners = append(httpsListeners, listener)
413436
}
414437
}

internal/gatewayapi/testdata/gateway-with-two-listeners-on-same-tcp-or-tls-port.out.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ gateways:
5050
status: "True"
5151
type: Conflicted
5252
- lastTransitionTime: null
53-
message: All listeners for a given port must use a unique hostname
53+
message: All listeners for a given port must use a compatible protocol
5454
reason: ProtocolConflict
5555
status: "False"
5656
type: Accepted

internal/gatewayapi/testdata/gateway-with-two-listeners-with-http-and-tlsroute-same-hostname-and-port.out.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ gateways:
5656
status: "True"
5757
type: Conflicted
5858
- lastTransitionTime: null
59-
message: All listeners for a given port must use a unique hostname
59+
message: All listeners for a given port must use a compatible protocol
6060
reason: ProtocolConflict
6161
status: "False"
6262
type: Accepted
6363
- lastTransitionTime: null
64-
message: All listeners for a given port must use a unique hostname
64+
message: All listeners for a given port must use a compatible protocol
6565
reason: ProtocolConflict
6666
status: "False"
6767
type: Programmed

internal/gatewayapi/testdata/gateway-with-two-listeners-with-same-port-and-incompatible-protocol.in.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,26 @@ gateways:
2121
allowedRoutes:
2222
namespaces:
2323
from: All
24+
- allowedRoutes:
25+
namespaces:
26+
from: All
27+
name: udp-8162
28+
port: 8162
29+
protocol: UDP
30+
# This listener(http-8162) is valid because HTTP + UDP are compatible protocols.
31+
- allowedRoutes:
32+
namespaces:
33+
from: All
34+
name: http-8162
35+
port: 8162
36+
protocol: HTTP
37+
# This listener(tcp-8162) is invalid because TCP is not compatible with HTTP.
38+
- allowedRoutes:
39+
namespaces:
40+
from: All
41+
name: tcp-8162
42+
port: 8162
43+
protocol: TCP
2444
httpRoutes:
2545
- apiVersion: gateway.networking.k8s.io/v1
2646
kind: HTTPRoute

internal/gatewayapi/testdata/gateway-with-two-listeners-with-same-port-and-incompatible-protocol.out.yaml

Lines changed: 156 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@ gateways:
2121
name: http-2
2222
port: 80
2323
protocol: HTTPS
24+
- allowedRoutes:
25+
namespaces:
26+
from: All
27+
name: udp-8162
28+
port: 8162
29+
protocol: UDP
30+
- allowedRoutes:
31+
namespaces:
32+
from: All
33+
name: http-8162
34+
port: 8162
35+
protocol: HTTP
36+
- allowedRoutes:
37+
namespaces:
38+
from: All
39+
name: tcp-8162
40+
port: 8162
41+
protocol: TCP
2442
status:
2543
listeners:
2644
- attachedRoutes: 1
@@ -54,7 +72,7 @@ gateways:
5472
status: "True"
5573
type: Conflicted
5674
- lastTransitionTime: null
57-
message: All listeners for a given port must use a unique hostname
75+
message: All listeners for a given port must use a compatible protocol
5876
reason: ProtocolConflict
5977
status: "False"
6078
type: Accepted
@@ -74,6 +92,76 @@ gateways:
7492
kind: HTTPRoute
7593
- group: gateway.networking.k8s.io
7694
kind: GRPCRoute
95+
- attachedRoutes: 0
96+
conditions:
97+
- lastTransitionTime: null
98+
message: Sending translated listener configuration to the data plane
99+
reason: Programmed
100+
status: "True"
101+
type: Programmed
102+
- lastTransitionTime: null
103+
message: Listener has been successfully translated
104+
reason: Accepted
105+
status: "True"
106+
type: Accepted
107+
- lastTransitionTime: null
108+
message: Listener references have been resolved
109+
reason: ResolvedRefs
110+
status: "True"
111+
type: ResolvedRefs
112+
name: udp-8162
113+
supportedKinds:
114+
- group: gateway.networking.k8s.io
115+
kind: UDPRoute
116+
- attachedRoutes: 1
117+
conditions:
118+
- lastTransitionTime: null
119+
message: Sending translated listener configuration to the data plane
120+
reason: Programmed
121+
status: "True"
122+
type: Programmed
123+
- lastTransitionTime: null
124+
message: Listener has been successfully translated
125+
reason: Accepted
126+
status: "True"
127+
type: Accepted
128+
- lastTransitionTime: null
129+
message: Listener references have been resolved
130+
reason: ResolvedRefs
131+
status: "True"
132+
type: ResolvedRefs
133+
name: http-8162
134+
supportedKinds:
135+
- group: gateway.networking.k8s.io
136+
kind: HTTPRoute
137+
- group: gateway.networking.k8s.io
138+
kind: GRPCRoute
139+
- attachedRoutes: 0
140+
conditions:
141+
- lastTransitionTime: null
142+
message: All listeners for a given port must use a compatible protocol
143+
reason: ProtocolConflict
144+
status: "True"
145+
type: Conflicted
146+
- lastTransitionTime: null
147+
message: All listeners for a given port must use a compatible protocol
148+
reason: ProtocolConflict
149+
status: "False"
150+
type: Accepted
151+
- lastTransitionTime: null
152+
message: All listeners for a given port must use a compatible protocol
153+
reason: ProtocolConflict
154+
status: "False"
155+
type: Programmed
156+
- lastTransitionTime: null
157+
message: Listener references have been resolved
158+
reason: ResolvedRefs
159+
status: "True"
160+
type: ResolvedRefs
161+
name: tcp-8162
162+
supportedKinds:
163+
- group: gateway.networking.k8s.io
164+
kind: TCPRoute
77165
httpRoutes:
78166
- apiVersion: gateway.networking.k8s.io/v1
79167
kind: HTTPRoute
@@ -118,6 +206,18 @@ infraIR:
118206
name: http-80
119207
protocol: HTTP
120208
servicePort: 80
209+
- name: envoy-gateway/gateway-1/udp-8162
210+
ports:
211+
- containerPort: 8162
212+
name: udp-8162
213+
protocol: UDP
214+
servicePort: 8162
215+
- name: envoy-gateway/gateway-1/http-8162
216+
ports:
217+
- containerPort: 8162
218+
name: http-8162
219+
protocol: HTTP
220+
servicePort: 8162
121221
metadata:
122222
labels:
123223
gateway.envoyproxy.io/owning-gateway-name: gateway-1
@@ -199,8 +299,63 @@ xdsIR:
199299
distinct: false
200300
name: ""
201301
prefix: /
302+
- address: 0.0.0.0
303+
externalPort: 8162
304+
hostnames:
305+
- '*'
306+
metadata:
307+
kind: Gateway
308+
name: gateway-1
309+
namespace: envoy-gateway
310+
sectionName: http-8162
311+
name: envoy-gateway/gateway-1/http-8162
312+
path:
313+
escapedSlashesAction: UnescapeAndRedirect
314+
mergeSlashes: true
315+
port: 8162
316+
routes:
317+
- destination:
318+
metadata:
319+
kind: HTTPRoute
320+
name: httproute-1
321+
namespace: default
322+
name: httproute/default/httproute-1/rule/0
323+
settings:
324+
- addressType: IP
325+
endpoints:
326+
- host: 7.7.7.7
327+
port: 8080
328+
metadata:
329+
kind: Service
330+
name: service-1
331+
namespace: default
332+
sectionName: "8080"
333+
name: httproute/default/httproute-1/rule/0/backend/0
334+
protocol: HTTP
335+
weight: 1
336+
hostname: '*'
337+
isHTTP2: false
338+
metadata:
339+
kind: HTTPRoute
340+
name: httproute-1
341+
namespace: default
342+
name: httproute/default/httproute-1/rule/0/match/0/*
343+
pathMatch:
344+
distinct: false
345+
name: ""
346+
prefix: /
202347
readyListener:
203348
address: 0.0.0.0
204349
ipFamily: IPv4
205350
path: /ready
206351
port: 19003
352+
udp:
353+
- address: 0.0.0.0
354+
externalPort: 8162
355+
metadata:
356+
kind: Gateway
357+
name: gateway-1
358+
namespace: envoy-gateway
359+
sectionName: udp-8162
360+
name: envoy-gateway/gateway-1/udp-8162
361+
port: 8162

internal/gatewayapi/testdata/gateway-with-two-listeners-with-same-port-http-tcp-protocol.out.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ gateways:
5353
status: "True"
5454
type: Conflicted
5555
- lastTransitionTime: null
56-
message: All listeners for a given port must use a unique hostname
56+
message: All listeners for a given port must use a compatible protocol
5757
reason: ProtocolConflict
5858
status: "False"
5959
type: Accepted
6060
- lastTransitionTime: null
61-
message: All listeners for a given port must use a unique hostname
61+
message: All listeners for a given port must use a compatible protocol
6262
reason: ProtocolConflict
6363
status: "False"
6464
type: Programmed

internal/gatewayapi/testdata/listenerset-protocol-conflict.out.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@ listenerSets:
174174
status: "True"
175175
type: Conflicted
176176
- lastTransitionTime: null
177-
message: All listeners for a given port must use a unique hostname
177+
message: All listeners for a given port must use a compatible protocol
178178
reason: ProtocolConflict
179179
status: "False"
180180
type: Accepted
181181
- lastTransitionTime: null
182-
message: All listeners for a given port must use a unique hostname
182+
message: All listeners for a given port must use a compatible protocol
183183
reason: ProtocolConflict
184184
status: "False"
185185
type: Programmed
@@ -259,12 +259,12 @@ listenerSets:
259259
status: "True"
260260
type: Conflicted
261261
- lastTransitionTime: null
262-
message: All listeners for a given port must use a unique hostname
262+
message: All listeners for a given port must use a compatible protocol
263263
reason: ProtocolConflict
264264
status: "False"
265265
type: Accepted
266266
- lastTransitionTime: null
267-
message: All listeners for a given port must use a unique hostname
267+
message: All listeners for a given port must use a compatible protocol
268268
reason: ProtocolConflict
269269
status: "False"
270270
type: Programmed
@@ -351,12 +351,12 @@ listenerSets:
351351
status: "True"
352352
type: Conflicted
353353
- lastTransitionTime: null
354-
message: All listeners for a given port must use a unique hostname
354+
message: All listeners for a given port must use a compatible protocol
355355
reason: ProtocolConflict
356356
status: "False"
357357
type: Accepted
358358
- lastTransitionTime: null
359-
message: All listeners for a given port must use a unique hostname
359+
message: All listeners for a given port must use a compatible protocol
360360
reason: ProtocolConflict
361361
status: "False"
362362
type: Programmed
@@ -408,12 +408,12 @@ listenerSets:
408408
status: "True"
409409
type: Conflicted
410410
- lastTransitionTime: null
411-
message: All listeners for a given port must use a unique hostname
411+
message: All listeners for a given port must use a compatible protocol
412412
reason: ProtocolConflict
413413
status: "False"
414414
type: Accepted
415415
- lastTransitionTime: null
416-
message: All listeners for a given port must use a unique hostname
416+
message: All listeners for a given port must use a compatible protocol
417417
reason: ProtocolConflict
418418
status: "False"
419419
type: Programmed

0 commit comments

Comments
 (0)