@@ -20,6 +20,7 @@ import (
20
20
"fmt"
21
21
"reflect"
22
22
"strings"
23
+ "volcano.sh/volcano/pkg/controllers/job/plugins"
23
24
24
25
"github.com/golang/glog"
25
26
@@ -43,7 +44,7 @@ func AdmitJobs(ar v1beta1.AdmissionReview) *v1beta1.AdmissionResponse {
43
44
44
45
switch ar .Request .Operation {
45
46
case v1beta1 .Create :
46
- msg = validateJob (job , & reviewResponse )
47
+ msg = validateJobSpec (job . Spec , & reviewResponse )
47
48
break
48
49
case v1beta1 .Update :
49
50
oldJob , err := DecodeJob (ar .Request .OldObject , ar .Request .Resource )
@@ -63,18 +64,18 @@ func AdmitJobs(ar v1beta1.AdmissionReview) *v1beta1.AdmissionResponse {
63
64
return & reviewResponse
64
65
}
65
66
66
- func validateJob ( job v1alpha1.Job , reviewResponse * v1beta1.AdmissionResponse ) string {
67
+ func validateJobSpec ( jobSpec v1alpha1.JobSpec , reviewResponse * v1beta1.AdmissionResponse ) string {
67
68
68
69
var msg string
69
70
taskNames := map [string ]string {}
70
71
var totalReplicas int32
71
72
72
- if len (job . Spec .Tasks ) == 0 {
73
+ if len (jobSpec .Tasks ) == 0 {
73
74
reviewResponse .Allowed = false
74
75
return fmt .Sprintf ("No task specified in job spec" )
75
76
}
76
77
77
- for _ , task := range job . Spec .Tasks {
78
+ for _ , task := range jobSpec .Tasks {
78
79
if task .Replicas == 0 {
79
80
msg = msg + fmt .Sprintf (" 'replicas' is set '0' in task: %s;" , task .Name )
80
81
}
@@ -96,15 +97,24 @@ func validateJob(job v1alpha1.Job, reviewResponse *v1beta1.AdmissionResponse) st
96
97
}
97
98
}
98
99
99
- if totalReplicas < job . Spec .MinAvailable {
100
+ if totalReplicas < jobSpec .MinAvailable {
100
101
msg = msg + " 'minAvailable' should not be greater than total replicas in tasks;"
101
102
}
102
103
103
104
//duplicate job event policies
104
- if duplicateInfo , ok := CheckPolicyDuplicate (job . Spec .Policies ); ok {
105
+ if duplicateInfo , ok := CheckPolicyDuplicate (jobSpec .Policies ); ok {
105
106
msg = msg + fmt .Sprintf (" duplicated job event policies: %s;" , duplicateInfo )
106
107
}
107
108
109
+ //invalid job plugins
110
+ if len (jobSpec .Plugins ) != 0 {
111
+ for name := range jobSpec .Plugins {
112
+ if _ , found := plugins .GetPluginBuilder (name ); ! found {
113
+ msg = msg + fmt .Sprintf (" unable to find job plugin: %s" , name )
114
+ }
115
+ }
116
+ }
117
+
108
118
if msg != "" {
109
119
reviewResponse .Allowed = false
110
120
}
0 commit comments