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
06d57ec7
Commit
06d57ec7
authored
Feb 25, 2016
by
mqliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Deployment: preserve availability when maxUnavailability is not 100%
parent
9a4e3f84
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 @
06d57ec7
...
@@ -847,7 +847,7 @@ func (dc *DeploymentController) reconcileOldReplicaSets(allRSs []*extensions.Rep
...
@@ -847,7 +847,7 @@ func (dc *DeploymentController) reconcileOldReplicaSets(allRSs []*extensions.Rep
return
false
,
fmt
.
Errorf
(
"could not find available pods: %v"
,
err
)
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
{
if
err
!=
nil
{
return
false
,
err
return
false
,
err
}
}
...
@@ -948,7 +948,7 @@ func (dc *DeploymentController) cleanupUnhealthyReplicas(oldRSs []*extensions.Re
...
@@ -948,7 +948,7 @@ func (dc *DeploymentController) cleanupUnhealthyReplicas(oldRSs []*extensions.Re
// scaleDownOldReplicaSetsForRollingUpdate scales down old replica sets when deployment strategy is "RollingUpdate".
// scaleDownOldReplicaSetsForRollingUpdate scales down old replica sets when deployment strategy is "RollingUpdate".
// Need check maxUnavailable to ensure availability
// Need check maxUnavailable to ensure availability
func
(
dc
*
DeploymentController
)
scaleDownOldReplicaSetsForRollingUpdate
(
allRSs
[]
*
extensions
.
ReplicaSet
,
oldRSs
[]
*
extensions
.
ReplicaSet
,
deployment
extensions
.
Deployment
)
(
int
,
error
)
{
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
{
if
err
!=
nil
{
return
0
,
err
return
0
,
err
}
}
...
...
pkg/util/deployment/deployment.go
View file @
06d57ec7
...
@@ -420,7 +420,7 @@ func NewRSNewReplicas(deployment *extensions.Deployment, allRSs []*extensions.Re
...
@@ -420,7 +420,7 @@ func NewRSNewReplicas(deployment *extensions.Deployment, allRSs []*extensions.Re
switch
deployment
.
Spec
.
Strategy
.
Type
{
switch
deployment
.
Spec
.
Strategy
.
Type
{
case
extensions
.
RollingUpdateDeploymentStrategyType
:
case
extensions
.
RollingUpdateDeploymentStrategyType
:
// Check if we can scale up.
// 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
{
if
err
!=
nil
{
return
0
,
err
return
0
,
err
}
}
...
...
pkg/util/intstr/intstr.go
View file @
06d57ec7
...
@@ -116,13 +116,17 @@ func (intstr *IntOrString) Fuzz(c fuzz.Continue) {
...
@@ -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
)
value
,
isPercent
,
err
:=
getIntOrPercentValue
(
intOrPercent
)
if
err
!=
nil
{
if
err
!=
nil
{
return
0
,
fmt
.
Errorf
(
"invalid value for IntOrString: %v"
,
err
)
return
0
,
fmt
.
Errorf
(
"invalid value for IntOrString: %v"
,
err
)
}
}
if
isPercent
{
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
return
value
,
nil
}
}
...
...
pkg/util/intstr/intstr_test.go
View file @
06d57ec7
...
@@ -114,6 +114,7 @@ func TestGetValueFromIntOrPercent(t *testing.T) {
...
@@ -114,6 +114,7 @@ func TestGetValueFromIntOrPercent(t *testing.T) {
tests
:=
[]
struct
{
tests
:=
[]
struct
{
input
IntOrString
input
IntOrString
total
int
total
int
roundUp
bool
expectErr
bool
expectErr
bool
expectVal
int
expectVal
int
}{
}{
...
@@ -125,10 +126,25 @@ func TestGetValueFromIntOrPercent(t *testing.T) {
...
@@ -125,10 +126,25 @@ func TestGetValueFromIntOrPercent(t *testing.T) {
{
{
input
:
FromString
(
"90%"
),
input
:
FromString
(
"90%"
),
total
:
100
,
total
:
100
,
roundUp
:
true
,
expectErr
:
false
,
expectErr
:
false
,
expectVal
:
90
,
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
(
"%"
),
input
:
FromString
(
"%"
),
expectErr
:
true
,
expectErr
:
true
,
},
},
...
@@ -144,7 +160,7 @@ func TestGetValueFromIntOrPercent(t *testing.T) {
...
@@ -144,7 +160,7 @@ func TestGetValueFromIntOrPercent(t *testing.T) {
for
i
,
test
:=
range
tests
{
for
i
,
test
:=
range
tests
{
t
.
Logf
(
"test case %d"
,
i
)
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
{
if
test
.
expectErr
&&
err
==
nil
{
t
.
Errorf
(
"expected error, but got none"
)
t
.
Errorf
(
"expected error, but got none"
)
continue
continue
...
@@ -154,7 +170,7 @@ func TestGetValueFromIntOrPercent(t *testing.T) {
...
@@ -154,7 +170,7 @@ func TestGetValueFromIntOrPercent(t *testing.T) {
continue
continue
}
}
if
test
.
expectVal
!=
value
{
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