Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
adc890a5
Commit
adc890a5
authored
May 11, 2016
by
Maciej Szulik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ScheduledJob validation & defaults
parent
aabf86ab
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
0 deletions
+71
-0
defaults.go
pkg/apis/batch/v2alpha1/defaults.go
+7
-0
validation.go
pkg/apis/batch/validation/validation.go
+64
-0
validation_test.go
pkg/apis/batch/validation/validation_test.go
+0
-0
No files found.
pkg/apis/batch/v2alpha1/defaults.go
View file @
adc890a5
...
...
@@ -23,6 +23,7 @@ import (
func
addDefaultingFuncs
(
scheme
*
runtime
.
Scheme
)
{
scheme
.
AddDefaultingFuncs
(
SetDefaults_Job
,
SetDefaults_ScheduledJob
,
)
}
...
...
@@ -40,3 +41,9 @@ func SetDefaults_Job(obj *Job) {
*
obj
.
Spec
.
Parallelism
=
1
}
}
func
SetDefaults_ScheduledJob
(
obj
*
ScheduledJob
)
{
if
obj
.
Spec
.
ConcurrencyPolicy
==
""
{
obj
.
Spec
.
ConcurrencyPolicy
=
AllowConcurrent
}
}
pkg/apis/batch/validation/validation.go
View file @
adc890a5
...
...
@@ -17,6 +17,8 @@ limitations under the License.
package
validation
import
(
"github.com/robfig/cron"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
unversionedvalidation
"k8s.io/kubernetes/pkg/api/unversioned/validation"
...
...
@@ -155,3 +157,65 @@ func ValidateJobStatusUpdate(status, oldStatus batch.JobStatus) field.ErrorList
allErrs
=
append
(
allErrs
,
ValidateJobStatus
(
&
status
,
field
.
NewPath
(
"status"
))
...
)
return
allErrs
}
func
ValidateScheduledJob
(
scheduledJob
*
batch
.
ScheduledJob
)
field
.
ErrorList
{
// ScheduledJobs and rcs have the same name validation
allErrs
:=
apivalidation
.
ValidateObjectMeta
(
&
scheduledJob
.
ObjectMeta
,
true
,
apivalidation
.
ValidateReplicationControllerName
,
field
.
NewPath
(
"metadata"
))
allErrs
=
append
(
allErrs
,
ValidateScheduledJobSpec
(
&
scheduledJob
.
Spec
,
field
.
NewPath
(
"spec"
))
...
)
return
allErrs
}
func
ValidateScheduledJobSpec
(
spec
*
batch
.
ScheduledJobSpec
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
allErrs
:=
field
.
ErrorList
{}
if
len
(
spec
.
Schedule
)
==
0
{
allErrs
=
append
(
allErrs
,
field
.
Required
(
fldPath
.
Child
(
"schedule"
),
""
))
}
else
{
allErrs
=
append
(
allErrs
,
validateScheduleFormat
(
spec
.
Schedule
,
fldPath
.
Child
(
"schedule"
))
...
)
}
if
spec
.
StartingDeadlineSeconds
!=
nil
{
allErrs
=
append
(
allErrs
,
apivalidation
.
ValidateNonnegativeField
(
int64
(
*
spec
.
StartingDeadlineSeconds
),
fldPath
.
Child
(
"startingDeadlineSeconds"
))
...
)
}
allErrs
=
append
(
allErrs
,
validateConcurrencyPolicy
(
&
spec
.
ConcurrencyPolicy
,
fldPath
.
Child
(
"concurrencyPolicy"
))
...
)
allErrs
=
append
(
allErrs
,
ValidateJobTemplateSpec
(
&
spec
.
JobTemplate
,
fldPath
.
Child
(
"jobTemplate"
))
...
)
return
allErrs
}
func
validateConcurrencyPolicy
(
concurrencyPolicy
*
batch
.
ConcurrencyPolicy
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
allErrs
:=
field
.
ErrorList
{}
switch
*
concurrencyPolicy
{
case
batch
.
AllowConcurrent
,
batch
.
ForbidConcurrent
,
batch
.
ReplaceConcurrent
:
break
case
""
:
allErrs
=
append
(
allErrs
,
field
.
Required
(
fldPath
,
""
))
default
:
validValues
:=
[]
string
{
string
(
batch
.
AllowConcurrent
),
string
(
batch
.
ForbidConcurrent
),
string
(
batch
.
ReplaceConcurrent
)}
allErrs
=
append
(
allErrs
,
field
.
NotSupported
(
fldPath
,
*
concurrencyPolicy
,
validValues
))
}
return
allErrs
}
func
validateScheduleFormat
(
schedule
string
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
allErrs
:=
field
.
ErrorList
{}
_
,
err
:=
cron
.
Parse
(
schedule
)
if
err
!=
nil
{
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
,
schedule
,
err
.
Error
()))
}
return
allErrs
}
func
ValidateJobTemplate
(
job
*
batch
.
JobTemplate
)
field
.
ErrorList
{
// this method should be identical to ValidateJob
allErrs
:=
apivalidation
.
ValidateObjectMeta
(
&
job
.
ObjectMeta
,
true
,
apivalidation
.
ValidateReplicationControllerName
,
field
.
NewPath
(
"metadata"
))
allErrs
=
append
(
allErrs
,
ValidateJobTemplateSpec
(
&
job
.
Template
,
field
.
NewPath
(
"template"
))
...
)
return
allErrs
}
func
ValidateJobTemplateSpec
(
spec
*
batch
.
JobTemplateSpec
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
// this method should be identical to ValidateJob
allErrs
:=
ValidateJobSpec
(
&
spec
.
Spec
,
fldPath
.
Child
(
"spec"
))
return
allErrs
}
pkg/apis/batch/validation/validation_test.go
View file @
adc890a5
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment