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
594e228a
Commit
594e228a
authored
Apr 25, 2018
by
Faraaz Khan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
set updated replicas correctly in scale up, scale down scenarios as well
parent
beec45b4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
19 deletions
+42
-19
stateful_set_control.go
pkg/controller/statefulset/stateful_set_control.go
+6
-3
stateful_set_control_test.go
pkg/controller/statefulset/stateful_set_control_test.go
+36
-16
No files found.
pkg/controller/statefulset/stateful_set_control.go
View file @
594e228a
...
...
@@ -380,7 +380,8 @@ func (ssc *defaultStatefulSetControl) updateStatefulSet(
}
if
getPodRevision
(
replicas
[
i
])
==
currentRevision
.
Name
{
status
.
CurrentReplicas
--
}
else
if
getPodRevision
(
replicas
[
i
])
==
updateRevision
.
Name
{
}
if
getPodRevision
(
replicas
[
i
])
==
updateRevision
.
Name
{
status
.
UpdatedReplicas
--
}
status
.
Replicas
--
...
...
@@ -399,7 +400,8 @@ func (ssc *defaultStatefulSetControl) updateStatefulSet(
status
.
Replicas
++
if
getPodRevision
(
replicas
[
i
])
==
currentRevision
.
Name
{
status
.
CurrentReplicas
++
}
else
if
getPodRevision
(
replicas
[
i
])
==
updateRevision
.
Name
{
}
if
getPodRevision
(
replicas
[
i
])
==
updateRevision
.
Name
{
status
.
UpdatedReplicas
++
}
...
...
@@ -480,7 +482,8 @@ func (ssc *defaultStatefulSetControl) updateStatefulSet(
}
if
getPodRevision
(
condemned
[
target
])
==
currentRevision
.
Name
{
status
.
CurrentReplicas
--
}
else
if
getPodRevision
(
condemned
[
target
])
==
updateRevision
.
Name
{
}
if
getPodRevision
(
condemned
[
target
])
==
updateRevision
.
Name
{
status
.
UpdatedReplicas
--
}
if
monotonic
{
...
...
pkg/controller/statefulset/stateful_set_control_test.go
View file @
594e228a
...
...
@@ -81,7 +81,6 @@ func TestStatefulSetControl(t *testing.T) {
obj
func
()
*
apps
.
StatefulSet
}{
{
CreatesPods
,
simpleSetFn
},
{
SetsStatusFields
,
simpleSetFn
},
{
ScalesUp
,
simpleSetFn
},
{
ScalesDown
,
simpleSetFn
},
{
ReplacesPods
,
largeSetFn
},
...
...
@@ -129,21 +128,6 @@ func CreatesPods(t *testing.T, set *apps.StatefulSet, invariants invariantFunc)
if
set
.
Status
.
Replicas
!=
3
{
t
.
Error
(
"Failed to scale statefulset to 3 replicas"
)
}
}
func
SetsStatusFields
(
t
*
testing
.
T
,
set
*
apps
.
StatefulSet
,
invariants
invariantFunc
)
{
client
:=
fake
.
NewSimpleClientset
(
set
)
spc
,
_
,
ssc
,
stop
:=
setupController
(
client
)
defer
close
(
stop
)
if
err
:=
scaleUpStatefulSetControl
(
set
,
ssc
,
spc
,
invariants
);
err
!=
nil
{
t
.
Errorf
(
"Failed to turn up StatefulSet : %s"
,
err
)
}
var
err
error
set
,
err
=
spc
.
setsLister
.
StatefulSets
(
set
.
Namespace
)
.
Get
(
set
.
Name
)
if
err
!=
nil
{
t
.
Fatalf
(
"Error getting updated StatefulSet: %v"
,
err
)
}
if
set
.
Status
.
ReadyReplicas
!=
3
{
t
.
Error
(
"Failed to set ReadyReplicas correctly"
)
}
...
...
@@ -172,6 +156,12 @@ func ScalesUp(t *testing.T, set *apps.StatefulSet, invariants invariantFunc) {
if
set
.
Status
.
Replicas
!=
4
{
t
.
Error
(
"Failed to scale statefulset to 4 replicas"
)
}
if
set
.
Status
.
ReadyReplicas
!=
4
{
t
.
Error
(
"Failed to set readyReplicas correctly"
)
}
if
set
.
Status
.
UpdatedReplicas
!=
4
{
t
.
Error
(
"Failed to set updatedReplicas correctly"
)
}
}
func
ScalesDown
(
t
*
testing
.
T
,
set
*
apps
.
StatefulSet
,
invariants
invariantFunc
)
{
...
...
@@ -189,6 +179,12 @@ func ScalesDown(t *testing.T, set *apps.StatefulSet, invariants invariantFunc) {
if
set
.
Status
.
Replicas
!=
0
{
t
.
Error
(
"Failed to scale statefulset to 0 replicas"
)
}
if
set
.
Status
.
ReadyReplicas
!=
0
{
t
.
Error
(
"Failed to set readyReplicas correctly"
)
}
if
set
.
Status
.
UpdatedReplicas
!=
0
{
t
.
Error
(
"Failed to set updatedReplicas correctly"
)
}
}
func
ReplacesPods
(
t
*
testing
.
T
,
set
*
apps
.
StatefulSet
,
invariants
invariantFunc
)
{
...
...
@@ -320,6 +316,12 @@ func CreatePodFailure(t *testing.T, set *apps.StatefulSet, invariants invariantF
if
set
.
Status
.
Replicas
!=
3
{
t
.
Error
(
"Failed to scale StatefulSet to 3 replicas"
)
}
if
set
.
Status
.
ReadyReplicas
!=
3
{
t
.
Error
(
"Failed to set readyReplicas correctly"
)
}
if
set
.
Status
.
UpdatedReplicas
!=
3
{
t
.
Error
(
"Failed to updatedReplicas correctly"
)
}
}
func
UpdatePodFailure
(
t
*
testing
.
T
,
set
*
apps
.
StatefulSet
,
invariants
invariantFunc
)
{
...
...
@@ -340,6 +342,12 @@ func UpdatePodFailure(t *testing.T, set *apps.StatefulSet, invariants invariantF
if
set
.
Status
.
Replicas
!=
3
{
t
.
Error
(
"Failed to scale StatefulSet to 3 replicas"
)
}
if
set
.
Status
.
ReadyReplicas
!=
3
{
t
.
Error
(
"Failed to set readyReplicas correctly"
)
}
if
set
.
Status
.
UpdatedReplicas
!=
3
{
t
.
Error
(
"Failed to set updatedReplicas correctly"
)
}
// now mutate a pod's identity
pods
,
err
:=
spc
.
podsLister
.
List
(
labels
.
Everything
())
...
...
@@ -379,6 +387,12 @@ func UpdateSetStatusFailure(t *testing.T, set *apps.StatefulSet, invariants inva
if
set
.
Status
.
Replicas
!=
3
{
t
.
Error
(
"Failed to scale StatefulSet to 3 replicas"
)
}
if
set
.
Status
.
ReadyReplicas
!=
3
{
t
.
Error
(
"Failed to set readyReplicas to 3"
)
}
if
set
.
Status
.
UpdatedReplicas
!=
3
{
t
.
Error
(
"Failed to set updatedReplicas to 3"
)
}
}
func
PodRecreateDeleteFailure
(
t
*
testing
.
T
,
set
*
apps
.
StatefulSet
,
invariants
invariantFunc
)
{
...
...
@@ -458,6 +472,12 @@ func TestStatefulSetControlScaleDownDeleteError(t *testing.T) {
if
set
.
Status
.
Replicas
!=
0
{
t
.
Error
(
"Failed to scale statefulset to 0 replicas"
)
}
if
set
.
Status
.
ReadyReplicas
!=
0
{
t
.
Error
(
"Failed to set readyReplicas to 0"
)
}
if
set
.
Status
.
UpdatedReplicas
!=
0
{
t
.
Error
(
"Failed to set updatedReplicas to 0"
)
}
}
func
TestStatefulSetControl_getSetRevisions
(
t
*
testing
.
T
)
{
...
...
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