Skip to content

Commit cad6480

Browse files
committed
Job Pod Failure policy - cover testing of negative exit codes
1 parent e15d5b9 commit cad6480

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

pkg/apis/batch/validation/validation_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,25 @@ func TestValidateJob(t *testing.T) {
134134
},
135135
},
136136
},
137+
"valid pod failure policy with negative exitCodes - need for Windows support": {
138+
opts: JobValidationOptions{RequirePrefixedLabels: true},
139+
job: batch.Job{
140+
ObjectMeta: validJobObjectMeta,
141+
Spec: batch.JobSpec{
142+
Selector: validGeneratedSelector,
143+
Template: validPodTemplateSpecForGeneratedRestartPolicyNever,
144+
PodFailurePolicy: &batch.PodFailurePolicy{
145+
Rules: []batch.PodFailurePolicyRule{{
146+
Action: batch.PodFailurePolicyActionFailJob,
147+
OnExitCodes: &batch.PodFailurePolicyOnExitCodesRequirement{
148+
Operator: batch.PodFailurePolicyOnExitCodesOpNotIn,
149+
Values: []int32{-1073741819, -1073741676, -1073741510},
150+
},
151+
}},
152+
},
153+
},
154+
},
155+
},
137156
"valid pod failure policy": {
138157
opts: JobValidationOptions{RequirePrefixedLabels: true},
139158
job: batch.Job{

pkg/controller/job/pod_failure_policy_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,37 @@ func TestMatchPodFailurePolicy(t *testing.T) {
216216
wantCountFailed: false,
217217
wantAction: &ignore,
218218
},
219+
"ignore rule matched on negative exit codes - needed for Windows support": {
220+
podFailurePolicy: &batch.PodFailurePolicy{
221+
Rules: []batch.PodFailurePolicyRule{
222+
{
223+
Action: batch.PodFailurePolicyActionIgnore,
224+
OnExitCodes: &batch.PodFailurePolicyOnExitCodesRequirement{
225+
Operator: batch.PodFailurePolicyOnExitCodesOpIn,
226+
Values: []int32{-1073741676, -1073741510},
227+
},
228+
},
229+
},
230+
},
231+
failedPod: &v1.Pod{
232+
ObjectMeta: validPodObjectMeta,
233+
Status: v1.PodStatus{
234+
Phase: v1.PodFailed,
235+
ContainerStatuses: []v1.ContainerStatus{
236+
{
237+
State: v1.ContainerState{
238+
Terminated: &v1.ContainerStateTerminated{
239+
ExitCode: -1073741510,
240+
},
241+
},
242+
},
243+
},
244+
},
245+
},
246+
wantJobFailureMessage: nil,
247+
wantCountFailed: false,
248+
wantAction: &ignore,
249+
},
219250
"FailJob rule matched for exit codes": {
220251
podFailurePolicy: &batch.PodFailurePolicy{
221252
Rules: []batch.PodFailurePolicyRule{

test/integration/job/job_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,59 @@ func TestJobPodFailurePolicy(t *testing.T) {
428428
Value: 0,
429429
},
430430
},
431+
"pod status matching the configured FailJob rule on a negative exit code - needed for Windows support": {
432+
job: batchv1.Job{
433+
Spec: batchv1.JobSpec{
434+
Template: v1.PodTemplateSpec{
435+
Spec: v1.PodSpec{
436+
Containers: []v1.Container{
437+
{
438+
Name: "main-container",
439+
Image: "foo",
440+
ImagePullPolicy: v1.PullIfNotPresent,
441+
TerminationMessagePolicy: v1.TerminationMessageFallbackToLogsOnError,
442+
},
443+
},
444+
},
445+
},
446+
PodFailurePolicy: &batchv1.PodFailurePolicy{
447+
Rules: []batchv1.PodFailurePolicyRule{
448+
{
449+
Action: batchv1.PodFailurePolicyActionFailJob,
450+
OnExitCodes: &batchv1.PodFailurePolicyOnExitCodesRequirement{
451+
Operator: batchv1.PodFailurePolicyOnExitCodesOpIn,
452+
Values: []int32{-1073741510, 137},
453+
},
454+
},
455+
},
456+
},
457+
},
458+
},
459+
podStatus: v1.PodStatus{
460+
Phase: v1.PodFailed,
461+
ContainerStatuses: []v1.ContainerStatus{
462+
{
463+
Name: "main-container",
464+
State: v1.ContainerState{
465+
Terminated: &v1.ContainerStateTerminated{
466+
ExitCode: -1073741510,
467+
},
468+
},
469+
},
470+
},
471+
},
472+
wantActive: 0,
473+
wantFailed: 1,
474+
wantJobConditionType: batchv1.JobFailed,
475+
wantJobFinishedMetric: metricLabelsWithValue{
476+
Labels: []string{"NonIndexed", "failed", "PodFailurePolicy"},
477+
Value: 1,
478+
},
479+
wantPodFailuresHandledByPolicyRuleMetric: &metricLabelsWithValue{
480+
Labels: []string{"FailJob"},
481+
Value: 1,
482+
},
483+
},
431484
}
432485

433486
closeFn, restConfig, clientSet, ns := setup(t, "pod-failure-policy")

0 commit comments

Comments
 (0)