Skip to content

Commit

Permalink
Added condition to take only Ready pods for load balancing
Browse files Browse the repository at this point in the history
Signed-off-by: ajaychoudhary-hotstar <[email protected]>
  • Loading branch information
ajaychoudhary-hotstar committed Nov 8, 2024
1 parent 90cabf7 commit 61568c5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
24 changes: 13 additions & 11 deletions cmd/entrypoint/endpoint_routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,20 @@ func k8sEndpointSlicesToAmbex(endpointSlice *kates.EndpointSlice, svc *kates.Ser
}
}
}
for _, address := range endpoint.Addresses {
for pn := range portNames {
sep := "/"
if pn == "" {
sep = ""
if *endpoint.Conditions.Ready {
for _, address := range endpoint.Addresses {
for pn := range portNames {
sep := "/"
if pn == "" {
sep = ""
}
result = append(result, &ambex.Endpoint{
ClusterName: fmt.Sprintf("k8s/%s/%s%s%s", svc.Namespace, svc.Name, sep, pn),
Ip: address,
Port: uint32(*port.Port),
Protocol: string(*port.Protocol),
})
}
result = append(result, &ambex.Endpoint{
ClusterName: fmt.Sprintf("k8s/%s/%s%s%s", svc.Namespace, svc.Name, sep, pn),
Ip: address,
Port: uint32(*port.Port),
Protocol: string(*port.Protocol),
})
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/entrypoint/endpoint_routing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func TestEndpointRoutingMultiplePorts(t *testing.T) {
},
},
}))
endpoint, port, err := makeSliceEndpoint(8080, "1.2.3.4")
endpoint, port, err := makeSliceEndpoint("cleartext", 8080, "encrypted", 8443, "1.2.3.4")
require.NoError(t, err)
assert.NoError(t, f.Upsert(makeEndpointSlice("default", "foo", "foo", endpoint, port)))
f.Flush()
Expand Down Expand Up @@ -328,6 +328,11 @@ func makeSliceEndpoint(args ...interface{}) ([]kates.Endpoint, []kates.EndpointS
if IP != nil {
endpoints = append(endpoints, kates.Endpoint{
Addresses: []string{v},
Conditions: kates.EndpointConditions{
Ready: &[]bool{true}[0],
Serving: &[]bool{true}[0],
Terminating: &[]bool{false}[0],
},
})
} else {
portName = v // Assume it's a port name if not an IP address
Expand Down
1 change: 1 addition & 0 deletions pkg/kates/aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type EndpointPort = corev1.EndpointPort
type EndpointSlice = discoveryv1.EndpointSlice
type Endpoint = discoveryv1.Endpoint
type EndpointSlicePort = discoveryv1.EndpointPort
type EndpointConditions = discoveryv1.EndpointConditions

type Protocol = corev1.Protocol

Expand Down

0 comments on commit 61568c5

Please sign in to comment.