@@ -21,8 +21,10 @@ package e2enode
21
21
22
22
import (
23
23
"context"
24
+ "fmt"
24
25
"time"
25
26
27
+ podv1util "k8s.io/kubernetes/pkg/api/v1/pod"
26
28
imageutils "k8s.io/kubernetes/test/utils/image"
27
29
28
30
"github.com/onsi/ginkgo/v2"
@@ -97,7 +99,7 @@ func doTest(ctx context.Context, f *framework.Framework, targetRestarts int, con
97
99
98
100
// Hard wait 30 seconds for targetRestarts in the best case; longer timeout later will handle if infra was slow.
99
101
time .Sleep (30 * time .Second )
100
- podErr = e2epod . WaitForContainerRestartedNTimes (ctx , f . ClientSet , f .Namespace .Name , pod .Name , containerName , 5 * time .Minute , targetRestarts )
102
+ podErr = waitForContainerRestartedNTimes (ctx , f , f .Namespace .Name , pod .Name , containerName , 5 * time .Minute , targetRestarts )
101
103
gomega .Expect (podErr ).ShouldNot (gomega .HaveOccurred (), "Expected container to repeatedly back off container failures" )
102
104
103
105
r , err := extractObservedBackoff (ctx , f , pod .Name , containerName )
@@ -140,3 +142,14 @@ func newFailAlwaysPod() *v1.Pod {
140
142
}
141
143
return pod
142
144
}
145
+
146
+ func waitForContainerRestartedNTimes (ctx context.Context , f * framework.Framework , namespace string , podName string , containerName string , timeout time.Duration , target int ) error {
147
+ conditionDesc := fmt .Sprintf ("A container in pod %s restarted at least %d times" , podName , target )
148
+ return e2epod .WaitForPodCondition (ctx , f .ClientSet , namespace , podName , conditionDesc , timeout , func (pod * v1.Pod ) (bool , error ) {
149
+ cs , found := podv1util .GetContainerStatus (pod .Status .ContainerStatuses , containerName )
150
+ if ! found {
151
+ return false , fmt .Errorf ("could not find container %s in pod %s" , containerName , podName )
152
+ }
153
+ return cs .RestartCount >= int32 (target ), nil
154
+ })
155
+ }
0 commit comments