in projects/k8s-hybrid-neg-controller/pkg/reconciler/endpointslice.go [257:286]
func (r *endpointSliceReconciler) mapServicePortsToEndpointsByZone(logger logr.Logger, servicePorts []corev1.ServicePort, zones []string, endpointSliceList discoveryv1.EndpointSliceList) neg.ServiceEndpoints {
servicePortsToEndpointsByZone := initializeServicePortNameToEndpointsByZoneMap(servicePorts, zones)
for _, endpointSlice := range endpointSliceList.Items {
// The endpoint port may be different to the service port for headful Services.
for _, endpointSlicePort := range endpointSlice.Ports {
if endpointSlicePort.Port == nil || *endpointSlicePort.Port == 0 {
logger.V(2).Info("Skipping EndpointSlice port without Port value", "endpointSlice", endpointSlice)
continue
}
var servicePortName string // empty string is a valid port name if there's only one service port
if endpointSlicePort.Name != nil {
servicePortName = *endpointSlicePort.Name
}
logger.V(4).Info("Number of endpoints for port", "endpointsSize", len(endpointSlice.Endpoints), "port", *endpointSlicePort.Port, "portName", servicePortName)
for _, endpoint := range endpointSlice.Endpoints {
if endpoint.Conditions.Ready == nil || !*endpoint.Conditions.Ready {
continue
}
zone := r.mapZone(logger, endpoint)
for _, address := range endpoint.Addresses {
servicePortsToEndpointsByZone[servicePortName][zone].Put(&computepb.NetworkEndpoint{
IpAddress: proto.String(address),
Port: endpointSlicePort.Port,
})
}
}
}
}
return servicePortsToEndpointsByZone
}