Skip to content

Commit 1fe3a7e

Browse files
fix(test): disable SuccessCriteriaMet in 1.30.
Signed-off-by: Electronic-Waste <[email protected]>
1 parent fb66fdb commit 1fe3a7e

File tree

1 file changed

+49
-20
lines changed

1 file changed

+49
-20
lines changed

pkg/controller.v1beta1/trial/trial_controller_test.go

+49-20
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package trial
1818

1919
import (
2020
"context"
21+
"os"
22+
"strings"
2123
"testing"
2224
"time"
2325

@@ -263,29 +265,56 @@ func TestReconcileBatchJob(t *testing.T) {
263265
g.Expect(c.Get(ctx, succeededBatchJobKey, batchJob)).Should(gomega.Succeed())
264266
}, timeout).Should(gomega.Succeed())
265267

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+
266274
// Update BatchJob status to Complete.
267275
batchJobCompleteMessage := "BatchJob completed test message"
268276
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())
289318

290319
// Expect that Trial status is succeeded and metrics are properly populated
291320
// Metrics available because GetTrialObservationLog returns values

0 commit comments

Comments
 (0)