Skip to content

Commit e2197fe

Browse files
authored
Merge pull request #1200 from zhangzujian/fix-pinger
pinger: fix getting empty PodIPs
2 parents c970f88 + 727ea53 commit e2197fe

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

pkg/pinger/config.go

+24-8
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,32 @@ func ParseFlags() (*Configuration, error) {
136136
return nil, err
137137
}
138138

139-
name := os.Getenv("POD_NAME")
140-
pod, err := config.KubeClient.CoreV1().Pods("kube-system").Get(context.Background(), name, metav1.GetOptions{})
141-
if err != nil {
142-
klog.Errorf("failed to get self pod kube-system/%s: %v", name, err)
143-
return nil, err
139+
podName := os.Getenv("POD_NAME")
140+
for i := 0; i < 3; i++ {
141+
pod, err := config.KubeClient.CoreV1().Pods("kube-system").Get(context.Background(), podName, metav1.GetOptions{})
142+
if err != nil {
143+
klog.Errorf("failed to get self pod kube-system/%s: %v", podName, err)
144+
return nil, err
145+
}
146+
147+
if len(pod.Status.PodIPs) != 0 {
148+
config.PodProtocols = make([]string, len(pod.Status.PodIPs))
149+
for i, podIP := range pod.Status.PodIPs {
150+
config.PodProtocols[i] = util.CheckProtocol(podIP.IP)
151+
}
152+
break
153+
}
154+
155+
if pod.Status.ContainerStatuses[0].Ready {
156+
klog.Fatalf("failed to get IPs of Pod kube-system/%s", podName)
157+
}
158+
159+
klog.Infof("cannot get Pod IPs now, waiting Pod to be ready")
160+
time.Sleep(time.Second)
144161
}
145162

146-
config.PodProtocols = make([]string, len(pod.Status.PodIPs))
147-
for i, podIP := range pod.Status.PodIPs {
148-
config.PodProtocols[i] = util.CheckProtocol(podIP.IP)
163+
if len(config.PodProtocols) == 0 {
164+
klog.Fatalf("failed to get IPs of Pod kube-system/%s after 3 attempts", podName)
149165
}
150166

151167
klog.Infof("pinger config is %+v", config)

0 commit comments

Comments
 (0)