@@ -17,6 +17,7 @@ import (
1717 "github.com/google/cel-go/cel"
1818 corev1 "k8s.io/api/core/v1"
1919 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20+ "k8s.io/apimachinery/pkg/types"
2021 utilerrors "k8s.io/apimachinery/pkg/util/errors"
2122 "k8s.io/apimachinery/pkg/util/sets"
2223 "k8s.io/utils/ptr"
@@ -334,7 +335,7 @@ func (t *Translator) ProcessListeners(gateways []*GatewayContext, xdsIR resource
334335 }
335336 t .processProxyReadyListener (xdsIR [irKey ], gateway .envoyProxy )
336337 t .processProxyObservability (gateway , xdsIR [irKey ], infraIR [irKey ].Proxy , resources )
337-
338+ gatewayAttachedListenerSets := sets . New [ string ]()
338339 for _ , listener := range gateway .listeners {
339340 // Finalize listener conditions and check readiness.
340341 t .validateListenerConditions (listener )
@@ -348,6 +349,13 @@ func (t *Translator) ProcessListeners(gateways []*GatewayContext, xdsIR resource
348349 continue
349350 }
350351
352+ if listener .isFromListenerSet () {
353+ gatewayAttachedListenerSets .Insert (types.NamespacedName {
354+ Namespace : listener .listenerSet .Namespace ,
355+ Name : listener .listenerSet .Name ,
356+ }.String ())
357+ }
358+
351359 address := netutils .IPv4ListenerAddress
352360 ipFamily := getEnvoyIPFamily (gateway .envoyProxy )
353361 if ipFamily != nil && (* ipFamily == egv1a1 .IPv6 || * ipFamily == egv1a1 .DualStack ) {
@@ -427,11 +435,35 @@ func (t *Translator) ProcessListeners(gateways []*GatewayContext, xdsIR resource
427435 foundPorts [irKey ] = append (foundPorts [irKey ], servicePort )
428436 }
429437 }
438+ gateway .IncreaseAttachedListenerSets (uint32 (len (gatewayAttachedListenerSets )))
430439 }
431440
432441 t .checkOverlappingTLSConfig (gateways )
433442}
434443
444+ // isListenerReady returns true if the listener is ready (Accepted=True and Programmed=True or no conditions yet).
445+ // A listener is not ready if it has Accepted=False or Programmed=False.
446+ func isListenerReady (listener * ListenerContext ) bool {
447+ conditions := listener .GetConditions ()
448+
449+ // No conditions yet means it will be set to ready during validation.
450+ if len (conditions ) == 0 {
451+ return true
452+ }
453+
454+ // Check if Accepted=False or Programmed=False exists.
455+ for _ , cond := range conditions {
456+ if cond .Type == string (gwapiv1 .ListenerConditionAccepted ) && cond .Status == metav1 .ConditionFalse {
457+ return false
458+ }
459+ if cond .Type == string (gwapiv1 .ListenerConditionProgrammed ) && cond .Status == metav1 .ConditionFalse {
460+ return false
461+ }
462+ }
463+
464+ return true
465+ }
466+
435467// checkOverlappingTLSConfig checks for overlapping hostnames and certificates between listeners and sets
436468// the `OverlappingTLSConfig` condition if there are overlapping hostnames or certificates.
437469func (t * Translator ) checkOverlappingTLSConfig (gateways []* GatewayContext ) {
@@ -440,7 +472,7 @@ func (t *Translator) checkOverlappingTLSConfig(gateways []*GatewayContext) {
440472 httpsListeners := []* ListenerContext {}
441473 for _ , gateway := range gateways {
442474 for _ , listener := range gateway .listeners {
443- if listener .Protocol == gwapiv1 .HTTPSProtocolType {
475+ if listener .Protocol == gwapiv1 .HTTPSProtocolType && isListenerReady ( listener ) {
444476 httpsListeners = append (httpsListeners , listener )
445477 }
446478 }
@@ -455,7 +487,7 @@ func (t *Translator) checkOverlappingTLSConfig(gateways []*GatewayContext) {
455487 for _ , gateway := range gateways {
456488 httpsListeners := []* ListenerContext {}
457489 for _ , listener := range gateway .listeners {
458- if listener .Protocol == gwapiv1 .HTTPSProtocolType {
490+ if listener .Protocol == gwapiv1 .HTTPSProtocolType && isListenerReady ( listener ) {
459491 httpsListeners = append (httpsListeners , listener )
460492 }
461493 }
0 commit comments