Skip to content

Commit

Permalink
set time interval when wait for pod running
Browse files Browse the repository at this point in the history
Signed-off-by: hxcGit <houxc_mail@163.com>
  • Loading branch information
xavier-hou committed Apr 13, 2023
1 parent dc335bd commit 87e0e47
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pkg/node-servant/static-pod-upgrade/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"io"
"os"
"strings"
"time"

v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -77,6 +76,9 @@ func WaitForPodRunning(namespace, name, hash string, timeout time.Duration) (boo
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()

checkPod := func(pod *v1.Pod) (hasResult, result bool) {
h := pod.Annotations[StaticPodHashAnnotation]
if pod.Status.Phase == v1.PodRunning && h == hash {
Expand All @@ -97,9 +99,7 @@ func WaitForPodRunning(namespace, name, hash string, timeout time.Duration) (boo
default:
pod, err := GetPodFromYurtHub(namespace, name)
if err != nil {
if !strings.Contains(err.Error(), "fail to find pod") {
return false, err
}
klog.V(4).Infof("Temporarily fail to get pod from YurtHub, %v", err)
}
if pod != nil {
hasResult, result := checkPod(pod)
Expand All @@ -108,5 +108,6 @@ func WaitForPodRunning(namespace, name, hash string, timeout time.Duration) (boo
}
}
}
<-ticker.C
}
}

0 comments on commit 87e0e47

Please sign in to comment.