From aeceec72bbda985e96a7f72ed730381d37015976 Mon Sep 17 00:00:00 2001 From: kannon92 Date: Fri, 11 Aug 2023 20:52:24 +0000 Subject: [PATCH] add integration tests --- test/integration/job/job_test.go | 63 ++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/test/integration/job/job_test.go b/test/integration/job/job_test.go index cce3cec7905..c2c354ad5bf 100644 --- a/test/integration/job/job_test.go +++ b/test/integration/job/job_test.go @@ -1898,6 +1898,69 @@ func TestJobPodReplacementPolicy(t *testing.T) { } } +// This tests the feature enable -> disable -> enable path for PodReplacementPolicy. +// We verify that Failed case works as expected when turned on. +// Disable reverts to previous behavior. +// Enabling will then match the original failed case. +func TestJobPodReplacementPolicyFeatureToggling(t *testing.T) { + const podCount int32 = 2 + jobSpec := batchv1.JobSpec{ + Parallelism: ptr.To(podCount), + Completions: ptr.To(podCount), + CompletionMode: ptr.To(batchv1.NonIndexedCompletion), + PodReplacementPolicy: ptr.To(batchv1.Failed), + } + wantTerminating := ptr.To(podCount) + defer featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, features.JobPodReplacementPolicy, true)() + closeFn, restConfig, clientSet, ns := setup(t, "pod-replacement-policy") + defer closeFn() + ctx, cancel := startJobControllerAndWaitForCaches(t, restConfig) + defer func() { + cancel() + }() + resetMetrics() + + jobObj, err := createJobWithDefaults(ctx, clientSet, ns.Name, &batchv1.Job{ + Spec: jobSpec, + }) + if err != nil { + t.Fatalf("Failed to create Job: %v", err) + } + jobClient := clientSet.BatchV1().Jobs(jobObj.Namespace) + + waitForPodsToBeActive(ctx, t, jobClient, 2, jobObj) + deletePods(ctx, t, clientSet, jobObj.Namespace) + validateJobsPodsStatusOnly(ctx, t, clientSet, jobObj, podsByStatus{ + Terminating: wantTerminating, + Failed: 0, + Ready: ptr.To[int32](0), + }) + // Disable controller and turn feature off. + defer featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, features.JobPodReplacementPolicy, false)() + cancel() + ctx, cancel = startJobControllerAndWaitForCaches(t, restConfig) + + validateJobsPodsStatusOnly(ctx, t, clientSet, jobObj, podsByStatus{ + Terminating: nil, + Failed: int(podCount), + Ready: ptr.To[int32](0), + Active: int(podCount), + }) + // Disable the controller and turn feature on again. + defer featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, features.JobPodReplacementPolicy, true)() + cancel() + ctx, cancel = startJobControllerAndWaitForCaches(t, restConfig) + waitForPodsToBeActive(ctx, t, jobClient, 2, jobObj) + deletePods(ctx, t, clientSet, jobObj.Namespace) + + validateJobsPodsStatusOnly(ctx, t, clientSet, jobObj, podsByStatus{ + Terminating: wantTerminating, + Failed: int(podCount), + Active: 0, + Ready: ptr.To[int32](0), + }) +} + func TestElasticIndexedJob(t *testing.T) { const initialCompletions int32 = 3 type jobUpdate struct {