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
50f8f0c7
Commit
50f8f0c7
authored
Sep 24, 2015
by
Eric Tune
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14343 from erictune/job-update
Job update
parents
c340d664
95a44be2
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
80 additions
and
15 deletions
+80
-15
validation.go
pkg/apis/experimental/validation/validation.go
+28
-0
controller.go
pkg/controller/job/controller.go
+4
-4
master.go
pkg/master/master.go
+2
-1
etcd.go
pkg/registry/job/etcd/etcd.go
+19
-2
etcd_test.go
pkg/registry/job/etcd/etcd_test.go
+11
-8
strategy.go
pkg/registry/job/strategy.go
+16
-0
No files found.
pkg/apis/experimental/validation/validation.go
View file @
50f8f0c7
...
...
@@ -312,6 +312,21 @@ func ValidateJobSpec(spec *experimental.JobSpec) errs.ValidationErrorList {
return
allErrs
}
func
ValidateJobStatus
(
status
*
experimental
.
JobStatus
)
errs
.
ValidationErrorList
{
allErrs
:=
errs
.
ValidationErrorList
{}
if
status
.
Active
<
0
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
"active"
,
status
.
Active
,
isNegativeErrorMsg
))
}
if
status
.
Successful
<
0
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
"successful"
,
status
.
Successful
,
isNegativeErrorMsg
))
}
if
status
.
Unsuccessful
<
0
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
"unsuccessful"
,
status
.
Unsuccessful
,
isNegativeErrorMsg
))
}
return
allErrs
}
func
ValidateJobUpdate
(
oldJob
,
job
*
experimental
.
Job
)
errs
.
ValidationErrorList
{
allErrs
:=
errs
.
ValidationErrorList
{}
allErrs
=
append
(
allErrs
,
apivalidation
.
ValidateObjectMetaUpdate
(
&
oldJob
.
ObjectMeta
,
&
job
.
ObjectMeta
)
.
Prefix
(
"metadata"
)
...
)
...
...
@@ -319,6 +334,13 @@ func ValidateJobUpdate(oldJob, job *experimental.Job) errs.ValidationErrorList {
return
allErrs
}
func
ValidateJobUpdateStatus
(
oldJob
,
job
*
experimental
.
Job
)
errs
.
ValidationErrorList
{
allErrs
:=
errs
.
ValidationErrorList
{}
allErrs
=
append
(
allErrs
,
apivalidation
.
ValidateObjectMetaUpdate
(
&
oldJob
.
ObjectMeta
,
&
job
.
ObjectMeta
)
.
Prefix
(
"metadata"
)
...
)
allErrs
=
append
(
allErrs
,
ValidateJobStatusUpdate
(
oldJob
.
Status
,
job
.
Status
)
.
Prefix
(
"status"
)
...
)
return
allErrs
}
func
ValidateJobSpecUpdate
(
oldSpec
,
spec
experimental
.
JobSpec
)
errs
.
ValidationErrorList
{
allErrs
:=
errs
.
ValidationErrorList
{}
allErrs
=
append
(
allErrs
,
ValidateJobSpec
(
&
spec
)
...
)
...
...
@@ -333,3 +355,9 @@ func ValidateJobSpecUpdate(oldSpec, spec experimental.JobSpec) errs.ValidationEr
}
return
allErrs
}
func
ValidateJobStatusUpdate
(
oldStatus
,
status
experimental
.
JobStatus
)
errs
.
ValidationErrorList
{
allErrs
:=
errs
.
ValidationErrorList
{}
allErrs
=
append
(
allErrs
,
ValidateJobStatus
(
&
status
)
...
)
return
allErrs
}
pkg/controller/job/controller.go
View file @
50f8f0c7
...
...
@@ -44,7 +44,7 @@ type JobController struct {
kubeClient
client
.
Interface
podControl
controller
.
PodControlInterface
// To allow injection of updateJob for testing.
// To allow injection of updateJob
Status
for testing.
updateHandler
func
(
job
*
experimental
.
Job
)
error
syncHandler
func
(
jobKey
string
)
error
// podStoreSynced returns true if the pod store has been synced at least once.
...
...
@@ -127,7 +127,7 @@ func NewJobController(kubeClient client.Interface) *JobController {
},
)
jm
.
updateHandler
=
jm
.
updateJob
jm
.
updateHandler
=
jm
.
updateJob
Status
jm
.
syncHandler
=
jm
.
syncJob
jm
.
podStoreSynced
=
jm
.
podController
.
HasSynced
return
jm
...
...
@@ -433,8 +433,8 @@ func (jm *JobController) manageJob(activePods []*api.Pod, successful, unsuccessf
return
active
}
func
(
jm
*
JobController
)
updateJob
(
job
*
experimental
.
Job
)
error
{
_
,
err
:=
jm
.
kubeClient
.
Experimental
()
.
Jobs
(
job
.
Namespace
)
.
Update
(
job
)
func
(
jm
*
JobController
)
updateJob
Status
(
job
*
experimental
.
Job
)
error
{
_
,
err
:=
jm
.
kubeClient
.
Experimental
()
.
Jobs
(
job
.
Namespace
)
.
Update
Status
(
job
)
return
err
}
...
...
pkg/master/master.go
View file @
50f8f0c7
...
...
@@ -960,7 +960,7 @@ func (m *Master) experimental(c *Config) *apiserver.APIGroupVersion {
thirdPartyResourceStorage
:=
thirdpartyresourceetcd
.
NewREST
(
c
.
ExpDatabaseStorage
)
daemonSetStorage
:=
daemonetcd
.
NewREST
(
c
.
ExpDatabaseStorage
)
deploymentStorage
:=
deploymentetcd
.
NewStorage
(
c
.
ExpDatabaseStorage
)
jobStorage
:=
jobetcd
.
NewREST
(
c
.
ExpDatabaseStorage
)
jobStorage
,
jobStatusStorage
:=
jobetcd
.
NewREST
(
c
.
ExpDatabaseStorage
)
thirdPartyControl
:=
ThirdPartyController
{
master
:
m
,
...
...
@@ -982,6 +982,7 @@ func (m *Master) experimental(c *Config) *apiserver.APIGroupVersion {
strings
.
ToLower
(
"deployments"
)
:
deploymentStorage
.
Deployment
,
strings
.
ToLower
(
"deployments/scale"
)
:
deploymentStorage
.
Scale
,
strings
.
ToLower
(
"jobs"
)
:
jobStorage
,
strings
.
ToLower
(
"jobs/status"
)
:
jobStatusStorage
,
}
return
&
apiserver
.
APIGroupVersion
{
...
...
pkg/registry/job/etcd/etcd.go
View file @
50f8f0c7
...
...
@@ -38,7 +38,7 @@ type REST struct {
var
jobPrefix
=
"/jobs"
// NewREST returns a RESTStorage object that will work against Jobs.
func
NewREST
(
s
storage
.
Interface
)
*
REST
{
func
NewREST
(
s
storage
.
Interface
)
(
*
REST
,
*
StatusREST
)
{
store
:=
&
etcdgeneric
.
Etcd
{
NewFunc
:
func
()
runtime
.
Object
{
return
&
experimental
.
Job
{}
},
...
...
@@ -73,5 +73,22 @@ func NewREST(s storage.Interface) *REST {
Storage
:
s
,
}
return
&
REST
{
store
}
statusStore
:=
*
store
statusStore
.
UpdateStrategy
=
job
.
StatusStrategy
return
&
REST
{
store
},
&
StatusREST
{
store
:
&
statusStore
}
}
// StatusREST implements the REST endpoint for changing the status of a resourcequota.
type
StatusREST
struct
{
store
*
etcdgeneric
.
Etcd
}
func
(
r
*
StatusREST
)
New
()
runtime
.
Object
{
return
&
experimental
.
Job
{}
}
// Update alters the status subset of an object.
func
(
r
*
StatusREST
)
Update
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
(
runtime
.
Object
,
bool
,
error
)
{
return
r
.
store
.
Update
(
ctx
,
obj
)
}
pkg/registry/job/etcd/etcd_test.go
View file @
50f8f0c7
...
...
@@ -30,9 +30,10 @@ import (
"k8s.io/kubernetes/pkg/tools"
)
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
tools
.
FakeEtcdClient
)
{
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
StatusREST
,
*
tools
.
FakeEtcdClient
)
{
etcdStorage
,
fakeClient
:=
registrytest
.
NewEtcdStorage
(
t
,
"experimental"
)
return
NewREST
(
etcdStorage
),
fakeClient
storage
,
statusStorage
:=
NewREST
(
etcdStorage
)
return
storage
,
statusStorage
,
fakeClient
}
func
validNewJob
()
*
experimental
.
Job
{
...
...
@@ -68,7 +69,7 @@ func validNewJob() *experimental.Job {
}
func
TestCreate
(
t
*
testing
.
T
)
{
storage
,
fakeClient
:=
newStorage
(
t
)
storage
,
_
,
fakeClient
:=
newStorage
(
t
)
test
:=
registrytest
.
New
(
t
,
fakeClient
,
storage
.
Etcd
)
validJob
:=
validNewJob
()
validJob
.
ObjectMeta
=
api
.
ObjectMeta
{}
...
...
@@ -87,7 +88,7 @@ func TestCreate(t *testing.T) {
}
func
TestUpdate
(
t
*
testing
.
T
)
{
storage
,
fakeClient
:=
newStorage
(
t
)
storage
,
_
,
fakeClient
:=
newStorage
(
t
)
test
:=
registrytest
.
New
(
t
,
fakeClient
,
storage
.
Etcd
)
two
:=
2
test
.
TestUpdate
(
...
...
@@ -114,25 +115,25 @@ func TestUpdate(t *testing.T) {
}
func
TestDelete
(
t
*
testing
.
T
)
{
storage
,
fakeClient
:=
newStorage
(
t
)
storage
,
_
,
fakeClient
:=
newStorage
(
t
)
test
:=
registrytest
.
New
(
t
,
fakeClient
,
storage
.
Etcd
)
test
.
TestDelete
(
validNewJob
())
}
func
TestGet
(
t
*
testing
.
T
)
{
storage
,
fakeClient
:=
newStorage
(
t
)
storage
,
_
,
fakeClient
:=
newStorage
(
t
)
test
:=
registrytest
.
New
(
t
,
fakeClient
,
storage
.
Etcd
)
test
.
TestGet
(
validNewJob
())
}
func
TestList
(
t
*
testing
.
T
)
{
storage
,
fakeClient
:=
newStorage
(
t
)
storage
,
_
,
fakeClient
:=
newStorage
(
t
)
test
:=
registrytest
.
New
(
t
,
fakeClient
,
storage
.
Etcd
)
test
.
TestList
(
validNewJob
())
}
func
TestWatch
(
t
*
testing
.
T
)
{
storage
,
fakeClient
:=
newStorage
(
t
)
storage
,
_
,
fakeClient
:=
newStorage
(
t
)
test
:=
registrytest
.
New
(
t
,
fakeClient
,
storage
.
Etcd
)
test
.
TestWatch
(
validNewJob
(),
...
...
@@ -151,3 +152,5 @@ func TestWatch(t *testing.T) {
},
)
}
// TODO: test update /status
pkg/registry/job/strategy.go
View file @
50f8f0c7
...
...
@@ -79,6 +79,22 @@ func (jobStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) fiel
return
append
(
validationErrorList
,
updateErrorList
...
)
}
type
jobStatusStrategy
struct
{
jobStrategy
}
var
StatusStrategy
=
jobStatusStrategy
{
Strategy
}
func
(
jobStatusStrategy
)
PrepareForUpdate
(
obj
,
old
runtime
.
Object
)
{
newJob
:=
obj
.
(
*
experimental
.
Job
)
oldJob
:=
old
.
(
*
experimental
.
Job
)
newJob
.
Spec
=
oldJob
.
Spec
}
func
(
jobStatusStrategy
)
ValidateUpdate
(
ctx
api
.
Context
,
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
return
validation
.
ValidateJobUpdateStatus
(
obj
.
(
*
experimental
.
Job
),
old
.
(
*
experimental
.
Job
))
}
// JobSelectableFields returns a field set that represents the object for matching purposes.
func
JobToSelectableFields
(
job
*
experimental
.
Job
)
fields
.
Set
{
return
fields
.
Set
{
...
...
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