Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions internal/gatewayapi/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -1932,24 +1932,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)
}

}
}

Expand Down
4 changes: 3 additions & 1 deletion internal/gatewayapi/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -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,
},
Expand Down
Loading