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
c5dfe6b6
Commit
c5dfe6b6
authored
Dec 29, 2018
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update feature-gate handling of TTLSecondsAfterFinished
parent
43f0423d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
13 deletions
+23
-13
BUILD
pkg/apis/batch/validation/BUILD
+0
-2
validation.go
pkg/apis/batch/validation/validation.go
+2
-9
BUILD
pkg/registry/batch/job/BUILD
+1
-0
strategy.go
pkg/registry/batch/job/strategy.go
+1
-2
strategy_test.go
pkg/registry/batch/job/strategy_test.go
+19
-0
No files found.
pkg/apis/batch/validation/BUILD
View file @
c5dfe6b6
...
@@ -14,13 +14,11 @@ go_library(
...
@@ -14,13 +14,11 @@ go_library(
"//pkg/apis/batch:go_default_library",
"//pkg/apis/batch:go_default_library",
"//pkg/apis/core:go_default_library",
"//pkg/apis/core:go_default_library",
"//pkg/apis/core/validation:go_default_library",
"//pkg/apis/core/validation:go_default_library",
"//pkg/features:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/validation:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/validation:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/validation:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/validation:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//vendor/github.com/robfig/cron:go_default_library",
"//vendor/github.com/robfig/cron:go_default_library",
],
],
)
)
...
...
pkg/apis/batch/validation/validation.go
View file @
c5dfe6b6
...
@@ -24,11 +24,9 @@ import (
...
@@ -24,11 +24,9 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/labels"
apimachineryvalidation
"k8s.io/apimachinery/pkg/util/validation"
apimachineryvalidation
"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/apimachinery/pkg/util/validation/field"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
"k8s.io/kubernetes/pkg/apis/batch"
"k8s.io/kubernetes/pkg/apis/batch"
api
"k8s.io/kubernetes/pkg/apis/core"
api
"k8s.io/kubernetes/pkg/apis/core"
apivalidation
"k8s.io/kubernetes/pkg/apis/core/validation"
apivalidation
"k8s.io/kubernetes/pkg/apis/core/validation"
"k8s.io/kubernetes/pkg/features"
)
)
// TODO: generalize for other controller objects that will follow the same pattern, such as ReplicaSet and DaemonSet, and
// TODO: generalize for other controller objects that will follow the same pattern, such as ReplicaSet and DaemonSet, and
...
@@ -119,13 +117,8 @@ func validateJobSpec(spec *batch.JobSpec, fldPath *field.Path) field.ErrorList {
...
@@ -119,13 +117,8 @@ func validateJobSpec(spec *batch.JobSpec, fldPath *field.Path) field.ErrorList {
if
spec
.
BackoffLimit
!=
nil
{
if
spec
.
BackoffLimit
!=
nil
{
allErrs
=
append
(
allErrs
,
apivalidation
.
ValidateNonnegativeField
(
int64
(
*
spec
.
BackoffLimit
),
fldPath
.
Child
(
"backoffLimit"
))
...
)
allErrs
=
append
(
allErrs
,
apivalidation
.
ValidateNonnegativeField
(
int64
(
*
spec
.
BackoffLimit
),
fldPath
.
Child
(
"backoffLimit"
))
...
)
}
}
if
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
TTLAfterFinished
)
{
if
spec
.
TTLSecondsAfterFinished
!=
nil
{
// normal validation for TTLSecondsAfterFinished
allErrs
=
append
(
allErrs
,
apivalidation
.
ValidateNonnegativeField
(
int64
(
*
spec
.
TTLSecondsAfterFinished
),
fldPath
.
Child
(
"ttlSecondsAfterFinished"
))
...
)
if
spec
.
TTLSecondsAfterFinished
!=
nil
{
allErrs
=
append
(
allErrs
,
apivalidation
.
ValidateNonnegativeField
(
int64
(
*
spec
.
TTLSecondsAfterFinished
),
fldPath
.
Child
(
"ttlSecondsAfterFinished"
))
...
)
}
}
else
if
spec
.
TTLSecondsAfterFinished
!=
nil
{
allErrs
=
append
(
allErrs
,
field
.
Forbidden
(
fldPath
.
Child
(
"ttlSecondsAfterFinished"
),
"disabled by feature-gate"
))
}
}
allErrs
=
append
(
allErrs
,
apivalidation
.
ValidatePodTemplateSpec
(
&
spec
.
Template
,
fldPath
.
Child
(
"template"
))
...
)
allErrs
=
append
(
allErrs
,
apivalidation
.
ValidatePodTemplateSpec
(
&
spec
.
Template
,
fldPath
.
Child
(
"template"
))
...
)
...
...
pkg/registry/batch/job/BUILD
View file @
c5dfe6b6
...
@@ -50,6 +50,7 @@ go_test(
...
@@ -50,6 +50,7 @@ go_test(
"//staging/src/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/registry/rest:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/registry/rest:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature/testing:go_default_library",
],
],
)
)
...
...
pkg/registry/batch/job/strategy.go
View file @
c5dfe6b6
...
@@ -89,9 +89,8 @@ func (jobStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object
...
@@ -89,9 +89,8 @@ func (jobStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object
oldJob
:=
old
.
(
*
batch
.
Job
)
oldJob
:=
old
.
(
*
batch
.
Job
)
newJob
.
Status
=
oldJob
.
Status
newJob
.
Status
=
oldJob
.
Status
if
!
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
TTLAfterFinished
)
{
if
!
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
TTLAfterFinished
)
&&
oldJob
.
Spec
.
TTLSecondsAfterFinished
==
nil
{
newJob
.
Spec
.
TTLSecondsAfterFinished
=
nil
newJob
.
Spec
.
TTLSecondsAfterFinished
=
nil
oldJob
.
Spec
.
TTLSecondsAfterFinished
=
nil
}
}
pod
.
DropDisabledFields
(
&
newJob
.
Spec
.
Template
.
Spec
,
&
oldJob
.
Spec
.
Template
.
Spec
)
pod
.
DropDisabledFields
(
&
newJob
.
Spec
.
Template
.
Spec
,
&
oldJob
.
Spec
.
Template
.
Spec
)
...
...
pkg/registry/batch/job/strategy_test.go
View file @
c5dfe6b6
...
@@ -25,6 +25,7 @@ import (
...
@@ -25,6 +25,7 @@ import (
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/apiserver/pkg/registry/rest"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
utilfeaturetesting
"k8s.io/apiserver/pkg/util/feature/testing"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/testapi"
apitesting
"k8s.io/kubernetes/pkg/api/testing"
apitesting
"k8s.io/kubernetes/pkg/api/testing"
"k8s.io/kubernetes/pkg/apis/batch"
"k8s.io/kubernetes/pkg/apis/batch"
...
@@ -121,6 +122,24 @@ func TestJobStrategy(t *testing.T) {
...
@@ -121,6 +122,24 @@ func TestJobStrategy(t *testing.T) {
t
.
Errorf
(
"Job should only allow updating .spec.ttlSecondsAfterFinished when %v feature is enabled"
,
features
.
TTLAfterFinished
)
t
.
Errorf
(
"Job should only allow updating .spec.ttlSecondsAfterFinished when %v feature is enabled"
,
features
.
TTLAfterFinished
)
}
}
// set TTLSecondsAfterFinished on both old and new jobs
job
.
Spec
.
TTLSecondsAfterFinished
=
newInt32
(
1
)
updatedJob
.
Spec
.
TTLSecondsAfterFinished
=
newInt32
(
2
)
// Existing TTLSecondsAfterFinished should be preserved when feature is on
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
TTLAfterFinished
,
true
)()
Strategy
.
PrepareForUpdate
(
ctx
,
updatedJob
,
job
)
if
job
.
Spec
.
TTLSecondsAfterFinished
==
nil
||
updatedJob
.
Spec
.
TTLSecondsAfterFinished
==
nil
{
t
.
Errorf
(
"existing TTLSecondsAfterFinished should be preserved"
)
}
// Existing TTLSecondsAfterFinished should be preserved when feature is off
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
TTLAfterFinished
,
false
)()
Strategy
.
PrepareForUpdate
(
ctx
,
updatedJob
,
job
)
if
job
.
Spec
.
TTLSecondsAfterFinished
==
nil
||
updatedJob
.
Spec
.
TTLSecondsAfterFinished
==
nil
{
t
.
Errorf
(
"existing TTLSecondsAfterFinished should be preserved"
)
}
// Make sure we correctly implement the interface.
// Make sure we correctly implement the interface.
// Otherwise a typo could silently change the default.
// Otherwise a typo could silently change the default.
var
gcds
rest
.
GarbageCollectionDeleteStrategy
=
Strategy
var
gcds
rest
.
GarbageCollectionDeleteStrategy
=
Strategy
...
...
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