/
endpoint_utils.go
49 lines (43 loc) · 1.03 KB
/
endpoint_utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package helper
import (
v1 "k8s.io/api/core/v1"
discovery "k8s.io/api/discovery/v1"
"strings"
)
func LogEndpoints(eps *v1.Endpoints) string {
if eps == nil {
return "endpoints is nil"
}
var epAddrList []string
for _, subSet := range eps.Subsets {
for _, addr := range subSet.Addresses {
epAddrList = append(epAddrList, addr.IP)
}
}
return strings.Join(epAddrList, ",")
}
func LogEndpointSlice(es *discovery.EndpointSlice) string {
if es == nil {
return "endpointSlice is nil"
}
var epAddrList []string
for _, ep := range es.Endpoints {
epAddrList = append(epAddrList, ep.Addresses...)
}
return strings.Join(epAddrList, ",")
}
func LogEndpointSliceList(esList []discovery.EndpointSlice) string {
if esList == nil {
return "endpointSliceList is nil"
}
var epAddrList []string
for _, es := range esList {
for _, ep := range es.Endpoints {
if ep.Conditions.Ready != nil && !*ep.Conditions.Ready {
continue
}
epAddrList = append(epAddrList, ep.Addresses...)
}
}
return strings.Join(epAddrList, ",")
}