Skip to content

Commit a93a2c4

Browse files
committed
refactor listener.IsReady()
Signed-off-by: zirain <zirain2009@gmail.com>
1 parent 04376f8 commit a93a2c4

2 files changed

Lines changed: 14 additions & 28 deletions

File tree

internal/gatewayapi/contexts.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,22 @@ func (l *ListenerContext) IsReady() bool {
274274
conditions = l.gateway.Status.Listeners[l.listenerStatusIdx].Conditions
275275
}
276276

277+
// No conditions yet means it will be set to ready during validation.
278+
if len(conditions) == 0 {
279+
return true
280+
}
281+
282+
// Check if Accepted=False or Programmed=False exists.
277283
for _, cond := range conditions {
278-
if cond.Type == string(gwapiv1.ListenerConditionProgrammed) && cond.Status == metav1.ConditionTrue {
279-
return true
284+
if cond.Type == string(gwapiv1.ListenerConditionAccepted) && cond.Status == metav1.ConditionFalse {
285+
return false
286+
}
287+
if cond.Type == string(gwapiv1.ListenerConditionProgrammed) && cond.Status == metav1.ConditionFalse {
288+
return false
280289
}
281290
}
282291

283-
return false
292+
return true
284293
}
285294

286295
func (l *ListenerContext) GetNamespace() string {

internal/gatewayapi/listener.go

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

414-
// isListenerReady returns true if the listener is ready (Accepted=True and Programmed=True or no conditions yet).
415-
// A listener is not ready if it has Accepted=False or Programmed=False.
416-
func isListenerReady(listener *ListenerContext) bool {
417-
conditions := listener.GetConditions()
418-
419-
// No conditions yet means it will be set to ready during validation.
420-
if len(conditions) == 0 {
421-
return true
422-
}
423-
424-
// Check if Accepted=False or Programmed=False exists.
425-
for _, cond := range conditions {
426-
if cond.Type == string(gwapiv1.ListenerConditionAccepted) && cond.Status == metav1.ConditionFalse {
427-
return false
428-
}
429-
if cond.Type == string(gwapiv1.ListenerConditionProgrammed) && cond.Status == metav1.ConditionFalse {
430-
return false
431-
}
432-
}
433-
434-
return true
435-
}
436-
437414
// checkOverlappingTLSConfig checks for overlapping hostnames and certificates between listeners and sets
438415
// the `OverlappingTLSConfig` condition if there are overlapping hostnames or certificates.
439416
func (t *Translator) checkOverlappingTLSConfig(gateways []*GatewayContext) {
@@ -442,7 +419,7 @@ func (t *Translator) checkOverlappingTLSConfig(gateways []*GatewayContext) {
442419
httpsListeners := []*ListenerContext{}
443420
for _, gateway := range gateways {
444421
for _, listener := range gateway.listeners {
445-
if listener.Protocol == gwapiv1.HTTPSProtocolType && isListenerReady(listener) {
422+
if listener.Protocol == gwapiv1.HTTPSProtocolType && listener.IsReady() {
446423
httpsListeners = append(httpsListeners, listener)
447424
}
448425
}
@@ -457,7 +434,7 @@ func (t *Translator) checkOverlappingTLSConfig(gateways []*GatewayContext) {
457434
for _, gateway := range gateways {
458435
httpsListeners := []*ListenerContext{}
459436
for _, listener := range gateway.listeners {
460-
if listener.Protocol == gwapiv1.HTTPSProtocolType && isListenerReady(listener) {
437+
if listener.Protocol == gwapiv1.HTTPSProtocolType && listener.IsReady() {
461438
httpsListeners = append(httpsListeners, listener)
462439
}
463440
}

0 commit comments

Comments
 (0)