diff --git a/internal/gatewayapi/route.go b/internal/gatewayapi/route.go index 7bf2cdd9c57..bbee3f7d09a 100644 --- a/internal/gatewayapi/route.go +++ b/internal/gatewayapi/route.go @@ -2057,24 +2057,23 @@ func getIREndpointsFromEndpointSlice(endpointSlice *discoveryv1.EndpointSlice, p continue } conditions := endpoint.Conditions + // Unknown Serving/Terminating (nil) should fall-back to Ready, see https://pkg.go.dev/k8s.io/api/discovery/v1#EndpointConditions + // So drain the endpoint if: + // 1. Both `Terminating` and `Serving` are != null, and either `Terminating=true` or `Serving=false` + // 2. Or `Ready=false` + var draining bool if conditions.Serving != nil && conditions.Terminating != nil { - // Check if the endpoint is serving - if !*conditions.Serving { - continue - } - // Drain the endpoint if it is being terminated - draining := *conditions.Terminating - for _, address := range endpoint.Addresses { - ep := ir.NewDestEndpoint(nil, address, uint32(*endpointPort.Port), draining, endpoint.Zone) - endpoints = append(endpoints, ep) - } - } else if conditions.Ready == nil || *conditions.Ready { - for _, address := range endpoint.Addresses { - ep := ir.NewDestEndpoint(nil, address, uint32(*endpointPort.Port), false, endpoint.Zone) - endpoints = append(endpoints, ep) - } + draining = *conditions.Terminating || !*conditions.Serving + } else { + draining = conditions.Ready != nil && !*conditions.Ready + } + + for _, address := range endpoint.Addresses { + ep := ir.NewDestEndpoint(nil, address, uint32(*endpointPort.Port), draining, endpoint.Zone) + endpoints = append(endpoints, ep) } + } } diff --git a/internal/gatewayapi/route_test.go b/internal/gatewayapi/route_test.go index 31de02fd136..e402cfad1fc 100644 --- a/internal/gatewayapi/route_test.go +++ b/internal/gatewayapi/route_test.go @@ -176,7 +176,7 @@ func TestGetIREndpointsFromEndpointSlices(t *testing.T) { expectedAddrType: ir.MIXED, }, { - name: "Keep serving and terminating as draining", + name: "Keep non-serving or terminating as draining", endpointSlices: []*discoveryv1.EndpointSlice{ { ObjectMeta: metav1.ObjectMeta{Name: "slice1"}, @@ -201,6 +201,8 @@ func TestGetIREndpointsFromEndpointSlices(t *testing.T) { portProtocol: corev1.ProtocolTCP, expectedEndpoints: []*ir.DestinationEndpoint{ {Host: "192.0.2.1", Port: 80, Draining: true}, + {Host: "192.0.2.2", Port: 80, Draining: true}, + {Host: "192.0.2.3", Port: 80, Draining: true}, }, expectedAddrType: ir.IP, },