fix(kube-peers): Add support for ExternalIP addresses

Why:
* In some environments Nodes have an ExternalIP but no InternalIP

This change addresses the need by:
* Falling back to ExternalIP addresses if there isn't an InternalIP for a node
This commit is contained in:
Mike Bryant committed 2017-04-27 13:56:23 +01:00
1 parent 402fe094f4
commit e78be1fc35
1 file changed
+11 -1
+11 -1
View File
@@ -35,11 +35,21 @@ func getKubePeers() ([]string, error) {
}
addresses := make([]string, 0, len(nodeList.Items))
for _, peer := range nodeList.Items {
var internalIP, externalIP string
for _, addr := range peer.Status.Addresses {
if addr.Type == "InternalIP" {
addresses = append(addresses, addr.Address)
internalIP = addr.Address
} else if addr.Type == "ExternalIP" {
externalIP = addr.Address
}
}
// Fallback for cases where a Node has an ExternalIP but no InternalIP
if internalIP != "" {
addresses = append(addresses, internalIP)
} else if externalIP != "" {
addresses = append(addresses, externalIP)
}
}
return addresses, nil
}