@@ -42,17 +42,23 @@ type JobState func(job *batchv1.Job) string
42
42
// WaitForJobPodsRunning wait for all pods for the Job named JobName in namespace ns to become Running. Only use
43
43
// when pods will run for a long time, or it will be racy.
44
44
func WaitForJobPodsRunning (ctx context.Context , c clientset.Interface , ns , jobName string , expectedCount int32 ) error {
45
- return waitForJobPodsInPhase (ctx , c , ns , jobName , expectedCount , v1 .PodRunning )
45
+ return waitForJobPodsInPhase (ctx , c , ns , jobName , expectedCount , v1 .PodRunning , JobTimeout )
46
+ }
47
+
48
+ // WaitForJobPodsRunningWithTimeout wait for all pods for the Job named JobName in namespace ns to become Running. Only use
49
+ // when pods will run for a long time, or it will be racy. same as WaitForJobPodsRunning but with an additional timeout parameter
50
+ func WaitForJobPodsRunningWithTimeout (ctx context.Context , c clientset.Interface , ns , jobName string , expectedCount int32 , timeout time.Duration ) error {
51
+ return waitForJobPodsInPhase (ctx , c , ns , jobName , expectedCount , v1 .PodRunning , timeout )
46
52
}
47
53
48
54
// WaitForJobPodsSucceeded wait for all pods for the Job named JobName in namespace ns to become Succeeded.
49
55
func WaitForJobPodsSucceeded (ctx context.Context , c clientset.Interface , ns , jobName string , expectedCount int32 ) error {
50
- return waitForJobPodsInPhase (ctx , c , ns , jobName , expectedCount , v1 .PodSucceeded )
56
+ return waitForJobPodsInPhase (ctx , c , ns , jobName , expectedCount , v1 .PodSucceeded , JobTimeout )
51
57
}
52
58
53
59
// waitForJobPodsInPhase wait for all pods for the Job named JobName in namespace ns to be in a given phase.
54
- func waitForJobPodsInPhase (ctx context.Context , c clientset.Interface , ns , jobName string , expectedCount int32 , phase v1.PodPhase ) error {
55
- return wait .PollUntilContextTimeout (ctx , framework .Poll , JobTimeout , false , func (ctx context.Context ) (bool , error ) {
60
+ func waitForJobPodsInPhase (ctx context.Context , c clientset.Interface , ns , jobName string , expectedCount int32 , phase v1.PodPhase , timeout time. Duration ) error {
61
+ return wait .PollUntilContextTimeout (ctx , framework .Poll , timeout , false , func (ctx context.Context ) (bool , error ) {
56
62
pods , err := GetJobPods (ctx , c , ns , jobName )
57
63
if err != nil {
58
64
return false , err
@@ -157,7 +163,12 @@ func isJobFailed(j *batchv1.Job) bool {
157
163
158
164
// WaitForJobFinish uses c to wait for the Job jobName in namespace ns to finish (either Failed or Complete).
159
165
func WaitForJobFinish (ctx context.Context , c clientset.Interface , ns , jobName string ) error {
160
- return wait .PollUntilContextTimeout (ctx , framework .Poll , JobTimeout , true , func (ctx context.Context ) (bool , error ) {
166
+ return WaitForJobFinishWithTimeout (ctx , c , ns , jobName , JobTimeout )
167
+ }
168
+
169
+ // WaitForJobFinishWithTimeout uses c to wait for the Job jobName in namespace ns to finish (either Failed or Complete).
170
+ func WaitForJobFinishWithTimeout (ctx context.Context , c clientset.Interface , ns , jobName string , timeout time.Duration ) error {
171
+ return wait .PollUntilContextTimeout (ctx , framework .Poll , timeout , true , func (ctx context.Context ) (bool , error ) {
161
172
curr , err := c .BatchV1 ().Jobs (ns ).Get (ctx , jobName , metav1.GetOptions {})
162
173
if err != nil {
163
174
return false , err
0 commit comments