mirror of
https://git.vectorsigma.ru/public/k3s.git
synced 2026-07-29 11:39:41 +00:00
refactor tunnel.go and controller.go, remove duplicated lines. Signed-off-by: Xiao Deshi <xiaods@gmail.com>
29 lines
545 B
Go
29 lines
545 B
Go
package util
|
|
|
|
import (
|
|
"net"
|
|
"strconv"
|
|
|
|
v1 "k8s.io/api/core/v1"
|
|
)
|
|
|
|
func GetAddresses(endpoint *v1.Endpoints) []string {
|
|
serverAddresses := []string{}
|
|
if endpoint == nil {
|
|
return serverAddresses
|
|
}
|
|
for _, subset := range endpoint.Subsets {
|
|
var port string
|
|
if len(subset.Ports) > 0 {
|
|
port = strconv.Itoa(int(subset.Ports[0].Port))
|
|
}
|
|
if port == "" {
|
|
port = "443"
|
|
}
|
|
for _, address := range subset.Addresses {
|
|
serverAddresses = append(serverAddresses, net.JoinHostPort(address.IP, port))
|
|
}
|
|
}
|
|
return serverAddresses
|
|
}
|