feat: support topology aware hints (#9165)
* support topology aware hints Signed-off-by: tombokombo <tombo@sysart.tech> * add flag to enable topology and fixes Signed-off-by: tombokombo <tombo@sysart.tech> * update readme Signed-off-by: tombokombo <tombo@sysart.tech> * add e2e test Signed-off-by: tombokombo <tombo@sysart.tech> * isolate topology test Signed-off-by: tombokombo <tombo@sysart.tech> * gofmt fix Signed-off-by: tombokombo <tombo@sysart.tech> Signed-off-by: tombokombo <tombo@sysart.tech>
This commit is contained in:
parent
ada114315e
commit
5b2a9475dc
14 changed files with 564 additions and 18 deletions
|
|
@ -35,7 +35,7 @@ import (
|
|||
)
|
||||
|
||||
// getEndpoints returns a list of Endpoint structs for a given service/target port combination.
|
||||
func getEndpointsFromSlices(s *corev1.Service, port *corev1.ServicePort, proto corev1.Protocol,
|
||||
func getEndpointsFromSlices(s *corev1.Service, port *corev1.ServicePort, proto corev1.Protocol, zoneForHints string,
|
||||
getServiceEndpointsSlices func(string) ([]*discoveryv1.EndpointSlice, error)) []ingress.Endpoint {
|
||||
|
||||
upsServers := []ingress.Endpoint{}
|
||||
|
|
@ -49,6 +49,7 @@ func getEndpointsFromSlices(s *corev1.Service, port *corev1.ServicePort, proto c
|
|||
processedUpstreamServers := make(map[string]struct{})
|
||||
|
||||
svcKey := k8s.MetaNamespaceKey(s)
|
||||
var useTopologyHints bool
|
||||
|
||||
// ExternalName services
|
||||
if s.Spec.Type == corev1.ServiceTypeExternalName {
|
||||
|
|
@ -111,12 +112,38 @@ func getEndpointsFromSlices(s *corev1.Service, port *corev1.ServicePort, proto c
|
|||
ports = append(ports, targetPort)
|
||||
}
|
||||
}
|
||||
useTopologyHints = false
|
||||
if zoneForHints != emptyZone {
|
||||
useTopologyHints = true
|
||||
// check if all endpointslices has zone hints
|
||||
for _, ep := range eps.Endpoints {
|
||||
if ep.Hints == nil || len(ep.Hints.ForZones) == 0 {
|
||||
useTopologyHints = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if useTopologyHints {
|
||||
klog.V(3).Infof("All endpoint slices has zone hint, using zone %q for Service %q", zoneForHints, svcKey)
|
||||
}
|
||||
}
|
||||
|
||||
for _, ep := range eps.Endpoints {
|
||||
if !(*ep.Conditions.Ready) {
|
||||
continue
|
||||
}
|
||||
epHasZone := false
|
||||
if useTopologyHints {
|
||||
for _, epzone := range ep.Hints.ForZones {
|
||||
if epzone.Name == zoneForHints {
|
||||
epHasZone = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ep.Hints
|
||||
if useTopologyHints && !epHasZone {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, epPort := range ports {
|
||||
for _, epAddress := range ep.Addresses {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue