mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 09:52:49 +00:00
Merge pull request #132727 from mimowo/automated-cherry-pick-of-#132614-upstream-release-1.32
Automated cherry pick of #132614: Fix validation for Job with suspend=true,completions=0 to set Complete condition
This commit is contained in:
commit
bcb9d4ce05
@ -379,6 +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 := 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
|
||||
@ -394,7 +395,7 @@ func getStatusValidationOptions(newJob, oldJob *batch.Job) batchvalidation.JobSt
|
||||
RejectFailedJobWithoutFailureTarget: isJobFailedChanged || isFailedIndexesChanged,
|
||||
RejectCompleteJobWithoutSuccessCriteriaMet: isJobCompleteChanged || isJobSuccessCriteriaMetChanged,
|
||||
RejectFinishedJobWithActivePods: isJobFinishedChanged || isActiveChanged,
|
||||
RejectFinishedJobWithoutStartTime: isJobFinishedChanged || isStartTimeChanged,
|
||||
RejectFinishedJobWithoutStartTime: (isJobFinishedChanged || isStartTimeChanged) && !isSuspendedWithZeroCompletions,
|
||||
RejectFinishedJobWithUncountedTerminatedPods: isJobFinishedChanged || isUncountedTerminatedPodsChanged,
|
||||
RejectStartTimeUpdateForUnsuspendedJob: isStartTimeChanged,
|
||||
RejectCompletionTimeBeforeStartTime: isStartTimeChanged || isCompletionTimeChanged,
|
||||
|
@ -3561,6 +3561,36 @@ func TestStatusStrategy_ValidateUpdate(t *testing.T) {
|
||||
{Type: field.ErrorTypeInvalid, Field: "status.ready"},
|
||||
},
|
||||
},
|
||||
"valid transition to Complete for suspended Job with completions=0; without startTime": {
|
||||
enableJobManagedBy: true,
|
||||
job: &batch.Job{
|
||||
ObjectMeta: validObjectMeta,
|
||||
Spec: batch.JobSpec{
|
||||
Completions: ptr.To[int32](0),
|
||||
Suspend: ptr.To(true),
|
||||
},
|
||||
},
|
||||
newJob: &batch.Job{
|
||||
ObjectMeta: validObjectMeta,
|
||||
Spec: batch.JobSpec{
|
||||
Completions: ptr.To[int32](0),
|
||||
Suspend: ptr.To(true),
|
||||
},
|
||||
Status: batch.JobStatus{
|
||||
CompletionTime: &now,
|
||||
Conditions: []batch.JobCondition{
|
||||
{
|
||||
Type: batch.JobSuccessCriteriaMet,
|
||||
Status: api.ConditionTrue,
|
||||
},
|
||||
{
|
||||
Type: batch.JobComplete,
|
||||
Status: api.ConditionTrue,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for name, tc := range cases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
|
@ -4062,6 +4062,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)
|
||||
|
Loading…
Reference in New Issue
Block a user