@@ -29,11 +29,11 @@ import (
29
29
apivalidation "k8s.io/kubernetes/pkg/apis/core/validation"
30
30
)
31
31
32
- // TODO: generalize for other controller objects that will follow the same pattern, such as ReplicaSet and DaemonSet, and
33
- // move to new location. Replace batch.Job with an interface.
34
- //
35
32
// ValidateGeneratedSelector validates that the generated selector on a controller object match the controller object
36
33
// metadata, and the labels on the pod template are as generated.
34
+ //
35
+ // TODO: generalize for other controller objects that will follow the same pattern, such as ReplicaSet and DaemonSet, and
36
+ // move to new location. Replace batch.Job with an interface.
37
37
func ValidateGeneratedSelector (obj * batch.Job ) field.ErrorList {
38
38
allErrs := field.ErrorList {}
39
39
if obj .Spec .ManualSelector != nil && * obj .Spec .ManualSelector {
@@ -75,6 +75,7 @@ func ValidateGeneratedSelector(obj *batch.Job) field.ErrorList {
75
75
return allErrs
76
76
}
77
77
78
+ // ValidateJob validates a Job and returns an ErrorList with any errors.
78
79
func ValidateJob (job * batch.Job ) field.ErrorList {
79
80
// Jobs and rcs have the same name validation
80
81
allErrs := apivalidation .ValidateObjectMeta (& job .ObjectMeta , true , apivalidation .ValidateReplicationControllerName , field .NewPath ("metadata" ))
@@ -83,6 +84,7 @@ func ValidateJob(job *batch.Job) field.ErrorList {
83
84
return allErrs
84
85
}
85
86
87
+ // ValidateJobSpec validates a JobSpec and returns an ErrorList with any errors.
86
88
func ValidateJobSpec (spec * batch.JobSpec , fldPath * field.Path ) field.ErrorList {
87
89
allErrs := validateJobSpec (spec , fldPath )
88
90
@@ -130,6 +132,7 @@ func validateJobSpec(spec *batch.JobSpec, fldPath *field.Path) field.ErrorList {
130
132
return allErrs
131
133
}
132
134
135
+ // ValidateJobStatus validates a JobStatus and returns an ErrorList with any errors.
133
136
func ValidateJobStatus (status * batch.JobStatus , fldPath * field.Path ) field.ErrorList {
134
137
allErrs := field.ErrorList {}
135
138
allErrs = append (allErrs , apivalidation .ValidateNonnegativeField (int64 (status .Active ), fldPath .Child ("active" ))... )
@@ -138,18 +141,21 @@ func ValidateJobStatus(status *batch.JobStatus, fldPath *field.Path) field.Error
138
141
return allErrs
139
142
}
140
143
144
+ // ValidateJobUpdate validates an update to a Job and returns an ErrorList with any errors.
141
145
func ValidateJobUpdate (job , oldJob * batch.Job ) field.ErrorList {
142
146
allErrs := apivalidation .ValidateObjectMetaUpdate (& job .ObjectMeta , & oldJob .ObjectMeta , field .NewPath ("metadata" ))
143
147
allErrs = append (allErrs , ValidateJobSpecUpdate (job .Spec , oldJob .Spec , field .NewPath ("spec" ))... )
144
148
return allErrs
145
149
}
146
150
151
+ // ValidateJobUpdateStatus validates an update to the status of a Job and returns an ErrorList with any errors.
147
152
func ValidateJobUpdateStatus (job , oldJob * batch.Job ) field.ErrorList {
148
153
allErrs := apivalidation .ValidateObjectMetaUpdate (& job .ObjectMeta , & oldJob .ObjectMeta , field .NewPath ("metadata" ))
149
154
allErrs = append (allErrs , ValidateJobStatusUpdate (job .Status , oldJob .Status )... )
150
155
return allErrs
151
156
}
152
157
158
+ // ValidateJobSpecUpdate validates an update to a JobSpec and returns an ErrorList with any errors.
153
159
func ValidateJobSpecUpdate (spec , oldSpec batch.JobSpec , fldPath * field.Path ) field.ErrorList {
154
160
allErrs := field.ErrorList {}
155
161
allErrs = append (allErrs , ValidateJobSpec (& spec , fldPath )... )
@@ -159,12 +165,14 @@ func ValidateJobSpecUpdate(spec, oldSpec batch.JobSpec, fldPath *field.Path) fie
159
165
return allErrs
160
166
}
161
167
168
+ // ValidateJobStatusUpdate validates an update to a JobStatus and returns an ErrorList with any errors.
162
169
func ValidateJobStatusUpdate (status , oldStatus batch.JobStatus ) field.ErrorList {
163
170
allErrs := field.ErrorList {}
164
171
allErrs = append (allErrs , ValidateJobStatus (& status , field .NewPath ("status" ))... )
165
172
return allErrs
166
173
}
167
174
175
+ // ValidateCronJob validates a CronJob and returns an ErrorList with any errors.
168
176
func ValidateCronJob (scheduledJob * batch.CronJob ) field.ErrorList {
169
177
// CronJobs and rcs have the same name validation
170
178
allErrs := apivalidation .ValidateObjectMeta (& scheduledJob .ObjectMeta , true , apivalidation .ValidateReplicationControllerName , field .NewPath ("metadata" ))
@@ -179,6 +187,7 @@ func ValidateCronJob(scheduledJob *batch.CronJob) field.ErrorList {
179
187
return allErrs
180
188
}
181
189
190
+ // ValidateCronJobUpdate validates an update to a CronJob and returns an ErrorList with any errors.
182
191
func ValidateCronJobUpdate (job , oldJob * batch.CronJob ) field.ErrorList {
183
192
allErrs := apivalidation .ValidateObjectMetaUpdate (& job .ObjectMeta , & oldJob .ObjectMeta , field .NewPath ("metadata" ))
184
193
allErrs = append (allErrs , ValidateCronJobSpec (& job .Spec , field .NewPath ("spec" ))... )
@@ -187,6 +196,7 @@ func ValidateCronJobUpdate(job, oldJob *batch.CronJob) field.ErrorList {
187
196
return allErrs
188
197
}
189
198
199
+ // ValidateCronJobSpec validates a CronJobSpec and returns an ErrorList with any errors.
190
200
func ValidateCronJobSpec (spec * batch.CronJobSpec , fldPath * field.Path ) field.ErrorList {
191
201
allErrs := field.ErrorList {}
192
202
@@ -237,13 +247,15 @@ func validateScheduleFormat(schedule string, fldPath *field.Path) field.ErrorLis
237
247
return allErrs
238
248
}
239
249
250
+ // ValidateJobTemplate validates a JobTemplate and returns an ErrorList with any errors.
240
251
func ValidateJobTemplate (job * batch.JobTemplate ) field.ErrorList {
241
252
// this method should be identical to ValidateJob
242
253
allErrs := apivalidation .ValidateObjectMeta (& job .ObjectMeta , true , apivalidation .ValidateReplicationControllerName , field .NewPath ("metadata" ))
243
254
allErrs = append (allErrs , ValidateJobTemplateSpec (& job .Template , field .NewPath ("template" ))... )
244
255
return allErrs
245
256
}
246
257
258
+ // ValidateJobTemplateSpec validates a JobTemplateSpec and returns an ErrorList with any errors.
247
259
func ValidateJobTemplateSpec (spec * batch.JobTemplateSpec , fldPath * field.Path ) field.ErrorList {
248
260
allErrs := validateJobSpec (& spec .Spec , fldPath .Child ("spec" ))
249
261
0 commit comments