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
f618cb47
Commit
f618cb47
authored
Feb 18, 2016
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #20696 from janetkuo/deployment-new-rc-replicas
Auto commit by PR queue bot
parents
ef6ae486
fe4bf6ff
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
39 deletions
+91
-39
deployment_controller.go
pkg/controller/deployment/deployment_controller.go
+54
-39
deployment.go
pkg/util/deployment/deployment.go
+37
-0
No files found.
pkg/controller/deployment/deployment_controller.go
View file @
f618cb47
This diff is collapsed.
Click to expand it.
pkg/util/deployment/deployment.go
View file @
f618cb47
...
@@ -26,6 +26,8 @@ import (
...
@@ -26,6 +26,8 @@ import (
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/extensions"
clientset
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
clientset
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/util/integer"
intstrutil
"k8s.io/kubernetes/pkg/util/intstr"
labelsutil
"k8s.io/kubernetes/pkg/util/labels"
labelsutil
"k8s.io/kubernetes/pkg/util/labels"
podutil
"k8s.io/kubernetes/pkg/util/pod"
podutil
"k8s.io/kubernetes/pkg/util/pod"
)
)
...
@@ -233,3 +235,38 @@ func Revision(rs *extensions.ReplicaSet) (int64, error) {
...
@@ -233,3 +235,38 @@ func Revision(rs *extensions.ReplicaSet) (int64, error) {
}
}
return
strconv
.
ParseInt
(
v
,
10
,
64
)
return
strconv
.
ParseInt
(
v
,
10
,
64
)
}
}
func
IsRollingUpdate
(
deployment
*
extensions
.
Deployment
)
bool
{
return
deployment
.
Spec
.
Strategy
.
Type
==
extensions
.
RollingUpdateDeploymentStrategyType
}
// NewRSNewReplicas calculates the number of replicas a deployment's new RS should have.
// When one of the followings is true, we're rolling out the deployment; otherwise, we're scaling it.
// 1) The new RS is saturated: newRS's replicas == deployment's replicas
// 2) Max number of pods allowed is reached: deployment's replicas + maxSurge == all RSs' replicas
func
NewRSNewReplicas
(
deployment
*
extensions
.
Deployment
,
allRSs
[]
*
extensions
.
ReplicaSet
,
newRS
*
extensions
.
ReplicaSet
)
(
int
,
error
)
{
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
)
if
err
!=
nil
{
return
0
,
err
}
// Find the total number of pods
currentPodCount
:=
GetReplicaCountForReplicaSets
(
allRSs
)
maxTotalPods
:=
deployment
.
Spec
.
Replicas
+
maxSurge
if
currentPodCount
>=
maxTotalPods
{
// Cannot scale up.
return
newRS
.
Spec
.
Replicas
,
nil
}
// Scale up.
scaleUpCount
:=
maxTotalPods
-
currentPodCount
// Do not exceed the number of desired replicas.
scaleUpCount
=
integer
.
IntMin
(
scaleUpCount
,
deployment
.
Spec
.
Replicas
-
newRS
.
Spec
.
Replicas
)
return
newRS
.
Spec
.
Replicas
+
scaleUpCount
,
nil
case
extensions
.
RecreateDeploymentStrategyType
:
return
deployment
.
Spec
.
Replicas
,
nil
default
:
return
0
,
fmt
.
Errorf
(
"deployment type %v isn't supported"
,
deployment
.
Spec
.
Strategy
.
Type
)
}
}
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