Skip to content
This repository was archived by the owner on Sep 24, 2021. It is now read-only.

Commit aa5cee5

Browse files
authored
Merge pull request #165 from tvs/etcd-fallback-nil
Fall back to 127.0.0.1 in etcdctl command when pod has an unparseable IP
2 parents 67227bb + 96d7ffe commit aa5cee5

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pkg/upgrade/control_plane.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"encoding/json"
99
"fmt"
10+
"net"
1011
"reflect"
1112
"strconv"
1213
"strings"
@@ -1227,9 +1228,12 @@ func (u *ControlPlaneUpgrader) etcdctl(ctx context.Context, args ...string) (str
12271228
func (u *ControlPlaneUpgrader) etcdctlForPod(ctx context.Context, pod *v1.Pod, args ...string) (string, string, error) {
12281229
u.log.Info("Running etcdctl", "pod", pod.Name, "args", strings.Join(args, " "))
12291230

1230-
ip := pod.Status.PodIP
1231-
if ip == "" {
1232-
ip = "127.0.0.1"
1231+
// In certain scenarios, the PodIP might be "unset" (empty) or set to "<nil>"
1232+
// In the event that the PodIP is not parseable to a valid address, we can
1233+
// fall back to localhost.
1234+
ip := net.ParseIP(pod.Status.PodIP)
1235+
if ip == nil {
1236+
ip = net.IPv4(127, 0, 0, 1)
12331237
}
12341238
endpoint := fmt.Sprintf("https://%s:2379", ip)
12351239

0 commit comments

Comments
 (0)