Review remarks

This commit is contained in:
Michal Wozniak 2025-06-30 13:18:53 +02:00
parent 3851253305
commit 068079fb7e
2 changed files with 24 additions and 24 deletions

View File

@ -379,7 +379,7 @@ func getStatusValidationOptions(newJob, oldJob *batch.Job) batchvalidation.JobSt
isUncountedTerminatedPodsChanged := !apiequality.Semantic.DeepEqual(oldJob.Status.UncountedTerminatedPods, newJob.Status.UncountedTerminatedPods)
isReadyChanged := !ptr.Equal(oldJob.Status.Ready, newJob.Status.Ready)
isTerminatingChanged := !ptr.Equal(oldJob.Status.Terminating, newJob.Status.Terminating)
isSuspendedWithZeroCompletions := newJob.Spec.Completions != nil && *newJob.Spec.Completions == 0 && newJob.Spec.Suspend != nil && *newJob.Spec.Suspend
isSuspendedWithZeroCompletions := ptr.Equal(newJob.Spec.Suspend, ptr.To(true)) && ptr.Equal(newJob.Spec.Completions, ptr.To[int32](0))
return batchvalidation.JobStatusValidationOptions{
// We allow to decrease the counter for succeeded pods for jobs which

View File

@ -2801,29 +2801,6 @@ func TestParallelJobWithCompletions(t *testing.T) {
})
}
// TestSuspendedJobWithZeroCompletions verifies the suspended Job with
// completions=0 is marked as Complete.
func TestSuspendedJobWithZeroCompletions(t *testing.T) {
closeFn, restConfig, clientSet, ns := setup(t, "suspended-with-zero-completions")
t.Cleanup(closeFn)
ctx, cancel := startJobControllerAndWaitForCaches(t, restConfig)
t.Cleanup(func() {
cancel()
})
jobObj, err := createJobWithDefaults(ctx, clientSet, ns.Name, &batchv1.Job{
Spec: batchv1.JobSpec{
Completions: ptr.To[int32](0),
Suspend: ptr.To(true),
},
})
if err != nil {
t.Fatalf("Failed to create Job: %v", err)
}
for _, condition := range []batchv1.JobConditionType{batchv1.JobSuccessCriteriaMet, batchv1.JobComplete} {
validateJobCondition(ctx, t, clientSet, jobObj, condition)
}
}
func TestIndexedJob(t *testing.T) {
t.Cleanup(setDurationDuringTest(&jobcontroller.DefaultJobPodFailureBackOff, fastPodFailureBackoff))
closeFn, restConfig, clientSet, ns := setup(t, "indexed")
@ -4007,6 +3984,29 @@ func TestSuspendJob(t *testing.T) {
}
}
// TestSuspendJobWithZeroCompletions verifies the suspended Job with
// completions=0 is marked as Complete.
func TestSuspendJobWithZeroCompletions(t *testing.T) {
closeFn, restConfig, clientSet, ns := setup(t, "suspended-with-zero-completions")
t.Cleanup(closeFn)
ctx, cancel := startJobControllerAndWaitForCaches(t, restConfig)
t.Cleanup(func() {
cancel()
})
jobObj, err := createJobWithDefaults(ctx, clientSet, ns.Name, &batchv1.Job{
Spec: batchv1.JobSpec{
Completions: ptr.To[int32](0),
Suspend: ptr.To(true),
},
})
if err != nil {
t.Fatalf("Failed to create Job: %v", err)
}
for _, condition := range []batchv1.JobConditionType{batchv1.JobSuccessCriteriaMet, batchv1.JobComplete} {
validateJobCondition(ctx, t, clientSet, jobObj, condition)
}
}
func TestSuspendJobControllerRestart(t *testing.T) {
closeFn, restConfig, clientSet, ns := setup(t, "suspend")
t.Cleanup(closeFn)