From 36a48bde3d2f49d7119ddbf8668f9280a378a6f0 Mon Sep 17 00:00:00 2001 From: TommyLike Date: Sun, 5 May 2019 14:37:46 +0800 Subject: [PATCH] Add default queue in admission hook --- pkg/admission/mutate_job.go | 8 ++++++++ test/e2e/admission.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/pkg/admission/mutate_job.go b/pkg/admission/mutate_job.go index f7ed88f2c24..6b392685860 100644 --- a/pkg/admission/mutate_job.go +++ b/pkg/admission/mutate_job.go @@ -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"` @@ -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) } diff --git a/test/e2e/admission.go b/test/e2e/admission.go index 1ddfefc57ed..c7b25f4efed 100644 --- a/test/e2e/admission.go +++ b/test/e2e/admission.go @@ -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" ) @@ -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' ") + }) })