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
d96cdb93
Commit
d96cdb93
authored
Feb 11, 2016
by
mqliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move helper funcs to util/deployment.go from util.go
parent
b1dedc09
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
31 deletions
+27
-31
deployment_controller.go
pkg/controller/deployment/deployment_controller.go
+6
-7
intstr.go
pkg/util/intstr/intstr.go
+21
-0
util.go
pkg/util/util.go
+0
-24
No files found.
pkg/controller/deployment/deployment_controller.go
View file @
d96cdb93
...
@@ -35,7 +35,6 @@ import (
...
@@ -35,7 +35,6 @@ import (
"k8s.io/kubernetes/pkg/controller/framework"
"k8s.io/kubernetes/pkg/controller/framework"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
deploymentutil
"k8s.io/kubernetes/pkg/util/deployment"
deploymentutil
"k8s.io/kubernetes/pkg/util/deployment"
utilerrors
"k8s.io/kubernetes/pkg/util/errors"
utilerrors
"k8s.io/kubernetes/pkg/util/errors"
"k8s.io/kubernetes/pkg/util/integer"
"k8s.io/kubernetes/pkg/util/integer"
...
@@ -768,12 +767,12 @@ func (dc *DeploymentController) reconcileNewReplicaSet(allRSs []*extensions.Repl
...
@@ -768,12 +767,12 @@ func (dc *DeploymentController) reconcileNewReplicaSet(allRSs []*extensions.Repl
return
true
,
err
return
true
,
err
}
}
// Check if we can scale up.
// Check if we can scale up.
maxSurge
,
isPercent
,
err
:=
util
.
GetIntOrPercentValue
(
&
deployment
.
Spec
.
Strategy
.
RollingUpdate
.
MaxSurge
)
maxSurge
,
isPercent
,
err
:=
intstr
util
.
GetIntOrPercentValue
(
&
deployment
.
Spec
.
Strategy
.
RollingUpdate
.
MaxSurge
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"invalid value for MaxSurge: %v"
,
err
)
return
false
,
fmt
.
Errorf
(
"invalid value for MaxSurge: %v"
,
err
)
}
}
if
isPercent
{
if
isPercent
{
maxSurge
=
util
.
GetValueFromPercent
(
maxSurge
,
deployment
.
Spec
.
Replicas
)
maxSurge
=
intstr
util
.
GetValueFromPercent
(
maxSurge
,
deployment
.
Spec
.
Replicas
)
}
}
// Find the total number of pods
// Find the total number of pods
currentPodCount
:=
deploymentutil
.
GetReplicaCountForReplicaSets
(
allRSs
)
currentPodCount
:=
deploymentutil
.
GetReplicaCountForReplicaSets
(
allRSs
)
...
@@ -816,12 +815,12 @@ func (dc *DeploymentController) reconcileOldReplicaSets(allRSs []*extensions.Rep
...
@@ -816,12 +815,12 @@ 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
,
isPercent
,
err
:=
util
.
GetIntOrPercentValue
(
&
deployment
.
Spec
.
Strategy
.
RollingUpdate
.
MaxUnavailable
)
maxUnavailable
,
isPercent
,
err
:=
intstr
util
.
GetIntOrPercentValue
(
&
deployment
.
Spec
.
Strategy
.
RollingUpdate
.
MaxUnavailable
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"invalid value for MaxUnavailable: %v"
,
err
)
return
false
,
fmt
.
Errorf
(
"invalid value for MaxUnavailable: %v"
,
err
)
}
}
if
isPercent
{
if
isPercent
{
maxUnavailable
=
util
.
GetValueFromPercent
(
maxUnavailable
,
deployment
.
Spec
.
Replicas
)
maxUnavailable
=
intstr
util
.
GetValueFromPercent
(
maxUnavailable
,
deployment
.
Spec
.
Replicas
)
}
}
// Check if we can scale down. We can scale down in the following 2 cases:
// Check if we can scale down. We can scale down in the following 2 cases:
...
@@ -920,12 +919,12 @@ func (dc *DeploymentController) cleanupUnhealthyReplicas(oldRSs []*extensions.Re
...
@@ -920,12 +919,12 @@ 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
,
isPercent
,
err
:=
util
.
GetIntOrPercentValue
(
&
deployment
.
Spec
.
Strategy
.
RollingUpdate
.
MaxUnavailable
)
maxUnavailable
,
isPercent
,
err
:=
intstr
util
.
GetIntOrPercentValue
(
&
deployment
.
Spec
.
Strategy
.
RollingUpdate
.
MaxUnavailable
)
if
err
!=
nil
{
if
err
!=
nil
{
return
0
,
fmt
.
Errorf
(
"invalid value for MaxUnavailable: %v"
,
err
)
return
0
,
fmt
.
Errorf
(
"invalid value for MaxUnavailable: %v"
,
err
)
}
}
if
isPercent
{
if
isPercent
{
maxUnavailable
=
util
.
GetValueFromPercent
(
maxUnavailable
,
deployment
.
Spec
.
Replicas
)
maxUnavailable
=
intstr
util
.
GetValueFromPercent
(
maxUnavailable
,
deployment
.
Spec
.
Replicas
)
}
}
// Check if we can scale down.
// Check if we can scale down.
minAvailable
:=
deployment
.
Spec
.
Replicas
-
maxUnavailable
minAvailable
:=
deployment
.
Spec
.
Replicas
-
maxUnavailable
...
...
pkg/util/intstr/intstr.go
View file @
d96cdb93
...
@@ -19,7 +19,9 @@ package intstr
...
@@ -19,7 +19,9 @@ package intstr
import
(
import
(
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"math"
"strconv"
"strconv"
"strings"
"github.com/google/gofuzz"
"github.com/google/gofuzz"
)
)
...
@@ -113,3 +115,22 @@ func (intstr *IntOrString) Fuzz(c fuzz.Continue) {
...
@@ -113,3 +115,22 @@ func (intstr *IntOrString) Fuzz(c fuzz.Continue) {
c
.
Fuzz
(
&
intstr
.
StrVal
)
c
.
Fuzz
(
&
intstr
.
StrVal
)
}
}
}
}
func
GetIntOrPercentValue
(
intOrStr
*
IntOrString
)
(
int
,
bool
,
error
)
{
switch
intOrStr
.
Type
{
case
Int
:
return
intOrStr
.
IntValue
(),
false
,
nil
case
String
:
s
:=
strings
.
Replace
(
intOrStr
.
StrVal
,
"%"
,
""
,
-
1
)
v
,
err
:=
strconv
.
Atoi
(
s
)
if
err
!=
nil
{
return
0
,
false
,
fmt
.
Errorf
(
"invalid value %q: %v"
,
intOrStr
.
StrVal
,
err
)
}
return
int
(
v
),
true
,
nil
}
return
0
,
false
,
fmt
.
Errorf
(
"invalid value: neither int nor percentage"
)
}
func
GetValueFromPercent
(
percent
int
,
value
int
)
int
{
return
int
(
math
.
Ceil
(
float64
(
percent
)
*
(
float64
(
value
))
/
100
))
}
pkg/util/util.go
View file @
d96cdb93
...
@@ -18,35 +18,11 @@ package util
...
@@ -18,35 +18,11 @@ package util
import
(
import
(
"fmt"
"fmt"
"math"
"os"
"os"
"reflect"
"reflect"
"regexp"
"regexp"
"strconv"
"strings"
"k8s.io/kubernetes/pkg/util/intstr"
)
)
func
GetIntOrPercentValue
(
intOrStr
*
intstr
.
IntOrString
)
(
int
,
bool
,
error
)
{
switch
intOrStr
.
Type
{
case
intstr
.
Int
:
return
intOrStr
.
IntValue
(),
false
,
nil
case
intstr
.
String
:
s
:=
strings
.
Replace
(
intOrStr
.
StrVal
,
"%"
,
""
,
-
1
)
v
,
err
:=
strconv
.
Atoi
(
s
)
if
err
!=
nil
{
return
0
,
false
,
fmt
.
Errorf
(
"invalid value %q: %v"
,
intOrStr
.
StrVal
,
err
)
}
return
int
(
v
),
true
,
nil
}
return
0
,
false
,
fmt
.
Errorf
(
"invalid value: neither int nor percentage"
)
}
func
GetValueFromPercent
(
percent
int
,
value
int
)
int
{
return
int
(
math
.
Ceil
(
float64
(
percent
)
*
(
float64
(
value
))
/
100
))
}
// Takes a list of strings and compiles them into a list of regular expressions
// Takes a list of strings and compiles them into a list of regular expressions
func
CompileRegexps
(
regexpStrings
[]
string
)
([]
*
regexp
.
Regexp
,
error
)
{
func
CompileRegexps
(
regexpStrings
[]
string
)
([]
*
regexp
.
Regexp
,
error
)
{
regexps
:=
[]
*
regexp
.
Regexp
{}
regexps
:=
[]
*
regexp
.
Regexp
{}
...
...
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