@@ -18,6 +18,8 @@ package trial
18
18
19
19
import (
20
20
"context"
21
+ "os"
22
+ "strings"
21
23
"testing"
22
24
"time"
23
25
@@ -263,29 +265,56 @@ func TestReconcileBatchJob(t *testing.T) {
263
265
g .Expect (c .Get (ctx , succeededBatchJobKey , batchJob )).Should (gomega .Succeed ())
264
266
}, timeout ).Should (gomega .Succeed ())
265
267
268
+ // Expect that Trial status is running
269
+ g .Eventually (func (g gomega.Gomega ) {
270
+ g .Expect (c .Get (ctx , trialKey , trial )).Should (gomega .Succeed ())
271
+ g .Expect (trial .IsRunning ()).Should (gomega .BeTrue ())
272
+ }, timeout ).Should (gomega .Succeed ())
273
+
266
274
// Update BatchJob status to Complete.
267
275
batchJobCompleteMessage := "BatchJob completed test message"
268
276
batchJobCompleteReason := "BatchJob completed test reason"
269
- g .Expect (c .Get (ctx , succeededBatchJobKey , batchJob )).NotTo (gomega .HaveOccurred ())
270
- batchJob .Status = batchv1.JobStatus {
271
- Conditions : []batchv1.JobCondition {
272
- {
273
- Type : batchv1 .JobSuccessCriteriaMet ,
274
- Status : corev1 .ConditionTrue ,
275
- Message : batchJobCompleteMessage ,
276
- Reason : batchJobCompleteReason ,
277
- },
278
- {
279
- Type : batchv1 .JobComplete ,
280
- Status : corev1 .ConditionTrue ,
281
- Message : batchJobCompleteMessage ,
282
- Reason : batchJobCompleteReason ,
283
- },
284
- },
285
- StartTime : & metav1.Time {Time : startTime },
286
- CompletionTime : & metav1.Time {Time : completionTime },
287
- }
288
- g .Expect (c .Status ().Update (ctx , batchJob )).NotTo (gomega .HaveOccurred ())
277
+ g .Eventually (func (g gomega.Gomega ) {
278
+ g .Expect (c .Get (ctx , succeededBatchJobKey , batchJob )).Should (gomega .Succeed ())
279
+ // TODO(Electronic-Waste): Remove this condition when K8s 1.30 is no longer supported.
280
+ // SuccessPolicy is available in K8s 1.31 and later. If we set it in K8s 1.30, it will be ignored.
281
+ // And when we set the status with `SuccessCriteriaMet`, it will report error:
282
+ // "Invalid value: cannot set SuccessCriteriaMet=True for Job without SuccessPolicy".
283
+ // REF: https://kubernetes.io/docs/concepts/workloads/controllers/job/#success-policy
284
+ isK8sVersion130 := strings .Contains (os .Getenv ("KUBEBUILDER_ASSETS" ), "1.30" )
285
+ if isK8sVersion130 {
286
+ batchJob .Status = batchv1.JobStatus {
287
+ Conditions : []batchv1.JobCondition {
288
+ {
289
+ Type : batchv1 .JobComplete ,
290
+ Status : corev1 .ConditionTrue ,
291
+ Message : batchJobCompleteMessage ,
292
+ Reason : batchJobCompleteReason ,
293
+ },
294
+ },
295
+ }
296
+ } else {
297
+ batchJob .Status = batchv1.JobStatus {
298
+ Conditions : []batchv1.JobCondition {
299
+ {
300
+ Type : batchv1 .JobSuccessCriteriaMet ,
301
+ Status : corev1 .ConditionTrue ,
302
+ Message : batchJobCompleteMessage ,
303
+ Reason : batchJobCompleteReason ,
304
+ },
305
+ {
306
+ Type : batchv1 .JobComplete ,
307
+ Status : corev1 .ConditionTrue ,
308
+ Message : batchJobCompleteMessage ,
309
+ Reason : batchJobCompleteReason ,
310
+ },
311
+ },
312
+ StartTime : & metav1.Time {Time : startTime },
313
+ CompletionTime : & metav1.Time {Time : completionTime },
314
+ }
315
+ }
316
+ g .Expect (c .Status ().Update (ctx , batchJob )).NotTo (gomega .HaveOccurred ())
317
+ }, timeout ).Should (gomega .Succeed ())
289
318
290
319
// Expect that Trial status is succeeded and metrics are properly populated
291
320
// Metrics available because GetTrialObservationLog returns values
0 commit comments