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
95469099
Commit
95469099
authored
Jan 21, 2016
by
Alex Mohr
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #19366 from ironcladlou/noop-zero-replicas
Support rolling update to 0 desired replicas
parents
12845ba9
eb778217
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
4 deletions
+88
-4
rolling_updater.go
pkg/kubectl/rolling_updater.go
+10
-3
rolling_updater_test.go
pkg/kubectl/rolling_updater_test.go
+78
-1
No files found.
pkg/kubectl/rolling_updater.go
View file @
95469099
...
...
@@ -208,13 +208,20 @@ func (r *RollingUpdater) Update(config *RollingUpdaterConfig) error {
if
err
!=
nil
{
return
err
}
//
Further validation
.
if
maxUnavailable
==
0
&&
maxSurge
==
0
{
//
Validate maximums
.
if
desired
>
0
&&
maxUnavailable
==
0
&&
maxSurge
==
0
{
return
fmt
.
Errorf
(
"one of maxSurge or maxUnavailable must be specified"
)
}
// The minumum pods which must remain available througout the update
// calculated for internal convenience.
minAvailable
:=
original
-
maxUnavailable
minAvailable
:=
int
(
math
.
Max
(
float64
(
0
),
float64
(
desired
-
maxUnavailable
)))
// If the desired new scale is 0, then the max unavailable is necessarily
// the effective scale of the old RC regardless of the configuration
// (equivalent to 100% maxUnavailable).
if
desired
==
0
{
maxUnavailable
=
original
minAvailable
=
0
}
fmt
.
Fprintf
(
out
,
"Scaling up %s from %d to %d, scaling down %s from %d to 0 (keep %d pods available, don't exceed %d pods)
\n
"
,
newRc
.
Name
,
newRc
.
Spec
.
Replicas
,
desired
,
oldRc
.
Name
,
oldRc
.
Spec
.
Replicas
,
minAvailable
,
original
+
maxSurge
)
...
...
pkg/kubectl/rolling_updater_test.go
View file @
95469099
...
...
@@ -539,7 +539,7 @@ Scaling foo-v1 down to 0
down
{
oldReady
:
10
,
newReady
:
20
,
to
:
0
},
},
output
:
`Created foo-v2
Scaling up foo-v2 from 0 to 20, scaling down foo-v1 from 10 to 0 (keep
1
0 pods available, don't exceed 70 pods)
Scaling up foo-v2 from 0 to 20, scaling down foo-v1 from 10 to 0 (keep
2
0 pods available, don't exceed 70 pods)
Scaling foo-v2 up to 20
Scaling foo-v1 down to 0
`
,
...
...
@@ -559,6 +559,83 @@ Scaling up foo-v2 from 1 to 1, scaling down foo-v1 from 1 to 0 (keep 1 pods avai
Scaling foo-v1 down to 0
`
,
},
{
name
:
"3->0 1/1 desired 0 (absolute values)"
,
oldRc
:
oldRc
(
3
,
3
),
newRc
:
newRc
(
0
,
0
),
newRcExists
:
true
,
maxUnavail
:
intstr
.
FromInt
(
1
),
maxSurge
:
intstr
.
FromInt
(
1
),
expected
:
[]
interface
{}{
down
{
oldReady
:
3
,
newReady
:
0
,
to
:
0
},
},
output
:
`Continuing update with existing controller foo-v2.
Scaling up foo-v2 from 0 to 0, scaling down foo-v1 from 3 to 0 (keep 0 pods available, don't exceed 4 pods)
Scaling foo-v1 down to 0
`
,
},
{
name
:
"3->0 10/10 desired 0 (percentages)"
,
oldRc
:
oldRc
(
3
,
3
),
newRc
:
newRc
(
0
,
0
),
newRcExists
:
true
,
maxUnavail
:
intstr
.
FromString
(
"10%"
),
maxSurge
:
intstr
.
FromString
(
"10%"
),
expected
:
[]
interface
{}{
down
{
oldReady
:
3
,
newReady
:
0
,
to
:
0
},
},
output
:
`Continuing update with existing controller foo-v2.
Scaling up foo-v2 from 0 to 0, scaling down foo-v1 from 3 to 0 (keep 0 pods available, don't exceed 3 pods)
Scaling foo-v1 down to 0
`
,
},
{
name
:
"3->0 10/10 desired 0 (create new RC)"
,
oldRc
:
oldRc
(
3
,
3
),
newRc
:
newRc
(
0
,
0
),
newRcExists
:
false
,
maxUnavail
:
intstr
.
FromString
(
"10%"
),
maxSurge
:
intstr
.
FromString
(
"10%"
),
expected
:
[]
interface
{}{
down
{
oldReady
:
3
,
newReady
:
0
,
to
:
0
},
},
output
:
`Created foo-v2
Scaling up foo-v2 from 0 to 0, scaling down foo-v1 from 3 to 0 (keep 0 pods available, don't exceed 3 pods)
Scaling foo-v1 down to 0
`
,
},
{
name
:
"0->0 1/1 desired 0 (absolute values)"
,
oldRc
:
oldRc
(
0
,
0
),
newRc
:
newRc
(
0
,
0
),
newRcExists
:
true
,
maxUnavail
:
intstr
.
FromInt
(
1
),
maxSurge
:
intstr
.
FromInt
(
1
),
expected
:
[]
interface
{}{
down
{
oldReady
:
0
,
newReady
:
0
,
to
:
0
},
},
output
:
`Continuing update with existing controller foo-v2.
Scaling up foo-v2 from 0 to 0, scaling down foo-v1 from 0 to 0 (keep 0 pods available, don't exceed 1 pods)
`
,
},
{
name
:
"30->2 50%/0"
,
oldRc
:
oldRc
(
30
,
30
),
newRc
:
newRc
(
0
,
2
),
newRcExists
:
false
,
maxUnavail
:
intstr
.
FromString
(
"50%"
),
maxSurge
:
intstr
.
FromInt
(
0
),
expected
:
[]
interface
{}{
down
{
oldReady
:
30
,
newReady
:
0
,
to
:
1
},
up
{
2
},
down
{
oldReady
:
1
,
newReady
:
2
,
to
:
0
},
},
output
:
`Created foo-v2
Scaling up foo-v2 from 0 to 2, scaling down foo-v1 from 30 to 0 (keep 1 pods available, don't exceed 30 pods)
Scaling foo-v1 down to 1
Scaling foo-v2 up to 2
Scaling foo-v1 down to 0
`
,
},
}
for
i
,
test
:=
range
tests
{
...
...
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