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
cfd8a389
Commit
cfd8a389
authored
Feb 23, 2017
by
Anthony Yeh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
StatefulSet: Set DefaultGarbageCollectionPolicy to OrphanDependents.
Now that StatefulSet adds ControllerRef to Pods it creates, we need to set this default so legacy behavior is maintained.
parent
b5dfc7b2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
4 deletions
+21
-4
BUILD
pkg/registry/apps/petset/BUILD
+2
-0
strategy.go
pkg/registry/apps/petset/strategy.go
+7
-0
strategy_test.go
pkg/registry/apps/petset/strategy_test.go
+12
-4
No files found.
pkg/registry/apps/petset/BUILD
View file @
cfd8a389
...
...
@@ -25,6 +25,7 @@ go_library(
"//vendor:k8s.io/apimachinery/pkg/util/validation/field",
"//vendor:k8s.io/apiserver/pkg/endpoints/request",
"//vendor:k8s.io/apiserver/pkg/registry/generic",
"//vendor:k8s.io/apiserver/pkg/registry/rest",
"//vendor:k8s.io/apiserver/pkg/storage",
"//vendor:k8s.io/apiserver/pkg/storage/names",
],
...
...
@@ -40,6 +41,7 @@ go_test(
"//pkg/apis/apps:go_default_library",
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1",
"//vendor:k8s.io/apiserver/pkg/endpoints/request",
"//vendor:k8s.io/apiserver/pkg/registry/rest",
],
)
...
...
pkg/registry/apps/petset/strategy.go
View file @
cfd8a389
...
...
@@ -26,6 +26,7 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/apiserver/pkg/storage"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api"
...
...
@@ -42,6 +43,12 @@ type statefulSetStrategy struct {
// Strategy is the default logic that applies when creating and updating Replication StatefulSet objects.
var
Strategy
=
statefulSetStrategy
{
api
.
Scheme
,
names
.
SimpleNameGenerator
}
// DefaultGarbageCollectionPolicy returns Orphan because that was the default
// behavior before the server-side garbage collection was implemented.
func
(
statefulSetStrategy
)
DefaultGarbageCollectionPolicy
()
rest
.
GarbageCollectionPolicy
{
return
rest
.
OrphanDependents
}
// NamespaceScoped returns true because all StatefulSet' need to be within a namespace.
func
(
statefulSetStrategy
)
NamespaceScoped
()
bool
{
return
true
...
...
pkg/registry/apps/petset/strategy_test.go
View file @
cfd8a389
...
...
@@ -21,6 +21,7 @@ import (
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apis/apps"
)
...
...
@@ -62,7 +63,7 @@ func TestStatefulSetStrategy(t *testing.T) {
}
errs
:=
Strategy
.
Validate
(
ctx
,
ps
)
if
len
(
errs
)
!=
0
{
t
.
Errorf
(
"
U
nexpected error validating %v"
,
errs
)
t
.
Errorf
(
"
u
nexpected error validating %v"
,
errs
)
}
// Just Spec.Replicas is allowed to change
...
...
@@ -77,14 +78,21 @@ func TestStatefulSetStrategy(t *testing.T) {
Strategy
.
PrepareForUpdate
(
ctx
,
validPs
,
ps
)
errs
=
Strategy
.
ValidateUpdate
(
ctx
,
validPs
,
ps
)
if
len
(
errs
)
!=
0
{
t
.
Errorf
(
"
U
pdating spec.Replicas is allowed on a statefulset: %v"
,
errs
)
t
.
Errorf
(
"
u
pdating spec.Replicas is allowed on a statefulset: %v"
,
errs
)
}
validPs
.
Spec
.
Selector
=
&
metav1
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{
"a"
:
"bar"
}}
Strategy
.
PrepareForUpdate
(
ctx
,
validPs
,
ps
)
errs
=
Strategy
.
ValidateUpdate
(
ctx
,
validPs
,
ps
)
if
len
(
errs
)
==
0
{
t
.
Errorf
(
"Expected a validation error since updates are disallowed on statefulsets."
)
t
.
Errorf
(
"expected a validation error since updates are disallowed on statefulsets."
)
}
// Make sure we correctly implement the interface.
// Otherwise a typo could silently change the default.
var
gcds
rest
.
GarbageCollectionDeleteStrategy
=
Strategy
if
got
,
want
:=
gcds
.
DefaultGarbageCollectionPolicy
(),
rest
.
OrphanDependents
;
got
!=
want
{
t
.
Errorf
(
"DefaultGarbageCollectionPolicy() = %#v, want %#v"
,
got
,
want
)
}
}
...
...
@@ -140,6 +148,6 @@ func TestStatefulSetStatusStrategy(t *testing.T) {
}
errs
:=
StatusStrategy
.
ValidateUpdate
(
ctx
,
newPS
,
oldPS
)
if
len
(
errs
)
!=
0
{
t
.
Errorf
(
"
U
nexpected error %v"
,
errs
)
t
.
Errorf
(
"
u
nexpected error %v"
,
errs
)
}
}
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