@@ -283,7 +283,7 @@ func (t *Translator) fillHTTPRoutePolicies(routes []*adctypes.Route, policies []
283283 }
284284}
285285
286- func (t * Translator ) translateEndpointSlice (portName * string , weight int , endpointSlices []discoveryv1.EndpointSlice ) adctypes.UpstreamNodes {
286+ func (t * Translator ) translateEndpointSlice (portName * string , weight int , endpointSlices []discoveryv1.EndpointSlice , endpointFilter func ( * discoveryv1. Endpoint ) bool ) adctypes.UpstreamNodes {
287287 var nodes adctypes.UpstreamNodes
288288 if len (endpointSlices ) == 0 {
289289 return nodes
@@ -294,6 +294,9 @@ func (t *Translator) translateEndpointSlice(portName *string, weight int, endpoi
294294 continue
295295 }
296296 for _ , endpoint := range endpointSlice .Endpoints {
297+ if endpointFilter != nil && ! endpointFilter (& endpoint ) {
298+ continue
299+ }
297300 for _ , addr := range endpoint .Addresses {
298301 node := adctypes.UpstreamNode {
299302 Host : addr ,
@@ -312,11 +315,19 @@ func (t *Translator) translateEndpointSlice(portName *string, weight int, endpoi
312315 return nodes
313316}
314317
315- func (t * Translator ) TranslateBackendRef (tctx * provider.TranslateContext , ref gatewayv1.BackendRef ) (adctypes.UpstreamNodes , error ) {
316- return t .translateBackendRef (tctx , ref )
318+ func DefaultEndpointFilter (endpoint * discoveryv1.Endpoint ) bool {
319+ if endpoint .Conditions .Ready != nil && ! * endpoint .Conditions .Ready {
320+ log .Debugw ("skip not ready endpoint" , zap .Any ("endpoint" , endpoint ))
321+ return false
322+ }
323+ return true
324+ }
325+
326+ func (t * Translator ) TranslateBackendRefWithFilter (tctx * provider.TranslateContext , ref gatewayv1.BackendRef , endpointFilter func (* discoveryv1.Endpoint ) bool ) (adctypes.UpstreamNodes , error ) {
327+ return t .translateBackendRef (tctx , ref , endpointFilter )
317328}
318329
319- func (t * Translator ) translateBackendRef (tctx * provider.TranslateContext , ref gatewayv1.BackendRef ) (adctypes.UpstreamNodes , error ) {
330+ func (t * Translator ) translateBackendRef (tctx * provider.TranslateContext , ref gatewayv1.BackendRef , endpointFilter func ( * discoveryv1. Endpoint ) bool ) (adctypes.UpstreamNodes , error ) {
320331 if ref .Kind != nil && * ref .Kind != "Service" {
321332 return adctypes.UpstreamNodes {}, fmt .Errorf ("kind %s is not supported" , * ref .Kind )
322333 }
@@ -363,7 +374,7 @@ func (t *Translator) translateBackendRef(tctx *provider.TranslateContext, ref ga
363374 }
364375
365376 endpointSlices := tctx .EndpointSlices [key ]
366- return t .translateEndpointSlice (portName , weight , endpointSlices ), nil
377+ return t .translateEndpointSlice (portName , weight , endpointSlices , endpointFilter ), nil
367378}
368379
369380// calculateHTTPRoutePriority calculates the priority of the HTTP route.
@@ -475,7 +486,7 @@ func (t *Translator) TranslateHTTPRoute(tctx *provider.TranslateContext, httpRou
475486 namespace := gatewayv1 .Namespace (httpRoute .Namespace )
476487 backend .Namespace = & namespace
477488 }
478- upNodes , err := t .translateBackendRef (tctx , backend .BackendRef )
489+ upNodes , err := t .translateBackendRef (tctx , backend .BackendRef , DefaultEndpointFilter )
479490 if err != nil {
480491 backendErr = err
481492 continue
0 commit comments