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:
Tim Hockin
2015-02-18 19:54:15 -08:00
parent 34eaa0dbd6
commit ae0062d001
25 changed files with 461 additions and 142 deletions

View File

@@ -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