Skip to content

Commit

Permalink
Merge branch 'master' into fix_cache_panic
Browse files Browse the repository at this point in the history
  • Loading branch information
k82cn authored May 31, 2019
2 parents e18910a + fd79373 commit e461ac4
Show file tree
Hide file tree
Showing 14 changed files with 600 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions cmd/admission/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net/http"

"github.com/golang/glog"
"github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned"

"k8s.io/api/admission/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -46,6 +47,14 @@ func GetClient(restConfig *restclient.Config) *kubernetes.Clientset {
return clientset
}

func GetKubeBatchClient(restConfig *restclient.Config) *versioned.Clientset {
clientset, err := versioned.NewForConfig(restConfig)
if err != nil {
glog.Fatal(err)
}
return clientset
}

// ConfigTLS is a helper function that generate tls certificates from directly defined tls config or kubeconfig
// These are passed in as command line for cluster certification. If tls config is passed in, we use the directly
// defined tls config, else use that defined in kubeconfig
Expand Down
2 changes: 2 additions & 0 deletions cmd/admission/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func main() {

clientset := app.GetClient(restConfig)

admissioncontroller.KubeBatchClientSet = app.GetKubeBatchClient(restConfig)

caCertPem, err := ioutil.ReadFile(config.CaCertFile)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
Expand Down
53 changes: 53 additions & 0 deletions cmd/controllers/app/options/options_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright 2019 The Volcano Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package options

import (
"github.com/spf13/pflag"
"reflect"
"testing"
)

func TestAddFlags(t *testing.T) {
fs := pflag.NewFlagSet("addflagstest", pflag.ContinueOnError)
s := NewServerOption()
s.AddFlags(fs)

args := []string{
"--master=127.0.0.1",
"--kube-api-burst=200",
}
fs.Parse(args)

// This is a snapshot of expected options parsed by args.
expected := &ServerOption{
Master: "127.0.0.1",
KubeAPIQPS: defaultQPS,
KubeAPIBurst: 200,
PrintVersion: false,
}

if !reflect.DeepEqual(expected, s) {
t.Errorf("Got different run options than expected.\nGot: %+v\nExpected: %+v\n", s, expected)
}

err := s.CheckOptionOrDie()
if err != nil {
t.Errorf("expected nil but got %v\n", err)
}

}
3 changes: 3 additions & 0 deletions installer/chart/templates/admission.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ rules:
- apiGroups: [""]
resources: ["secrets"]
verbs: ["create", "get", "patch"]
- apiGroups: ["scheduling.incubator.k8s.io"]
resources: ["queues"]
verbs: ["get", "list"]

---
kind: ClusterRoleBinding
Expand Down
9 changes: 9 additions & 0 deletions pkg/admission/admit_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"strings"

"github.com/golang/glog"
"github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned"

"k8s.io/api/admission/v1beta1"
"k8s.io/api/core/v1"
Expand All @@ -35,6 +36,9 @@ import (
"volcano.sh/volcano/pkg/controllers/job/plugins"
)

//KubeBatchClientSet is kube-batch clientset
var KubeBatchClientSet versioned.Interface

// job admit.
func AdmitJobs(ar v1beta1.AdmissionReview) *v1beta1.AdmissionResponse {

Expand Down Expand Up @@ -146,6 +150,11 @@ func validateJob(job v1alpha1.Job, reviewResponse *v1beta1.AdmissionResponse) st
msg = msg + validateInfo
}

// Check whether Queue already present or not
if _, err := KubeBatchClientSet.SchedulingV1alpha1().Queues().Get(job.Spec.Queue, metav1.GetOptions{}); err != nil {
msg = msg + fmt.Sprintf("Job not created with error: %v", err)
}

if msg != "" {
reviewResponse.Allowed = false
}
Expand Down
26 changes: 26 additions & 0 deletions pkg/admission/admit_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ import (
"strings"
"testing"

kubebatchclient "github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/fake"

"k8s.io/api/admission/v1beta1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

kbv1aplha1 "github.com/kubernetes-sigs/kube-batch/pkg/apis/scheduling/v1alpha1"
v1alpha1 "volcano.sh/volcano/pkg/apis/batch/v1alpha1"
)

Expand All @@ -48,6 +51,7 @@ func TestValidateExecution(t *testing.T) {
},
Spec: v1alpha1.JobSpec{
MinAvailable: 1,
Queue: "default",
Tasks: []v1alpha1.TaskSpec{
{
Name: "task-1",
Expand Down Expand Up @@ -83,6 +87,7 @@ func TestValidateExecution(t *testing.T) {
},
Spec: v1alpha1.JobSpec{
MinAvailable: 1,
Queue: "default",
Tasks: []v1alpha1.TaskSpec{
{
Name: "duplicated-task-1",
Expand Down Expand Up @@ -135,6 +140,7 @@ func TestValidateExecution(t *testing.T) {
},
Spec: v1alpha1.JobSpec{
MinAvailable: 1,
Queue: "default",
Tasks: []v1alpha1.TaskSpec{
{
Name: "task-1",
Expand Down Expand Up @@ -180,6 +186,7 @@ func TestValidateExecution(t *testing.T) {
},
Spec: v1alpha1.JobSpec{
MinAvailable: 2,
Queue: "default",
Tasks: []v1alpha1.TaskSpec{
{
Name: "task-1",
Expand Down Expand Up @@ -215,6 +222,7 @@ func TestValidateExecution(t *testing.T) {
},
Spec: v1alpha1.JobSpec{
MinAvailable: 1,
Queue: "default",
Tasks: []v1alpha1.TaskSpec{
{
Name: "task-1",
Expand Down Expand Up @@ -253,6 +261,7 @@ func TestValidateExecution(t *testing.T) {
},
Spec: v1alpha1.JobSpec{
MinAvailable: 1,
Queue: "default",
Tasks: []v1alpha1.TaskSpec{
{
Name: "task-1",
Expand Down Expand Up @@ -283,6 +292,23 @@ func TestValidateExecution(t *testing.T) {

for _, testCase := range testCases {

defaultqueue := kbv1aplha1.Queue{
ObjectMeta: metav1.ObjectMeta{
Name: "default",
},
Spec: kbv1aplha1.QueueSpec{
Weight: 1,
},
}
// create fake kube-batch clientset
KubeBatchClientSet = kubebatchclient.NewSimpleClientset()

//create default queue
_, err := KubeBatchClientSet.SchedulingV1alpha1().Queues().Create(&defaultqueue)
if err != nil {
t.Error("Queue Creation Failed")
}

ret := validateJob(testCase.Job, &testCase.reviewResponse)
//fmt.Printf("test-case name:%s, ret:%v testCase.reviewResponse:%v \n", testCase.Name, ret,testCase.reviewResponse)
if testCase.ExpectErr == true && ret == "" {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e461ac4

Please sign in to comment.