Skip to content

Commit

Permalink
Merge pull request #167 from SrinivasChilveri/ttlvalidation
Browse files Browse the repository at this point in the history
Added ttl validation in admission controller
  • Loading branch information
volcano-sh-bot authored May 15, 2019
2 parents efaad36 + 3dad87d commit fd4e5a0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
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."))
})
})

0 comments on commit fd4e5a0

Please sign in to comment.