Skip to content

Commit

Permalink
Merge pull request volcano-sh#50 from volcano-sh/feature/support-plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Klaus Ma authored Mar 29, 2019
2 parents 5bec9fb + dcfb24b commit 453738c
Show file tree
Hide file tree
Showing 78 changed files with 15,694 additions and 64 deletions.
40 changes: 20 additions & 20 deletions Gopkg.lock

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

5 changes: 5 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,15 @@ required = [
name = "k8s.io/code-generator"
version = "kubernetes-1.13.2"

[[constraint]]
name = "golang.org/x/crypto"
branch = "release-branch.go1.12"

[prune]
go-tests = true
unused-packages = true

[[prune.project]]
name = "k8s.io/code-generator"
unused-packages = false

1 change: 1 addition & 0 deletions example/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ spec:
storage: 1Gi
tasks:
- replicas: 6
name: "default-nginx"
template:
metadata:
name: web
Expand Down
16 changes: 9 additions & 7 deletions example/kube-batch-conf.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
actions: "reclaim, allocate, backfill, preempt"
tiers:
- plugins:
- name: priority
- name: gang
- plugins:
- name: drf
- name: predicates
- name: proportion
- plugins:
- name: priority
- name: gang
- name: conformance
- plugins:
- name: drf
- name: predicates
- name: proportion
- name: nodeorder
5 changes: 5 additions & 0 deletions hack/.golint_failures
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ volcano.sh/volcano/pkg/cli/job
volcano.sh/volcano/pkg/controllers/job
volcano.sh/volcano/pkg/controllers/job/apis
volcano.sh/volcano/pkg/controllers/job/cache
volcano.sh/volcano/pkg/controllers/job/helpers
volcano.sh/volcano/pkg/controllers/job/plugins
volcano.sh/volcano/pkg/controllers/job/plugins/env
volcano.sh/volcano/pkg/controllers/job/plugins/interface
volcano.sh/volcano/pkg/controllers/job/plugins/ssh
volcano.sh/volcano/pkg/controllers/job/state
volcano.sh/volcano/pkg/scheduler/actions/allocate
volcano.sh/volcano/pkg/scheduler/actions/backfill
Expand Down
2 changes: 0 additions & 2 deletions installer/chart/volcano/templates/admission-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ metadata:
"helm.sh/hook": pre-install,pre-upgrade,post-delete
webhooks:
- clientConfig:
caBundle: ""
service:
name: {{ .Release.Name }}-admission-service
namespace: {{ .Release.Namespace }}
Expand All @@ -33,7 +32,6 @@ metadata:
"helm.sh/hook": pre-install,pre-upgrade,post-delete
webhooks:
- clientConfig:
caBundle: ""
service:
name: {{ .Release.Name }}-admission-service
namespace: {{ .Release.Namespace }}
Expand Down
4 changes: 4 additions & 0 deletions installer/chart/volcano/templates/admission.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ spec:
admission: "true"
spec:
serviceAccount: {{ .Release.Name }}-admission
{{ if .Values.basic.image_pull_secret }}
imagePullSecrets:
- name: {{ .Values.basic.image_pull_secret }}
{{ end }}
containers:
- args:
- --tls-cert-file=/admission.local.config/certificates/tls.crt
Expand Down
6 changes: 5 additions & 1 deletion installer/chart/volcano/templates/controllers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ rules:
resources: ["persistentvolumeclaims"]
verbs: ["get", "list", "watch", "create"]
- apiGroups: [""]
resources: ["services"]
resources: ["services", "configmaps"]
verbs: ["get", "list", "watch", "create", "delete"]
- apiGroups: ["scheduling.incubator.k8s.io"]
resources: ["podgroups"]
Expand Down Expand Up @@ -74,6 +74,10 @@ spec:
vk-controllers: test
spec:
serviceAccount: {{ .Release.Name }}-controllers
{{ if .Values.basic.image_pull_secret }}
imagePullSecrets:
- name: {{ .Values.basic.image_pull_secret }}
{{ end }}
containers:
- name: {{ .Release.Name }}-controllers
image: {{.Values.basic.controller_image_name}}:{{.Values.basic.image_tag_version}}
Expand Down
3 changes: 2 additions & 1 deletion installer/chart/volcano/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ basic:
controller_image_name: "volcano-controllers"
scheduler_image_name: "volcano-scheduler"
admission_image_name: "volcano-admission"
admission_secret_name: "volcano-admission-secret"
admission_secret_name: "volcano-admission-secret"
image_pull_secret: ""
22 changes: 16 additions & 6 deletions pkg/admission/admit_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"reflect"
"strings"
"volcano.sh/volcano/pkg/controllers/job/plugins"

"github.com/golang/glog"

Expand All @@ -43,7 +44,7 @@ func AdmitJobs(ar v1beta1.AdmissionReview) *v1beta1.AdmissionResponse {

switch ar.Request.Operation {
case v1beta1.Create:
msg = validateJob(job, &reviewResponse)
msg = validateJobSpec(job.Spec, &reviewResponse)
break
case v1beta1.Update:
oldJob, err := DecodeJob(ar.Request.OldObject, ar.Request.Resource)
Expand All @@ -63,18 +64,18 @@ func AdmitJobs(ar v1beta1.AdmissionReview) *v1beta1.AdmissionResponse {
return &reviewResponse
}

func validateJob(job v1alpha1.Job, reviewResponse *v1beta1.AdmissionResponse) string {
func validateJobSpec(jobSpec v1alpha1.JobSpec, reviewResponse *v1beta1.AdmissionResponse) string {

var msg string
taskNames := map[string]string{}
var totalReplicas int32

if len(job.Spec.Tasks) == 0 {
if len(jobSpec.Tasks) == 0 {
reviewResponse.Allowed = false
return fmt.Sprintf("No task specified in job spec")
}

for _, task := range job.Spec.Tasks {
for _, task := range jobSpec.Tasks {
if task.Replicas == 0 {
msg = msg + fmt.Sprintf(" 'replicas' is set '0' in task: %s;", task.Name)
}
Expand All @@ -96,15 +97,24 @@ func validateJob(job v1alpha1.Job, reviewResponse *v1beta1.AdmissionResponse) st
}
}

if totalReplicas < job.Spec.MinAvailable {
if totalReplicas < jobSpec.MinAvailable {
msg = msg + " 'minAvailable' should not be greater than total replicas in tasks;"
}

//duplicate job event policies
if duplicateInfo, ok := CheckPolicyDuplicate(job.Spec.Policies); ok {
if duplicateInfo, ok := CheckPolicyDuplicate(jobSpec.Policies); ok {
msg = msg + fmt.Sprintf(" duplicated job event policies: %s;", duplicateInfo)
}

//invalid job plugins
if len(jobSpec.Plugins) != 0 {
for name := range jobSpec.Plugins {
if _, found := plugins.GetPluginBuilder(name); !found {
msg = msg + fmt.Sprintf(" unable to find job plugin: %s", name)
}
}
}

if msg != "" {
reviewResponse.Allowed = false
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/batch/v1alpha1/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ type JobSpec struct {

//Specifies the queue that will be used in the scheduler, "default" queue is used this leaves empty.
Queue string `json:"queue,omitempty" protobuf:"bytes,7,opt,name=queue"`

// Specifies the plugin of job
// Key is plugin name, value is the arguments of the plugin
// +optional
Plugins map[string][]string `json:"plugins,omitempty" protobuf:"bytes,7,opt,name=plugins"`
}

// VolumeSpec defines the specification of Volume, e.g. PVC
Expand All @@ -79,6 +84,7 @@ type JobEvent string

const (
CommandIssued JobEvent = "CommandIssued"
PluginError JobEvent = "PluginError"
)

// Event represent the phase of Job, e.g. pod-failed.
Expand Down Expand Up @@ -232,6 +238,8 @@ type JobStatus struct {
Terminating int32 `json:"terminating,omitempty" protobuf:"bytes,7,opt,name=terminating"`
//Current version of job
Version int32 `json:"version,omitempty" protobuf:"bytes,8,opt,name=version"`
// The resources that controlled by this job, e.g. Service, ConfigMap
ControlledResources map[string]string
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
24 changes: 23 additions & 1 deletion pkg/apis/batch/v1alpha1/zz_generated.deepcopy.go

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

Loading

0 comments on commit 453738c

Please sign in to comment.