MCPcopy
hub / github.com/istio/istio / getRemoteServiceAddresses

Function getRemoteServiceAddresses

pkg/test/framework/components/istio/util.go:76–152  ·  view source on GitHub ↗
(s *kube.Settings, cluster cluster.Cluster, ns, label, svcName string,
	port int,
)

Source from the content-addressed store, hash-verified

74}
75
76func getRemoteServiceAddresses(s *kube.Settings, cluster cluster.Cluster, ns, label, svcName string,
77 port int,
78) ([]any, bool, error) {
79 if !s.LoadBalancerSupported {
80 pods, err := cluster.PodsForSelector(context.TODO(), ns, label)
81 if err != nil {
82 return nil, false, err
83 }
84
85 names := make([]string, 0, len(pods.Items))
86 for _, p := range pods.Items {
87 names = append(names, p.Name)
88 }
89 scopes.Framework.Debugf("Querying remote service %s, pods:%v", svcName, names)
90 if len(pods.Items) == 0 {
91 return nil, false, fmt.Errorf("no remote service pod found")
92 }
93
94 scopes.Framework.Debugf("Found pod: %v", pods.Items[0].Name)
95 ip := pods.Items[0].Status.HostIP
96 if ip == "" {
97 return nil, false, fmt.Errorf("no Host IP available on the remote service node yet")
98 }
99
100 svc, err := cluster.Kube().CoreV1().Services(ns).Get(context.TODO(), svcName, metav1.GetOptions{})
101 if err != nil {
102 return nil, false, err
103 }
104
105 if len(svc.Spec.Ports) == 0 {
106 return nil, false, fmt.Errorf("no ports found in service: %s/%s", ns, svcName)
107 }
108
109 var nodePort int32
110 for _, svcPort := range svc.Spec.Ports {
111 if svcPort.Protocol == "TCP" && svcPort.Port == int32(port) {
112 nodePort = svcPort.NodePort
113 break
114 }
115 }
116 if nodePort == 0 {
117 return nil, false, fmt.Errorf("no port %d found in service: %s/%s", port, ns, svcName)
118 }
119
120 ipAddr, err := netip.ParseAddr(ip)
121 if err != nil {
122 return nil, false, err
123 }
124 return []any{netip.AddrPortFrom(ipAddr, uint16(nodePort))}, true, nil
125 }
126
127 // Otherwise, get the load balancer IP.
128 svc, err := cluster.Kube().CoreV1().Services(ns).Get(context.TODO(), svcName, metav1.GetOptions{})
129 if err != nil {
130 return nil, false, err
131 }
132
133 if len(svc.Status.LoadBalancer.Ingress) == 0 {

Callers 2

getAddressesInnerMethod · 0.85

Calls 6

DebugfMethod · 0.80
PodsForSelectorMethod · 0.65
ErrorfMethod · 0.65
GetMethod · 0.65
ServicesMethod · 0.65
KubeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…