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
b27edde3
Commit
b27edde3
authored
Feb 24, 2016
by
Brian Grant
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #21957 from mqliang/deployment-preserve-availability
Deployment: preserve availability when maxUnavailability is not 100%
parents
be6515ca
06d57ec7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
7 deletions
+27
-7
deployment_controller.go
pkg/controller/deployment/deployment_controller.go
+2
-2
deployment.go
pkg/util/deployment/deployment.go
+1
-1
intstr.go
pkg/util/intstr/intstr.go
+6
-2
intstr_test.go
pkg/util/intstr/intstr_test.go
+18
-2
No files found.
pkg/controller/deployment/deployment_controller.go
View file @
b27edde3
...
...
@@ -847,7 +847,7 @@ func (dc *DeploymentController) reconcileOldReplicaSets(allRSs []*extensions.Rep
return
false
,
fmt
.
Errorf
(
"could not find available pods: %v"
,
err
)
}
maxUnavailable
,
err
:=
intstrutil
.
GetValueFromIntOrPercent
(
&
deployment
.
Spec
.
Strategy
.
RollingUpdate
.
MaxUnavailable
,
deployment
.
Spec
.
Replicas
)
maxUnavailable
,
err
:=
intstrutil
.
GetValueFromIntOrPercent
(
&
deployment
.
Spec
.
Strategy
.
RollingUpdate
.
MaxUnavailable
,
deployment
.
Spec
.
Replicas
,
false
)
if
err
!=
nil
{
return
false
,
err
}
...
...
@@ -948,7 +948,7 @@ func (dc *DeploymentController) cleanupUnhealthyReplicas(oldRSs []*extensions.Re
// scaleDownOldReplicaSetsForRollingUpdate scales down old replica sets when deployment strategy is "RollingUpdate".
// Need check maxUnavailable to ensure availability
func
(
dc
*
DeploymentController
)
scaleDownOldReplicaSetsForRollingUpdate
(
allRSs
[]
*
extensions
.
ReplicaSet
,
oldRSs
[]
*
extensions
.
ReplicaSet
,
deployment
extensions
.
Deployment
)
(
int
,
error
)
{
maxUnavailable
,
err
:=
intstrutil
.
GetValueFromIntOrPercent
(
&
deployment
.
Spec
.
Strategy
.
RollingUpdate
.
MaxUnavailable
,
deployment
.
Spec
.
Replicas
)
maxUnavailable
,
err
:=
intstrutil
.
GetValueFromIntOrPercent
(
&
deployment
.
Spec
.
Strategy
.
RollingUpdate
.
MaxUnavailable
,
deployment
.
Spec
.
Replicas
,
false
)
if
err
!=
nil
{
return
0
,
err
}
...
...
pkg/util/deployment/deployment.go
View file @
b27edde3
...
...
@@ -435,7 +435,7 @@ func NewRSNewReplicas(deployment *extensions.Deployment, allRSs []*extensions.Re
switch
deployment
.
Spec
.
Strategy
.
Type
{
case
extensions
.
RollingUpdateDeploymentStrategyType
:
// Check if we can scale up.
maxSurge
,
err
:=
intstrutil
.
GetValueFromIntOrPercent
(
&
deployment
.
Spec
.
Strategy
.
RollingUpdate
.
MaxSurge
,
deployment
.
Spec
.
Replicas
)
maxSurge
,
err
:=
intstrutil
.
GetValueFromIntOrPercent
(
&
deployment
.
Spec
.
Strategy
.
RollingUpdate
.
MaxSurge
,
deployment
.
Spec
.
Replicas
,
true
)
if
err
!=
nil
{
return
0
,
err
}
...
...
pkg/util/intstr/intstr.go
View file @
b27edde3
...
...
@@ -116,13 +116,17 @@ func (intstr *IntOrString) Fuzz(c fuzz.Continue) {
}
}
func
GetValueFromIntOrPercent
(
intOrPercent
*
IntOrString
,
total
int
)
(
int
,
error
)
{
func
GetValueFromIntOrPercent
(
intOrPercent
*
IntOrString
,
total
int
,
roundUp
bool
)
(
int
,
error
)
{
value
,
isPercent
,
err
:=
getIntOrPercentValue
(
intOrPercent
)
if
err
!=
nil
{
return
0
,
fmt
.
Errorf
(
"invalid value for IntOrString: %v"
,
err
)
}
if
isPercent
{
value
=
int
(
math
.
Ceil
(
float64
(
value
)
*
(
float64
(
total
))
/
100
))
if
roundUp
{
value
=
int
(
math
.
Ceil
(
float64
(
value
)
*
(
float64
(
total
))
/
100
))
}
else
{
value
=
int
(
math
.
Floor
(
float64
(
value
)
*
(
float64
(
total
))
/
100
))
}
}
return
value
,
nil
}
...
...
pkg/util/intstr/intstr_test.go
View file @
b27edde3
...
...
@@ -114,6 +114,7 @@ func TestGetValueFromIntOrPercent(t *testing.T) {
tests
:=
[]
struct
{
input
IntOrString
total
int
roundUp
bool
expectErr
bool
expectVal
int
}{
...
...
@@ -125,10 +126,25 @@ func TestGetValueFromIntOrPercent(t *testing.T) {
{
input
:
FromString
(
"90%"
),
total
:
100
,
roundUp
:
true
,
expectErr
:
false
,
expectVal
:
90
,
},
{
input
:
FromString
(
"90%"
),
total
:
95
,
roundUp
:
true
,
expectErr
:
false
,
expectVal
:
86
,
},
{
input
:
FromString
(
"90%"
),
total
:
95
,
roundUp
:
false
,
expectErr
:
false
,
expectVal
:
85
,
},
{
input
:
FromString
(
"%"
),
expectErr
:
true
,
},
...
...
@@ -144,7 +160,7 @@ func TestGetValueFromIntOrPercent(t *testing.T) {
for
i
,
test
:=
range
tests
{
t
.
Logf
(
"test case %d"
,
i
)
value
,
err
:=
GetValueFromIntOrPercent
(
&
test
.
input
,
test
.
total
)
value
,
err
:=
GetValueFromIntOrPercent
(
&
test
.
input
,
test
.
total
,
test
.
roundUp
)
if
test
.
expectErr
&&
err
==
nil
{
t
.
Errorf
(
"expected error, but got none"
)
continue
...
...
@@ -154,7 +170,7 @@ func TestGetValueFromIntOrPercent(t *testing.T) {
continue
}
if
test
.
expectVal
!=
value
{
t
.
Errorf
(
"expected %v, but got %v"
,
test
.
expect
Err
,
value
)
t
.
Errorf
(
"expected %v, but got %v"
,
test
.
expect
Val
,
value
)
}
}
}
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