Merge pull request #122261 from mimowo/unit-tests-for-job-controller-fix

Add unit test for Job Controller for panic when PodFailurePolicy is used on 1.28
This commit is contained in:
Kubernetes Prow Robot
2023-12-14 07:27:48 +01:00
committed by GitHub

View File

@@ -256,6 +256,7 @@ func TestControllerSyncJob(t *testing.T) {
wasSuspended bool
suspend bool
podReplacementPolicy *batch.PodReplacementPolicy
podFailurePolicy *batch.PodFailurePolicy
initialStatus *jobInitialStatus
backoffRecord *backoffRecord
controllerTime *time.Time
@@ -293,6 +294,7 @@ func TestControllerSyncJob(t *testing.T) {
// features
podIndexLabelDisabled bool
jobPodReplacementPolicy bool
jobPodFailurePolicy bool
}{
"job start": {
parallelism: 2,
@@ -407,6 +409,22 @@ func TestControllerSyncJob(t *testing.T) {
expectedDeletions: 1,
expectedPodPatches: 1,
},
"more terminating pods than parallelism; PodFailurePolicy used": {
// Repro for https://github.com/kubernetes/kubernetes/issues/122235
parallelism: 1,
completions: 1,
backoffLimit: 6,
activePods: 2,
failedPods: 0,
terminatingPods: 4,
jobPodFailurePolicy: true,
podFailurePolicy: &batch.PodFailurePolicy{},
expectedTerminating: nil,
expectedReady: ptr.To[int32](0),
expectedActive: 1,
expectedDeletions: 1,
expectedPodPatches: 1,
},
"too few active pods and active back-off": {
parallelism: 1,
completions: 1,
@@ -935,6 +953,7 @@ func TestControllerSyncJob(t *testing.T) {
logger, _ := ktesting.NewTestContext(t)
defer featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, features.PodIndexLabel, !tc.podIndexLabelDisabled)()
defer featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, features.JobPodReplacementPolicy, tc.jobPodReplacementPolicy)()
defer featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, features.JobPodFailurePolicy, tc.jobPodFailurePolicy)()
// job manager setup
clientSet := clientset.NewForConfigOrDie(&restclient.Config{Host: "", ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Group: "", Version: "v1"}}})
@@ -957,6 +976,9 @@ func TestControllerSyncJob(t *testing.T) {
if tc.jobPodReplacementPolicy {
job.Spec.PodReplacementPolicy = tc.podReplacementPolicy
}
if tc.jobPodFailurePolicy {
job.Spec.PodFailurePolicy = tc.podFailurePolicy
}
if tc.initialStatus != nil {
startTime := metav1.Now()
job.Status.StartTime = &startTime