mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Job Pod Failure policy - cover testing of negative exit codes
This commit is contained in:
		@@ -134,6 +134,25 @@ func TestValidateJob(t *testing.T) {
 | 
				
			|||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
							"valid pod failure policy with negative exitCodes - need for Windows support": {
 | 
				
			||||||
 | 
								opts: JobValidationOptions{RequirePrefixedLabels: true},
 | 
				
			||||||
 | 
								job: batch.Job{
 | 
				
			||||||
 | 
									ObjectMeta: validJobObjectMeta,
 | 
				
			||||||
 | 
									Spec: batch.JobSpec{
 | 
				
			||||||
 | 
										Selector: validGeneratedSelector,
 | 
				
			||||||
 | 
										Template: validPodTemplateSpecForGeneratedRestartPolicyNever,
 | 
				
			||||||
 | 
										PodFailurePolicy: &batch.PodFailurePolicy{
 | 
				
			||||||
 | 
											Rules: []batch.PodFailurePolicyRule{{
 | 
				
			||||||
 | 
												Action: batch.PodFailurePolicyActionFailJob,
 | 
				
			||||||
 | 
												OnExitCodes: &batch.PodFailurePolicyOnExitCodesRequirement{
 | 
				
			||||||
 | 
													Operator: batch.PodFailurePolicyOnExitCodesOpNotIn,
 | 
				
			||||||
 | 
													Values:   []int32{-1073741819, -1073741676, -1073741510},
 | 
				
			||||||
 | 
												},
 | 
				
			||||||
 | 
											}},
 | 
				
			||||||
 | 
										},
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
		"valid pod failure policy": {
 | 
							"valid pod failure policy": {
 | 
				
			||||||
			opts: JobValidationOptions{RequirePrefixedLabels: true},
 | 
								opts: JobValidationOptions{RequirePrefixedLabels: true},
 | 
				
			||||||
			job: batch.Job{
 | 
								job: batch.Job{
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -216,6 +216,37 @@ func TestMatchPodFailurePolicy(t *testing.T) {
 | 
				
			|||||||
			wantCountFailed:       false,
 | 
								wantCountFailed:       false,
 | 
				
			||||||
			wantAction:            &ignore,
 | 
								wantAction:            &ignore,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
							"ignore rule matched on negative exit codes - needed for Windows support": {
 | 
				
			||||||
 | 
								podFailurePolicy: &batch.PodFailurePolicy{
 | 
				
			||||||
 | 
									Rules: []batch.PodFailurePolicyRule{
 | 
				
			||||||
 | 
										{
 | 
				
			||||||
 | 
											Action: batch.PodFailurePolicyActionIgnore,
 | 
				
			||||||
 | 
											OnExitCodes: &batch.PodFailurePolicyOnExitCodesRequirement{
 | 
				
			||||||
 | 
												Operator: batch.PodFailurePolicyOnExitCodesOpIn,
 | 
				
			||||||
 | 
												Values:   []int32{-1073741676, -1073741510},
 | 
				
			||||||
 | 
											},
 | 
				
			||||||
 | 
										},
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								failedPod: &v1.Pod{
 | 
				
			||||||
 | 
									ObjectMeta: validPodObjectMeta,
 | 
				
			||||||
 | 
									Status: v1.PodStatus{
 | 
				
			||||||
 | 
										Phase: v1.PodFailed,
 | 
				
			||||||
 | 
										ContainerStatuses: []v1.ContainerStatus{
 | 
				
			||||||
 | 
											{
 | 
				
			||||||
 | 
												State: v1.ContainerState{
 | 
				
			||||||
 | 
													Terminated: &v1.ContainerStateTerminated{
 | 
				
			||||||
 | 
														ExitCode: -1073741510,
 | 
				
			||||||
 | 
													},
 | 
				
			||||||
 | 
												},
 | 
				
			||||||
 | 
											},
 | 
				
			||||||
 | 
										},
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								wantJobFailureMessage: nil,
 | 
				
			||||||
 | 
								wantCountFailed:       false,
 | 
				
			||||||
 | 
								wantAction:            &ignore,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
		"FailJob rule matched for exit codes": {
 | 
							"FailJob rule matched for exit codes": {
 | 
				
			||||||
			podFailurePolicy: &batch.PodFailurePolicy{
 | 
								podFailurePolicy: &batch.PodFailurePolicy{
 | 
				
			||||||
				Rules: []batch.PodFailurePolicyRule{
 | 
									Rules: []batch.PodFailurePolicyRule{
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -428,6 +428,59 @@ func TestJobPodFailurePolicy(t *testing.T) {
 | 
				
			|||||||
				Value:  0,
 | 
									Value:  0,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
							"pod status matching the configured FailJob rule on a negative exit code - needed for Windows support": {
 | 
				
			||||||
 | 
								job: batchv1.Job{
 | 
				
			||||||
 | 
									Spec: batchv1.JobSpec{
 | 
				
			||||||
 | 
										Template: v1.PodTemplateSpec{
 | 
				
			||||||
 | 
											Spec: v1.PodSpec{
 | 
				
			||||||
 | 
												Containers: []v1.Container{
 | 
				
			||||||
 | 
													{
 | 
				
			||||||
 | 
														Name:                     "main-container",
 | 
				
			||||||
 | 
														Image:                    "foo",
 | 
				
			||||||
 | 
														ImagePullPolicy:          v1.PullIfNotPresent,
 | 
				
			||||||
 | 
														TerminationMessagePolicy: v1.TerminationMessageFallbackToLogsOnError,
 | 
				
			||||||
 | 
													},
 | 
				
			||||||
 | 
												},
 | 
				
			||||||
 | 
											},
 | 
				
			||||||
 | 
										},
 | 
				
			||||||
 | 
										PodFailurePolicy: &batchv1.PodFailurePolicy{
 | 
				
			||||||
 | 
											Rules: []batchv1.PodFailurePolicyRule{
 | 
				
			||||||
 | 
												{
 | 
				
			||||||
 | 
													Action: batchv1.PodFailurePolicyActionFailJob,
 | 
				
			||||||
 | 
													OnExitCodes: &batchv1.PodFailurePolicyOnExitCodesRequirement{
 | 
				
			||||||
 | 
														Operator: batchv1.PodFailurePolicyOnExitCodesOpIn,
 | 
				
			||||||
 | 
														Values:   []int32{-1073741510, 137},
 | 
				
			||||||
 | 
													},
 | 
				
			||||||
 | 
												},
 | 
				
			||||||
 | 
											},
 | 
				
			||||||
 | 
										},
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								podStatus: v1.PodStatus{
 | 
				
			||||||
 | 
									Phase: v1.PodFailed,
 | 
				
			||||||
 | 
									ContainerStatuses: []v1.ContainerStatus{
 | 
				
			||||||
 | 
										{
 | 
				
			||||||
 | 
											Name: "main-container",
 | 
				
			||||||
 | 
											State: v1.ContainerState{
 | 
				
			||||||
 | 
												Terminated: &v1.ContainerStateTerminated{
 | 
				
			||||||
 | 
													ExitCode: -1073741510,
 | 
				
			||||||
 | 
												},
 | 
				
			||||||
 | 
											},
 | 
				
			||||||
 | 
										},
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								wantActive:           0,
 | 
				
			||||||
 | 
								wantFailed:           1,
 | 
				
			||||||
 | 
								wantJobConditionType: batchv1.JobFailed,
 | 
				
			||||||
 | 
								wantJobFinishedMetric: metricLabelsWithValue{
 | 
				
			||||||
 | 
									Labels: []string{"NonIndexed", "failed", "PodFailurePolicy"},
 | 
				
			||||||
 | 
									Value:  1,
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								wantPodFailuresHandledByPolicyRuleMetric: &metricLabelsWithValue{
 | 
				
			||||||
 | 
									Labels: []string{"FailJob"},
 | 
				
			||||||
 | 
									Value:  1,
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	closeFn, restConfig, clientSet, ns := setup(t, "pod-failure-policy")
 | 
						closeFn, restConfig, clientSet, ns := setup(t, "pod-failure-policy")
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user