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
63feac0a
Commit
63feac0a
authored
Feb 25, 2016
by
Brian Grant
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #21872 from kargakis/maxUavailability-fix
kubectl: preserve availability when maxUnavailability is not 100%
parents
3b10ce15
9cc19102
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
103 deletions
+27
-103
rolling_updater.go
pkg/kubectl/rolling_updater.go
+2
-26
rolling_updater_test.go
pkg/kubectl/rolling_updater_test.go
+25
-77
No files found.
pkg/kubectl/rolling_updater.go
View file @
63feac0a
...
@@ -20,7 +20,6 @@ import (
...
@@ -20,7 +20,6 @@ import (
goerrors
"errors"
goerrors
"errors"
"fmt"
"fmt"
"io"
"io"
"math"
"strconv"
"strconv"
"strings"
"strings"
"time"
"time"
...
@@ -198,12 +197,12 @@ func (r *RollingUpdater) Update(config *RollingUpdaterConfig) error {
...
@@ -198,12 +197,12 @@ func (r *RollingUpdater) Update(config *RollingUpdaterConfig) error {
oldRc
.
Name
,
originalReplicasAnnotation
,
oldRc
.
Annotations
[
originalReplicasAnnotation
])
oldRc
.
Name
,
originalReplicasAnnotation
,
oldRc
.
Annotations
[
originalReplicasAnnotation
])
}
}
// The maximum pods which can go unavailable during the update.
// The maximum pods which can go unavailable during the update.
maxUnavailable
,
err
:=
extractMaxValue
(
config
.
MaxUnavailable
,
"maxUnavailable"
,
desired
)
maxUnavailable
,
err
:=
intstr
.
GetValueFromIntOrPercent
(
&
config
.
MaxUnavailable
,
desired
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
// The maximum scaling increment.
// The maximum scaling increment.
maxSurge
,
err
:=
extractMaxValue
(
config
.
MaxSurge
,
"maxSurge"
,
desired
)
maxSurge
,
err
:=
intstr
.
GetValueFromIntOrPercent
(
&
config
.
MaxSurge
,
desired
,
true
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -486,29 +485,6 @@ func (r *RollingUpdater) cleanupWithClients(oldRc, newRc *api.ReplicationControl
...
@@ -486,29 +485,6 @@ func (r *RollingUpdater) cleanupWithClients(oldRc, newRc *api.ReplicationControl
}
}
}
}
// func extractMaxValue is a helper to extract config max values as either
// absolute numbers or based on percentages of the given value.
func
extractMaxValue
(
field
intstr
.
IntOrString
,
name
string
,
value
int
)
(
int
,
error
)
{
switch
field
.
Type
{
case
intstr
.
Int
:
if
field
.
IntVal
<
0
{
return
0
,
fmt
.
Errorf
(
"%s must be >= 0"
,
name
)
}
return
field
.
IntValue
(),
nil
case
intstr
.
String
:
s
:=
strings
.
Replace
(
field
.
StrVal
,
"%"
,
""
,
-
1
)
v
,
err
:=
strconv
.
Atoi
(
s
)
if
err
!=
nil
{
return
0
,
fmt
.
Errorf
(
"invalid %s value %q: %v"
,
name
,
field
.
StrVal
,
err
)
}
if
v
<
0
{
return
0
,
fmt
.
Errorf
(
"%s must be >= 0"
,
name
)
}
return
int
(
math
.
Ceil
(
float64
(
value
)
*
(
float64
(
v
))
/
100
)),
nil
}
return
0
,
fmt
.
Errorf
(
"invalid kind %q for %s"
,
field
.
Type
,
name
)
}
func
Rename
(
c
client
.
ReplicationControllersNamespacer
,
rc
*
api
.
ReplicationController
,
newName
string
)
error
{
func
Rename
(
c
client
.
ReplicationControllersNamespacer
,
rc
*
api
.
ReplicationController
,
newName
string
)
error
{
oldName
:=
rc
.
Name
oldName
:=
rc
.
Name
rc
.
Name
=
newName
rc
.
Name
=
newName
...
...
pkg/kubectl/rolling_updater_test.go
View file @
63feac0a
...
@@ -430,20 +430,21 @@ Scaling foo-v1 down to 0
...
@@ -430,20 +430,21 @@ Scaling foo-v1 down to 0
Scaling foo-v2 up to 10
Scaling foo-v2 up to 10
`
,
`
,
},
{
},
{
name
:
"1->1
10/0 fast readiness
"
,
name
:
"1->1
25/25 maintain minimum availability
"
,
oldRc
:
oldRc
(
1
,
1
),
oldRc
:
oldRc
(
1
,
1
),
newRc
:
newRc
(
0
,
1
),
newRc
:
newRc
(
0
,
1
),
newRcExists
:
false
,
newRcExists
:
false
,
maxUnavail
:
intstr
.
FromString
(
"
10
%"
),
maxUnavail
:
intstr
.
FromString
(
"
25
%"
),
maxSurge
:
intstr
.
FromString
(
"
0
%"
),
maxSurge
:
intstr
.
FromString
(
"
25
%"
),
expected
:
[]
interface
{}{
expected
:
[]
interface
{}{
down
{
oldReady
:
1
,
newReady
:
0
,
to
:
0
},
up
{
1
},
up
{
1
},
down
{
oldReady
:
1
,
newReady
:
0
,
noop
:
true
},
down
{
oldReady
:
1
,
newReady
:
1
,
to
:
0
},
},
},
output
:
`Created foo-v2
output
:
`Created foo-v2
Scaling up foo-v2 from 0 to 1, scaling down foo-v1 from 1 to 0 (keep 0 pods available, don't exceed 1 pods)
Scaling up foo-v2 from 0 to 1, scaling down foo-v1 from 1 to 0 (keep 1 pods available, don't exceed 2 pods)
Scaling foo-v1 down to 0
Scaling foo-v2 up to 1
Scaling foo-v2 up to 1
Scaling foo-v1 down to 0
`
,
`
,
},
{
},
{
name
:
"1->1 0/10 delayed readiness"
,
name
:
"1->1 0/10 delayed readiness"
,
...
@@ -475,7 +476,7 @@ Scaling foo-v1 down to 0
...
@@ -475,7 +476,7 @@ Scaling foo-v1 down to 0
down
{
oldReady
:
1
,
newReady
:
1
,
to
:
0
},
down
{
oldReady
:
1
,
newReady
:
1
,
to
:
0
},
},
},
output
:
`Created foo-v2
output
:
`Created foo-v2
Scaling up foo-v2 from 0 to 1, scaling down foo-v1 from 1 to 0 (keep
0
pods available, don't exceed 2 pods)
Scaling up foo-v2 from 0 to 1, scaling down foo-v1 from 1 to 0 (keep
1
pods available, don't exceed 2 pods)
Scaling foo-v2 up to 1
Scaling foo-v2 up to 1
Scaling foo-v1 down to 0
Scaling foo-v1 down to 0
`
,
`
,
...
@@ -657,6 +658,23 @@ Scaling foo-v1 down to 0
...
@@ -657,6 +658,23 @@ Scaling foo-v1 down to 0
Scaling foo-v2 up to 2
Scaling foo-v2 up to 2
`
,
`
,
},
},
{
name
:
"1->1 100%/0 allow maxUnavailability"
,
oldRc
:
oldRc
(
1
,
1
),
newRc
:
newRc
(
0
,
1
),
newRcExists
:
false
,
maxUnavail
:
intstr
.
FromString
(
"100%"
),
maxSurge
:
intstr
.
FromInt
(
0
),
expected
:
[]
interface
{}{
down
{
oldReady
:
1
,
newReady
:
0
,
to
:
0
},
up
{
1
},
},
output
:
`Created foo-v2
Scaling up foo-v2 from 0 to 1, scaling down foo-v1 from 1 to 0 (keep 0 pods available, don't exceed 1 pods)
Scaling foo-v1 down to 0
Scaling foo-v2 up to 1
`
,
},
}
}
for
i
,
test
:=
range
tests
{
for
i
,
test
:=
range
tests
{
...
@@ -1571,73 +1589,3 @@ func TestRollingUpdater_readyPods(t *testing.T) {
...
@@ -1571,73 +1589,3 @@ func TestRollingUpdater_readyPods(t *testing.T) {
}
}
}
}
}
}
func
TestRollingUpdater_extractMaxValue
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
field
intstr
.
IntOrString
original
int
expected
int
valid
bool
}{
{
field
:
intstr
.
FromInt
(
1
),
original
:
100
,
expected
:
1
,
valid
:
true
,
},
{
field
:
intstr
.
FromInt
(
0
),
original
:
100
,
expected
:
0
,
valid
:
true
,
},
{
field
:
intstr
.
FromInt
(
-
1
),
original
:
100
,
valid
:
false
,
},
{
field
:
intstr
.
FromString
(
"10%"
),
original
:
100
,
expected
:
10
,
valid
:
true
,
},
{
field
:
intstr
.
FromString
(
"100%"
),
original
:
100
,
expected
:
100
,
valid
:
true
,
},
{
field
:
intstr
.
FromString
(
"200%"
),
original
:
100
,
expected
:
200
,
valid
:
true
,
},
{
field
:
intstr
.
FromString
(
"0%"
),
original
:
100
,
expected
:
0
,
valid
:
true
,
},
{
field
:
intstr
.
FromString
(
"-1%"
),
original
:
100
,
valid
:
false
,
},
}
for
i
,
test
:=
range
tests
{
t
.
Logf
(
"evaluating test %d"
,
i
)
max
,
err
:=
extractMaxValue
(
test
.
field
,
"field"
,
test
.
original
)
if
test
.
valid
&&
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
!
test
.
valid
&&
err
==
nil
{
t
.
Fatalf
(
"expected an error"
)
}
if
e
,
a
:=
test
.
expected
,
max
;
e
!=
a
{
t
.
Fatalf
(
"expected max %d, got %d"
,
e
,
a
)
}
}
}
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