Skip to content

Commit

Permalink
pinger: fix getting empty PodIPs
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian committed Dec 27, 2021
1 parent c970f88 commit 727ea53
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions pkg/pinger/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,32 @@ func ParseFlags() (*Configuration, error) {
return nil, err
}

name := os.Getenv("POD_NAME")
pod, err := config.KubeClient.CoreV1().Pods("kube-system").Get(context.Background(), name, metav1.GetOptions{})
if err != nil {
klog.Errorf("failed to get self pod kube-system/%s: %v", name, err)
return nil, err
podName := os.Getenv("POD_NAME")
for i := 0; i < 3; i++ {
pod, err := config.KubeClient.CoreV1().Pods("kube-system").Get(context.Background(), podName, metav1.GetOptions{})
if err != nil {
klog.Errorf("failed to get self pod kube-system/%s: %v", podName, err)
return nil, err
}

if len(pod.Status.PodIPs) != 0 {
config.PodProtocols = make([]string, len(pod.Status.PodIPs))
for i, podIP := range pod.Status.PodIPs {
config.PodProtocols[i] = util.CheckProtocol(podIP.IP)
}
break
}

if pod.Status.ContainerStatuses[0].Ready {
klog.Fatalf("failed to get IPs of Pod kube-system/%s", podName)
}

klog.Infof("cannot get Pod IPs now, waiting Pod to be ready")
time.Sleep(time.Second)
}

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

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

0 comments on commit 727ea53

Please sign in to comment.