mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-11 06:02:18 +00:00
Part 2 of plural ports: make endpoints a struct
Includes conversions for v1b[12] and tests and fixups for call sites.
This commit is contained in:
@@ -149,23 +149,18 @@ func (lb *LoadBalancerRR) NextEndpoint(service string, srcAddr net.Addr) (string
|
||||
return endpoint, nil
|
||||
}
|
||||
|
||||
func isValidEndpoint(spec string) bool {
|
||||
_, port, err := net.SplitHostPort(spec)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
value, err := strconv.Atoi(port)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return value > 0
|
||||
func isValidEndpoint(ep *api.Endpoint) bool {
|
||||
return ep.IP != "" && ep.Port > 0
|
||||
}
|
||||
|
||||
func filterValidEndpoints(endpoints []string) []string {
|
||||
func filterValidEndpoints(endpoints []api.Endpoint) []string {
|
||||
// Convert Endpoint objects into strings for easier use later. Ignore
|
||||
// the protocol field - we'll get that from the Service objects.
|
||||
var result []string
|
||||
for _, spec := range endpoints {
|
||||
if isValidEndpoint(spec) {
|
||||
result = append(result, spec)
|
||||
for i := range endpoints {
|
||||
ep := &endpoints[i]
|
||||
if isValidEndpoint(ep) {
|
||||
result = append(result, net.JoinHostPort(ep.IP, strconv.Itoa(ep.Port)))
|
||||
}
|
||||
}
|
||||
return result
|
||||
|
Reference in New Issue
Block a user