Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Used fixed API for Job Pod Failure Policy #620

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,5 @@ require (
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)

replace k8s.io/api => k8s.io/api v0.0.0-20240718103906-7c71f3c0b7a7 // feature-branch
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/api v0.29.4 h1:WEnF/XdxuCxdG3ayHNRR8yH3cI1B/llkWBma6bq4R3w=
k8s.io/api v0.29.4/go.mod h1:DetSv0t4FBTcEpfA84NJV3g9a7+rSzlUHk5ADAYHUv0=
k8s.io/api v0.0.0-20240718103906-7c71f3c0b7a7 h1:yum8NOR/ysIRWDiCZuVbLvHCmeuM2KHc/8voO+xoivw=
k8s.io/api v0.0.0-20240718103906-7c71f3c0b7a7/go.mod h1:AFqQkkEfmsUH52cPeKeWVm6eQZJUan7p62A0JEH+azM=
k8s.io/apiextensions-apiserver v0.29.2 h1:UK3xB5lOWSnhaCk0RFZ0LUacPZz9RY4wi/yt2Iu+btg=
k8s.io/apiextensions-apiserver v0.29.2/go.mod h1:aLfYjpA5p3OwtqNXQFkhJ56TB+spV8Gc4wfMhUA3/b8=
k8s.io/apimachinery v0.29.4 h1:RaFdJiDmuKs/8cm1M6Dh1Kvyh59YQFDcFuFTSmXes6Q=
Expand Down
6 changes: 6 additions & 0 deletions pkg/util/testing/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ func (j *JobTemplateWrapper) PodSpec(podSpec corev1.PodSpec) *JobTemplateWrapper
return j
}

// PodFailurePolicy sets the Job pod failure policy
func (j *JobTemplateWrapper) PodFailurePolicy(podFailurePolicy batchv1.PodFailurePolicy) *JobTemplateWrapper {
j.Spec.PodFailurePolicy = &podFailurePolicy
return j
}

// SetAnnotations sets the annotations on the Job template.
func (j *JobTemplateWrapper) SetAnnotations(annotations map[string]string) *JobTemplateWrapper {
j.Annotations = annotations
Expand Down
48 changes: 48 additions & 0 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
v1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -130,7 +131,54 @@ var _ = ginkgo.Describe("JobSet", func() {
util.JobSetDeleted(ctx, k8sClient, js, timeout)
})
})
ginkgo.When("pod failure policy is used", func() {
ginkgo.It("should allow to fail the Job on exit code", func() {
ctx := context.Background()

// This test verifies that the PodFailurePolicy terminated the Job
// Otherwise the pod restarts, with the default backoffLimit of 6
// the Pod restarts would take cumulatively at least:
// 10+20+40+80+160+320=630s (exceeding the test timeout)
ginkgo.By("creating jobset with ttl seconds after finished")
jsWrapper := testing.MakeJobSet("job-pod-failure-policy", ns.Name).
TTLSecondsAfterFinished(5).
ReplicatedJob(testing.MakeReplicatedJob("rjob").
Job(testing.MakeJobTemplate("job", ns.Name).
PodFailurePolicy(v1.PodFailurePolicy{
Rules: []v1.PodFailurePolicyRule{
{
Action: v1.PodFailurePolicyActionFailJob,
OnExitCodes: &v1.PodFailurePolicyOnExitCodesRequirement{
Operator: v1.PodFailurePolicyOnExitCodesOpIn,
Values: []int32{42},
},
},
},
}).
PodSpec(corev1.PodSpec{
RestartPolicy: "Never",
Containers: []corev1.Container{
{
Name: "sleep-test-container",
Image: "bash:latest",
Command: []string{"bash", "-c"},
Args: []string{"exit 42"},
},
},
}).Obj()).
Replicas(int32(1)).
Obj())
js := jsWrapper.Obj()

// Verify jobset created successfully.
ginkgo.By("checking that jobset creation succeeds")
gomega.Expect(k8sClient.Create(ctx, js)).Should(gomega.Succeed())

// Check jobset status if specified.
ginkgo.By("checking jobset condition")
util.JobSetFailed(ctx, k8sClient, js, timeout)
})
})
}) // end of Describe

// getPingCommand returns ping command for 4 hostnames
Expand Down