fix: upgrade-k8s use internal IP first, external IP fallback

Currently, upgrade-k8s adds both node internal and external IPs.
This commit uses the internal IP if available; external IP is
only used as a fallback.

Signed-off-by: Alex Lubbock <code@alexlubbock.com>
Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
This commit is contained in:
Alex Lubbock 2023-05-31 00:07:06 +01:00 committed by Andrey Smirnov
parent 3c64a5ffba
commit ecce29dee9
No known key found for this signature in database
GPG Key ID: 7B26396447AB6DFD

View File

@ -154,7 +154,7 @@ func (h *Client) NodeIPs(ctx context.Context, machineType machine.Type) (addrs [
for _, node := range resp.Items {
_, labelControlPlane := node.Labels[constants.LabelNodeRoleControlPlane]
var skip bool
var skip, foundInternalIP bool
switch machineType {
case machine.TypeInit, machine.TypeControlPlane:
@ -175,17 +175,20 @@ func (h *Client) NodeIPs(ctx context.Context, machineType machine.Type) (addrs [
for _, nodeAddress := range node.Status.Addresses {
if nodeAddress.Type == corev1.NodeInternalIP {
addrs = append(addrs, nodeAddress.Address)
foundInternalIP = true
break
}
}
// no internal IP, fallback to external IP
for _, nodeAddress := range node.Status.Addresses {
if nodeAddress.Type == corev1.NodeExternalIP {
addrs = append(addrs, nodeAddress.Address)
if !foundInternalIP {
// no internal IP, fallback to external IP
for _, nodeAddress := range node.Status.Addresses {
if nodeAddress.Type == corev1.NodeExternalIP {
addrs = append(addrs, nodeAddress.Address)
break
break
}
}
}
}