Skip to content

Commit

Permalink
Change priority order for getting node IPs
Browse files Browse the repository at this point in the history
Internal IP being the first.
  • Loading branch information
kokhang committed Sep 23, 2016
1 parent 3c5e6cf commit ca7731e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Service-loadbalancer support for L4 is very limited. The binding-port needs to b

### Software Loadbalancer using keepalived and nginx

1. First we need to create the loadbalancer controller.
1. First we need to create the loadbalancer controller. Make sure you provide the VIP allocation range. They must be reachable from outside. (Usually they are VIPs on the same subnet as the node network.)
```
$ kubectl create -f examples/kube-loadbalancer-rc.yaml
```
Expand Down
2 changes: 1 addition & 1 deletion loadbalancer-daemon/controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func getNodeInterface(kubeClient *client.Client) string {
}
iface := interfaceByIP(*nodeIP)
if iface == "" {
glog.Fatalf("Cannot find interface for IP: %v", nodeIP)
glog.Fatalf("Cannot find interface for IP: %v", *nodeIP)
}
return iface
}
10 changes: 6 additions & 4 deletions loadbalancer/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,24 +127,26 @@ func MapKeys(m map[string]string) []string {
}

// GetNodeHostIP returns the provided node's IP, based on the priority:
// 1. NodeExternalIP
// 1. NodeInternalIP
// 2. NodeLegacyHostIP
// 3. NodeInternalIP
// 3. NodeExternalIP

func GetNodeHostIP(node api.Node) (*string, error) {
addresses := node.Status.Addresses
addressMap := make(map[api.NodeAddressType][]api.NodeAddress)
for i := range addresses {
addressMap[addresses[i].Type] = append(addressMap[addresses[i].Type], addresses[i])
}
if addresses, ok := addressMap[api.NodeExternalIP]; ok {
if addresses, ok := addressMap[api.NodeInternalIP]; ok {
return &addresses[0].Address, nil
}
if addresses, ok := addressMap[api.NodeLegacyHostIP]; ok {
return &addresses[0].Address, nil
}
if addresses, ok := addressMap[api.NodeInternalIP]; ok {
if addresses, ok := addressMap[api.NodeExternalIP]; ok {
return &addresses[0].Address, nil
}

return nil, fmt.Errorf("Host IP unknown; known addresses: %v", addresses)
}

Expand Down

0 comments on commit ca7731e

Please sign in to comment.