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

Added ttl validation in admission controller #167

Merged
merged 1 commit into from
May 15, 2019
Merged
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
5 changes: 5 additions & 0 deletions pkg/admission/admit_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ func validateJob(job v1alpha1.Job, reviewResponse *v1beta1.AdmissionResponse) st
return fmt.Sprintf("'maxRetry' cannot be less than zero.")
}

if job.Spec.TTLSecondsAfterFinished != nil && *job.Spec.TTLSecondsAfterFinished < 0 {
reviewResponse.Allowed = false
return fmt.Sprintf("'ttlSecondsAfterFinished' cannot be less than zero.")
}

if len(job.Spec.Tasks) == 0 {
reviewResponse.Allowed = false
return fmt.Sprintf("No task specified in job spec")
Expand Down
30 changes: 30 additions & 0 deletions test/e2e/admission.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,34 @@ var _ = Describe("Job E2E Test: Test Admission service", func() {
Expect(createdJob.Spec.Queue).Should(Equal("default"),
"Job queue attribute would default to 'default' ")
})

It("ttl illegal", func() {
jobName := "job-ttl-illegal"
namespace := "test"
var ttl int32
ttl = -1
context := initTestContext()
defer cleanupTestContext(context)

_, err := createJobInner(context, &jobSpec{
min: 1,
namespace: namespace,
name: jobName,
ttl: &ttl,
tasks: []taskSpec{
{
img: defaultNginxImage,
req: oneCPU,
min: 1,
rep: 1,
name: "taskname",
},
},
})
Expect(err).To(HaveOccurred())
stError, ok := err.(*errors.StatusError)
Expect(ok).To(Equal(true))
Expect(stError.ErrStatus.Code).To(Equal(int32(500)))
Expect(stError.ErrStatus.Message).To(ContainSubstring("'ttlSecondsAfterFinished' cannot be less than zero."))
})
})