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
27e6ceed
Commit
27e6ceed
authored
Aug 04, 2017
by
Anirudh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change default update strategy to rolling update
parent
3e0eff9f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
163 additions
and
17 deletions
+163
-17
defaults.go
pkg/apis/apps/v1beta2/defaults.go
+13
-9
defaults_test.go
pkg/apis/apps/v1beta2/defaults_test.go
+144
-6
types.go
staging/src/k8s.io/api/apps/v1beta2/types.go
+6
-2
No files found.
pkg/apis/apps/v1beta2/defaults.go
View file @
27e6ceed
...
@@ -43,7 +43,7 @@ func SetDefaults_DaemonSet(obj *appsv1beta2.DaemonSet) {
...
@@ -43,7 +43,7 @@ func SetDefaults_DaemonSet(obj *appsv1beta2.DaemonSet) {
}
}
updateStrategy
:=
&
obj
.
Spec
.
UpdateStrategy
updateStrategy
:=
&
obj
.
Spec
.
UpdateStrategy
if
updateStrategy
.
Type
==
""
{
if
updateStrategy
.
Type
==
""
{
updateStrategy
.
Type
=
appsv1beta2
.
OnDele
teDaemonSetStrategyType
updateStrategy
.
Type
=
appsv1beta2
.
RollingUpda
teDaemonSetStrategyType
}
}
if
updateStrategy
.
Type
==
appsv1beta2
.
RollingUpdateDaemonSetStrategyType
{
if
updateStrategy
.
Type
==
appsv1beta2
.
RollingUpdateDaemonSetStrategyType
{
if
updateStrategy
.
RollingUpdate
==
nil
{
if
updateStrategy
.
RollingUpdate
==
nil
{
...
@@ -68,8 +68,19 @@ func SetDefaults_StatefulSet(obj *appsv1beta2.StatefulSet) {
...
@@ -68,8 +68,19 @@ func SetDefaults_StatefulSet(obj *appsv1beta2.StatefulSet) {
}
}
if
obj
.
Spec
.
UpdateStrategy
.
Type
==
""
{
if
obj
.
Spec
.
UpdateStrategy
.
Type
==
""
{
obj
.
Spec
.
UpdateStrategy
.
Type
=
appsv1beta2
.
OnDeleteStatefulSetStrategyType
obj
.
Spec
.
UpdateStrategy
.
Type
=
appsv1beta2
.
RollingUpdateStatefulSetStrategyType
// UpdateStrategy.RollingUpdate will take default values below.
obj
.
Spec
.
UpdateStrategy
.
RollingUpdate
=
&
appsv1beta2
.
RollingUpdateStatefulSetStrategy
{}
}
if
obj
.
Spec
.
UpdateStrategy
.
Type
==
appsv1beta2
.
RollingUpdateStatefulSetStrategyType
&&
obj
.
Spec
.
UpdateStrategy
.
RollingUpdate
!=
nil
&&
obj
.
Spec
.
UpdateStrategy
.
RollingUpdate
.
Partition
==
nil
{
obj
.
Spec
.
UpdateStrategy
.
RollingUpdate
.
Partition
=
new
(
int32
)
*
obj
.
Spec
.
UpdateStrategy
.
RollingUpdate
.
Partition
=
0
}
}
labels
:=
obj
.
Spec
.
Template
.
Labels
labels
:=
obj
.
Spec
.
Template
.
Labels
if
labels
!=
nil
{
if
labels
!=
nil
{
if
obj
.
Spec
.
Selector
==
nil
{
if
obj
.
Spec
.
Selector
==
nil
{
...
@@ -89,13 +100,6 @@ func SetDefaults_StatefulSet(obj *appsv1beta2.StatefulSet) {
...
@@ -89,13 +100,6 @@ func SetDefaults_StatefulSet(obj *appsv1beta2.StatefulSet) {
obj
.
Spec
.
RevisionHistoryLimit
=
new
(
int32
)
obj
.
Spec
.
RevisionHistoryLimit
=
new
(
int32
)
*
obj
.
Spec
.
RevisionHistoryLimit
=
10
*
obj
.
Spec
.
RevisionHistoryLimit
=
10
}
}
if
obj
.
Spec
.
UpdateStrategy
.
Type
==
appsv1beta2
.
RollingUpdateStatefulSetStrategyType
&&
obj
.
Spec
.
UpdateStrategy
.
RollingUpdate
!=
nil
&&
obj
.
Spec
.
UpdateStrategy
.
RollingUpdate
.
Partition
==
nil
{
obj
.
Spec
.
UpdateStrategy
.
RollingUpdate
.
Partition
=
new
(
int32
)
*
obj
.
Spec
.
UpdateStrategy
.
RollingUpdate
.
Partition
=
0
}
}
}
// SetDefaults_Deployment sets additional defaults compared to its counterpart
// SetDefaults_Deployment sets additional defaults compared to its counterpart
...
...
pkg/apis/apps/v1beta2/defaults_test.go
View file @
27e6ceed
...
@@ -21,7 +21,6 @@ import (
...
@@ -21,7 +21,6 @@ import (
"testing"
"testing"
appsv1beta2
"k8s.io/api/apps/v1beta2"
appsv1beta2
"k8s.io/api/apps/v1beta2"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
apiequality
"k8s.io/apimachinery/pkg/api/equality"
apiequality
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/api/resource"
...
@@ -36,6 +35,7 @@ import (
...
@@ -36,6 +35,7 @@ import (
func
TestSetDefaultDaemonSetSpec
(
t
*
testing
.
T
)
{
func
TestSetDefaultDaemonSetSpec
(
t
*
testing
.
T
)
{
defaultLabels
:=
map
[
string
]
string
{
"foo"
:
"bar"
}
defaultLabels
:=
map
[
string
]
string
{
"foo"
:
"bar"
}
maxUnavailable
:=
intstr
.
FromInt
(
1
)
period
:=
int64
(
v1
.
DefaultTerminationGracePeriodSeconds
)
period
:=
int64
(
v1
.
DefaultTerminationGracePeriodSeconds
)
defaultTemplate
:=
v1
.
PodTemplateSpec
{
defaultTemplate
:=
v1
.
PodTemplateSpec
{
Spec
:
v1
.
PodSpec
{
Spec
:
v1
.
PodSpec
{
...
@@ -78,7 +78,10 @@ func TestSetDefaultDaemonSetSpec(t *testing.T) {
...
@@ -78,7 +78,10 @@ func TestSetDefaultDaemonSetSpec(t *testing.T) {
},
},
Template
:
defaultTemplate
,
Template
:
defaultTemplate
,
UpdateStrategy
:
appsv1beta2
.
DaemonSetUpdateStrategy
{
UpdateStrategy
:
appsv1beta2
.
DaemonSetUpdateStrategy
{
Type
:
appsv1beta2
.
OnDeleteDaemonSetStrategyType
,
Type
:
appsv1beta2
.
RollingUpdateStatefulSetStrategyType
,
RollingUpdate
:
&
appsv1beta2
.
RollingUpdateDaemonSet
{
MaxUnavailable
:
&
maxUnavailable
,
},
},
},
RevisionHistoryLimit
:
newInt32
(
10
),
RevisionHistoryLimit
:
newInt32
(
10
),
},
},
...
@@ -108,14 +111,24 @@ func TestSetDefaultDaemonSetSpec(t *testing.T) {
...
@@ -108,14 +111,24 @@ func TestSetDefaultDaemonSetSpec(t *testing.T) {
},
},
Template
:
defaultTemplate
,
Template
:
defaultTemplate
,
UpdateStrategy
:
appsv1beta2
.
DaemonSetUpdateStrategy
{
UpdateStrategy
:
appsv1beta2
.
DaemonSetUpdateStrategy
{
Type
:
appsv1beta2
.
OnDeleteDaemonSetStrategyType
,
Type
:
appsv1beta2
.
RollingUpdateStatefulSetStrategyType
,
RollingUpdate
:
&
appsv1beta2
.
RollingUpdateDaemonSet
{
MaxUnavailable
:
&
maxUnavailable
,
},
},
},
RevisionHistoryLimit
:
newInt32
(
1
),
RevisionHistoryLimit
:
newInt32
(
1
),
},
},
},
},
},
},
{
// Update strategy.
{
// OnDeleteDaemonSetStrategyType update strategy.
original
:
&
appsv1beta2
.
DaemonSet
{},
original
:
&
appsv1beta2
.
DaemonSet
{
Spec
:
appsv1beta2
.
DaemonSetSpec
{
Template
:
templateNoLabel
,
UpdateStrategy
:
appsv1beta2
.
DaemonSetUpdateStrategy
{
Type
:
appsv1beta2
.
OnDeleteDaemonSetStrategyType
,
},
},
},
expected
:
&
appsv1beta2
.
DaemonSet
{
expected
:
&
appsv1beta2
.
DaemonSet
{
Spec
:
appsv1beta2
.
DaemonSetSpec
{
Spec
:
appsv1beta2
.
DaemonSetSpec
{
Template
:
templateNoLabel
,
Template
:
templateNoLabel
,
...
@@ -134,7 +147,10 @@ func TestSetDefaultDaemonSetSpec(t *testing.T) {
...
@@ -134,7 +147,10 @@ func TestSetDefaultDaemonSetSpec(t *testing.T) {
Spec
:
appsv1beta2
.
DaemonSetSpec
{
Spec
:
appsv1beta2
.
DaemonSetSpec
{
Template
:
templateNoLabel
,
Template
:
templateNoLabel
,
UpdateStrategy
:
appsv1beta2
.
DaemonSetUpdateStrategy
{
UpdateStrategy
:
appsv1beta2
.
DaemonSetUpdateStrategy
{
Type
:
appsv1beta2
.
OnDeleteDaemonSetStrategyType
,
Type
:
appsv1beta2
.
RollingUpdateStatefulSetStrategyType
,
RollingUpdate
:
&
appsv1beta2
.
RollingUpdateDaemonSet
{
MaxUnavailable
:
&
maxUnavailable
,
},
},
},
RevisionHistoryLimit
:
newInt32
(
10
),
RevisionHistoryLimit
:
newInt32
(
10
),
},
},
...
@@ -157,6 +173,128 @@ func TestSetDefaultDaemonSetSpec(t *testing.T) {
...
@@ -157,6 +173,128 @@ func TestSetDefaultDaemonSetSpec(t *testing.T) {
}
}
}
}
func
TestSetDefaultStatefulSet
(
t
*
testing
.
T
)
{
defaultLabels
:=
map
[
string
]
string
{
"foo"
:
"bar"
}
var
defaultPartition
int32
=
0
var
defaultReplicas
int32
=
1
period
:=
int64
(
v1
.
DefaultTerminationGracePeriodSeconds
)
defaultTemplate
:=
v1
.
PodTemplateSpec
{
Spec
:
v1
.
PodSpec
{
DNSPolicy
:
v1
.
DNSClusterFirst
,
RestartPolicy
:
v1
.
RestartPolicyAlways
,
SecurityContext
:
&
v1
.
PodSecurityContext
{},
TerminationGracePeriodSeconds
:
&
period
,
SchedulerName
:
api
.
DefaultSchedulerName
,
},
ObjectMeta
:
metav1
.
ObjectMeta
{
Labels
:
defaultLabels
,
},
}
tests
:=
[]
struct
{
original
*
appsv1beta2
.
StatefulSet
expected
*
appsv1beta2
.
StatefulSet
}{
{
// Selector, labels and default update strategy
original
:
&
appsv1beta2
.
StatefulSet
{
Spec
:
appsv1beta2
.
StatefulSetSpec
{
Template
:
defaultTemplate
,
},
},
expected
:
&
appsv1beta2
.
StatefulSet
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Labels
:
defaultLabels
,
},
Spec
:
appsv1beta2
.
StatefulSetSpec
{
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
defaultLabels
,
},
Replicas
:
&
defaultReplicas
,
Template
:
defaultTemplate
,
PodManagementPolicy
:
appsv1beta2
.
OrderedReadyPodManagement
,
UpdateStrategy
:
appsv1beta2
.
StatefulSetUpdateStrategy
{
Type
:
appsv1beta2
.
RollingUpdateStatefulSetStrategyType
,
RollingUpdate
:
&
appsv1beta2
.
RollingUpdateStatefulSetStrategy
{
Partition
:
&
defaultPartition
,
},
},
RevisionHistoryLimit
:
newInt32
(
10
),
},
},
},
{
// Alternate update strategy
original
:
&
appsv1beta2
.
StatefulSet
{
Spec
:
appsv1beta2
.
StatefulSetSpec
{
Template
:
defaultTemplate
,
UpdateStrategy
:
appsv1beta2
.
StatefulSetUpdateStrategy
{
Type
:
appsv1beta2
.
OnDeleteStatefulSetStrategyType
,
},
},
},
expected
:
&
appsv1beta2
.
StatefulSet
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Labels
:
defaultLabels
,
},
Spec
:
appsv1beta2
.
StatefulSetSpec
{
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
defaultLabels
,
},
Replicas
:
&
defaultReplicas
,
Template
:
defaultTemplate
,
PodManagementPolicy
:
appsv1beta2
.
OrderedReadyPodManagement
,
UpdateStrategy
:
appsv1beta2
.
StatefulSetUpdateStrategy
{
Type
:
appsv1beta2
.
OnDeleteStatefulSetStrategyType
,
},
RevisionHistoryLimit
:
newInt32
(
10
),
},
},
},
{
// Parallel pod management policy.
original
:
&
appsv1beta2
.
StatefulSet
{
Spec
:
appsv1beta2
.
StatefulSetSpec
{
Template
:
defaultTemplate
,
PodManagementPolicy
:
appsv1beta2
.
ParallelPodManagement
,
},
},
expected
:
&
appsv1beta2
.
StatefulSet
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Labels
:
defaultLabels
,
},
Spec
:
appsv1beta2
.
StatefulSetSpec
{
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
defaultLabels
,
},
Replicas
:
&
defaultReplicas
,
Template
:
defaultTemplate
,
PodManagementPolicy
:
appsv1beta2
.
ParallelPodManagement
,
UpdateStrategy
:
appsv1beta2
.
StatefulSetUpdateStrategy
{
Type
:
appsv1beta2
.
RollingUpdateStatefulSetStrategyType
,
RollingUpdate
:
&
appsv1beta2
.
RollingUpdateStatefulSetStrategy
{
Partition
:
&
defaultPartition
,
},
},
RevisionHistoryLimit
:
newInt32
(
10
),
},
},
},
}
for
i
,
test
:=
range
tests
{
original
:=
test
.
original
expected
:=
test
.
expected
obj2
:=
roundTrip
(
t
,
runtime
.
Object
(
original
))
got
,
ok
:=
obj2
.
(
*
appsv1beta2
.
StatefulSet
)
if
!
ok
{
t
.
Errorf
(
"(%d) unexpected object: %v"
,
i
,
got
)
t
.
FailNow
()
}
if
!
apiequality
.
Semantic
.
DeepEqual
(
got
.
Spec
,
expected
.
Spec
)
{
t
.
Errorf
(
"(%d) got different than expected
\n
got:
\n\t
%+v
\n
expected:
\n\t
%+v"
,
i
,
got
.
Spec
,
expected
.
Spec
)
}
}
}
func
TestSetDefaultDeployment
(
t
*
testing
.
T
)
{
func
TestSetDefaultDeployment
(
t
*
testing
.
T
)
{
defaultIntOrString
:=
intstr
.
FromString
(
"25%"
)
defaultIntOrString
:=
intstr
.
FromString
(
"25%"
)
differentIntOrString
:=
intstr
.
FromInt
(
5
)
differentIntOrString
:=
intstr
.
FromInt
(
5
)
...
...
staging/src/k8s.io/api/apps/v1beta2/types.go
View file @
27e6ceed
...
@@ -122,8 +122,11 @@ const (
...
@@ -122,8 +122,11 @@ const (
// necessary to perform the update for the indicated strategy.
// necessary to perform the update for the indicated strategy.
type
StatefulSetUpdateStrategy
struct
{
type
StatefulSetUpdateStrategy
struct
{
// Type indicates the type of the StatefulSetUpdateStrategy.
// Type indicates the type of the StatefulSetUpdateStrategy.
// Default is RollingUpdate.
// +optional
Type
StatefulSetUpdateStrategyType
`json:"type,omitempty" protobuf:"bytes,1,opt,name=type,casttype=StatefulSetStrategyType"`
Type
StatefulSetUpdateStrategyType
`json:"type,omitempty" protobuf:"bytes,1,opt,name=type,casttype=StatefulSetStrategyType"`
// RollingUpdate is used to communicate parameters when Type is RollingUpdateStatefulSetStrategyType.
// RollingUpdate is used to communicate parameters when Type is RollingUpdateStatefulSetStrategyType.
// +optional
RollingUpdate
*
RollingUpdateStatefulSetStrategy
`json:"rollingUpdate,omitempty" protobuf:"bytes,2,opt,name=rollingUpdate"`
RollingUpdate
*
RollingUpdateStatefulSetStrategy
`json:"rollingUpdate,omitempty" protobuf:"bytes,2,opt,name=rollingUpdate"`
}
}
...
@@ -151,6 +154,8 @@ const (
...
@@ -151,6 +154,8 @@ const (
type
RollingUpdateStatefulSetStrategy
struct
{
type
RollingUpdateStatefulSetStrategy
struct
{
// Partition indicates the ordinal at which the StatefulSet should be
// Partition indicates the ordinal at which the StatefulSet should be
// partitioned.
// partitioned.
// Default value is 0.
// +optional
Partition
*
int32
`json:"partition,omitempty" protobuf:"varint,1,opt,name=partition"`
Partition
*
int32
`json:"partition,omitempty" protobuf:"varint,1,opt,name=partition"`
}
}
...
@@ -504,8 +509,7 @@ type DeploymentList struct {
...
@@ -504,8 +509,7 @@ type DeploymentList struct {
// WIP: This is not ready to be used and we plan to make breaking changes to it.
// WIP: This is not ready to be used and we plan to make breaking changes to it.
type
DaemonSetUpdateStrategy
struct
{
type
DaemonSetUpdateStrategy
struct
{
// Type of daemon set update. Can be "RollingUpdate" or "OnDelete".
// Type of daemon set update. Can be "RollingUpdate" or "OnDelete". Default is RollingUpdate.
// Default is OnDelete.
// +optional
// +optional
Type
DaemonSetUpdateStrategyType
`json:"type,omitempty" protobuf:"bytes,1,opt,name=type"`
Type
DaemonSetUpdateStrategyType
`json:"type,omitempty" protobuf:"bytes,1,opt,name=type"`
...
...
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