ServiceEndpointsByPort returns the cached instances by port if it exists.
(svc *Service, port int, labels labels.Instance)
| 2520 | |
| 2521 | // ServiceEndpointsByPort returns the cached instances by port if it exists. |
| 2522 | func (ps *PushContext) ServiceEndpointsByPort(svc *Service, port int, labels labels.Instance) []*IstioEndpoint { |
| 2523 | var out []*IstioEndpoint |
| 2524 | |
| 2525 | // For InferencePool services, return ALL endpoints regardless of port |
| 2526 | // because they may have different target ports but belong to the same cluster |
| 2527 | if svc.UseInferenceSemantics() { |
| 2528 | allPorts := ps.ServiceIndex.instancesByPort[svc.Key()] |
| 2529 | for _, instances := range allPorts { |
| 2530 | if len(labels) == 0 { |
| 2531 | out = append(out, instances...) |
| 2532 | continue |
| 2533 | } |
| 2534 | for _, instance := range instances { |
| 2535 | if labels.SubsetOf(instance.Labels) { |
| 2536 | out = append(out, instance) |
| 2537 | } |
| 2538 | } |
| 2539 | } |
| 2540 | return out |
| 2541 | } |
| 2542 | |
| 2543 | if instances, exists := ps.ServiceIndex.instancesByPort[svc.Key()][port]; exists { |
| 2544 | // Use cached version of instances by port when labels are empty. |
| 2545 | if len(labels) == 0 { |
| 2546 | return instances |
| 2547 | } |
| 2548 | // If there are labels, we will filter instances by pod labels. |
| 2549 | for _, instance := range instances { |
| 2550 | // check that one of the input labels is a subset of the labels |
| 2551 | if labels.SubsetOf(instance.Labels) { |
| 2552 | out = append(out, instance) |
| 2553 | } |
| 2554 | } |
| 2555 | } |
| 2556 | |
| 2557 | return out |
| 2558 | } |
| 2559 | |
| 2560 | // ServiceEndpoints returns the cached instances by svc if exists. |
| 2561 | func (ps *PushContext) ServiceEndpoints(svcKey string) map[int][]*IstioEndpoint { |