Skip to content

Commit

Permalink
Merge pull request volcano-sh#127 from TommyLike/feature/add_default_…
Browse files Browse the repository at this point in the history
…queue_mutate

Add default queue in admission hook
  • Loading branch information
volcano-sh-bot authored May 5, 2019
2 parents 12b7d9b + 36a48bd commit 3d213a3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/admission/mutate_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ import (
"volcano.sh/volcano/pkg/apis/batch/v1alpha1"
)

const (
DefaultQueue = "default"
)

type patchOperation struct {
Op string `json:"op"`
Path string `json:"path"`
Expand Down Expand Up @@ -71,6 +75,10 @@ func MutateJobs(ar v1beta1.AdmissionReview) *v1beta1.AdmissionResponse {
func createPatch(job v1alpha1.Job) ([]byte, error) {
var patch []patchOperation
patch = append(patch, mutateSpec(job.Spec.Tasks, "/spec/tasks")...)
//Add default queue if not specified.
if job.Spec.Queue == "" {
patch = append(patch, patchOperation{Op: "add", Path: "/spec/queue", Value: DefaultQueue})
}

return json.Marshal(patch)
}
Expand Down
28 changes: 28 additions & 0 deletions test/e2e/admission.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1"
"volcano.sh/volcano/pkg/apis/batch/v1alpha1"
)

Expand Down Expand Up @@ -152,4 +153,31 @@ var _ = Describe("Job E2E Test: Test Admission service", func() {
Expect(stError.ErrStatus.Code).To(Equal(int32(500)))
Expect(stError.ErrStatus.Message).To(ContainSubstring("unable to find job plugin: big_plugin"))
})

It("Default queue would be added", func() {
jobName := "job-default-queue"
namespace := "test"
context := initTestContext()
defer cleanupTestContext(context)

_, err := createJobInner(context, &jobSpec{
min: 1,
namespace: namespace,
name: jobName,
tasks: []taskSpec{
{
img: defaultNginxImage,
req: oneCPU,
min: 1,
rep: 1,
name: "taskname",
},
},
})
Expect(err).NotTo(HaveOccurred())
createdJob, err := context.vkclient.BatchV1alpha1().Jobs(namespace).Get(jobName, v1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
Expect(createdJob.Spec.Queue).Should(Equal("default"),
"Job queue attribute would default to 'default' ")
})
})

0 comments on commit 3d213a3

Please sign in to comment.