@@ -37,6 +37,7 @@ import (
37
37
apitypes "k8s.io/apimachinery/pkg/types"
38
38
clientset "k8s.io/client-go/kubernetes"
39
39
"k8s.io/kubectl/pkg/util/podutils"
40
+ podv1util "k8s.io/kubernetes/pkg/api/v1/pod"
40
41
"k8s.io/kubernetes/test/e2e/framework"
41
42
testutils "k8s.io/kubernetes/test/utils"
42
43
"k8s.io/kubernetes/test/utils/format"
@@ -869,11 +870,14 @@ func WaitForContainerTerminated(ctx context.Context, c clientset.Interface, name
869
870
})
870
871
}
871
872
872
- // WaitForContainerRestartedNTimes waits for a container in the Pod to have restarted N times
873
- func WaitForContainerRestartedNTimes (ctx context.Context , c clientset.Interface , namespace string , podName string , timeout time.Duration , target int ) error {
873
+ // WaitForContainerRestartedNTimes waits for the given normal container in the Pod to have restarted N times
874
+ func WaitForContainerRestartedNTimes (ctx context.Context , c clientset.Interface , namespace string , podName string , containerName string , timeout time.Duration , target int ) error {
874
875
conditionDesc := fmt .Sprintf ("A container in pod %s restarted at least %d times" , podName , target )
875
876
return WaitForPodCondition (ctx , c , namespace , podName , conditionDesc , timeout , func (pod * v1.Pod ) (bool , error ) {
876
- r , _ := podutils .MaxContainerRestarts (pod )
877
- return r >= target , nil
877
+ cs , found := podv1util .GetContainerStatus (pod .Status .ContainerStatuses , containerName )
878
+ if ! found {
879
+ return false , fmt .Errorf ("could not find container %s in pod %s" , containerName , podName )
880
+ }
881
+ return cs .RestartCount >= int32 (target ), nil
878
882
})
879
883
}
0 commit comments