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
ee8598fd
Commit
ee8598fd
authored
Dec 05, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #17137 from janetkuo/deployment-minreadysec
Auto commit by PR queue bot
parents
8c7e5004
8fb0caa1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
106 additions
and
11 deletions
+106
-11
deployments.md
docs/user-guide/deployments.md
+0
-1
deployment_controller.go
pkg/controller/deployment/deployment_controller.go
+2
-1
deployment.go
pkg/util/deployment/deployment.go
+23
-5
deployment_test.go
pkg/util/deployment/deployment_test.go
+77
-0
deployment.go
test/e2e/deployment.go
+2
-2
util.go
test/e2e/util.go
+2
-2
No files found.
docs/user-guide/deployments.md
View file @
ee8598fd
...
@@ -402,7 +402,6 @@ at any time during the update is at most 130% of desired pods.
...
@@ -402,7 +402,6 @@ at any time during the update is at most 130% of desired pods.
minimum number of seconds for which a newly created pod should be ready
minimum number of seconds for which a newly created pod should be ready
without any of its containers crashing, for it to be considered available.
without any of its containers crashing, for it to be considered available.
This defaults to 0 (the pod will be considered available as soon as it is ready).
This defaults to 0 (the pod will be considered available as soon as it is ready).
__Note: This is not implemented yet__
.
## Alternative to Deployments
## Alternative to Deployments
...
...
pkg/controller/deployment/deployment_controller.go
View file @
ee8598fd
...
@@ -208,8 +208,9 @@ func (d *DeploymentController) reconcileOldRCs(allRCs []*api.ReplicationControll
...
@@ -208,8 +208,9 @@ func (d *DeploymentController) reconcileOldRCs(allRCs []*api.ReplicationControll
}
}
// Check if we can scale down.
// Check if we can scale down.
minAvailable
:=
deployment
.
Spec
.
Replicas
-
maxUnavailable
minAvailable
:=
deployment
.
Spec
.
Replicas
-
maxUnavailable
minReadySeconds
:=
deployment
.
Spec
.
Strategy
.
RollingUpdate
.
MinReadySeconds
// Find the number of ready pods.
// Find the number of ready pods.
readyPodCount
,
err
:=
deploymentutil
.
GetAvailablePodsForRCs
(
d
.
client
,
allRCs
)
readyPodCount
,
err
:=
deploymentutil
.
GetAvailablePodsForRCs
(
d
.
client
,
allRCs
,
minReadySeconds
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"could not find available pods: %v"
,
err
)
return
false
,
fmt
.
Errorf
(
"could not find available pods: %v"
,
err
)
}
}
...
...
pkg/util/deployment/deployment.go
View file @
ee8598fd
...
@@ -19,6 +19,7 @@ package deployment
...
@@ -19,6 +19,7 @@ package deployment
import
(
import
(
"fmt"
"fmt"
"hash/adler32"
"hash/adler32"
"time"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/unversioned"
...
@@ -132,19 +133,36 @@ func GetReplicaCountForRCs(replicationControllers []*api.ReplicationController)
...
@@ -132,19 +133,36 @@ func GetReplicaCountForRCs(replicationControllers []*api.ReplicationController)
}
}
// Returns the number of available pods corresponding to the given RCs.
// Returns the number of available pods corresponding to the given RCs.
func
GetAvailablePodsForRCs
(
c
client
.
Interface
,
rcs
[]
*
api
.
ReplicationController
)
(
int
,
error
)
{
func
GetAvailablePodsForRCs
(
c
client
.
Interface
,
rcs
[]
*
api
.
ReplicationController
,
minReadySeconds
int
)
(
int
,
error
)
{
// TODO: Use MinReadySeconds once https://github.com/kubernetes/kubernetes/pull/12894 is merged.
allPods
,
err
:=
getPodsForRCs
(
c
,
rcs
)
allPods
,
err
:=
getPodsForRCs
(
c
,
rcs
)
if
err
!=
nil
{
if
err
!=
nil
{
return
0
,
err
return
0
,
err
}
}
return
getReadyPodsCount
(
allPods
,
minReadySeconds
),
nil
}
func
getReadyPodsCount
(
pods
[]
api
.
Pod
,
minReadySeconds
int
)
int
{
readyPodCount
:=
0
readyPodCount
:=
0
for
_
,
pod
:=
range
allP
ods
{
for
_
,
pod
:=
range
p
ods
{
if
api
.
IsPodReady
(
&
pod
)
{
if
api
.
IsPodReady
(
&
pod
)
{
readyPodCount
++
// Check if we've passed minReadySeconds since LastTransitionTime
// If so, this pod is ready
for
_
,
c
:=
range
pod
.
Status
.
Conditions
{
// we only care about pod ready conditions
if
c
.
Type
==
api
.
PodReady
{
// 2 cases that this ready condition is valid (passed minReadySeconds, i.e. the pod is ready):
// 1. minReadySeconds <= 0
// 2. LastTransitionTime (is set) + minReadySeconds (>0) < current time
minReadySecondsDuration
:=
time
.
Duration
(
minReadySeconds
)
*
time
.
Second
if
minReadySeconds
<=
0
||
!
c
.
LastTransitionTime
.
IsZero
()
&&
c
.
LastTransitionTime
.
Add
(
minReadySecondsDuration
)
.
Before
(
time
.
Now
())
{
readyPodCount
++
break
}
}
}
}
}
}
}
return
readyPodCount
,
nil
return
readyPodCount
}
}
func
getPodsForRCs
(
c
client
.
Interface
,
replicationControllers
[]
*
api
.
ReplicationController
)
([]
api
.
Pod
,
error
)
{
func
getPodsForRCs
(
c
client
.
Interface
,
replicationControllers
[]
*
api
.
ReplicationController
)
([]
api
.
Pod
,
error
)
{
...
...
pkg/util/deployment/deployment_test.go
0 → 100644
View file @
ee8598fd
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
deployment
import
(
"testing"
"time"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
)
func
newPod
(
now
time
.
Time
,
ready
bool
,
beforeSec
int
)
api
.
Pod
{
conditionStatus
:=
api
.
ConditionFalse
if
ready
{
conditionStatus
=
api
.
ConditionTrue
}
return
api
.
Pod
{
Status
:
api
.
PodStatus
{
Conditions
:
[]
api
.
PodCondition
{
{
Type
:
api
.
PodReady
,
LastTransitionTime
:
unversioned
.
NewTime
(
now
.
Add
(
-
1
*
time
.
Duration
(
beforeSec
)
*
time
.
Second
)),
Status
:
conditionStatus
,
},
},
},
}
}
func
TestGetReadyPodsCount
(
t
*
testing
.
T
)
{
now
:=
time
.
Now
()
tests
:=
[]
struct
{
pods
[]
api
.
Pod
minReadySeconds
int
expected
int
}{
{
[]
api
.
Pod
{
newPod
(
now
,
true
,
0
),
newPod
(
now
,
true
,
2
),
newPod
(
now
,
false
,
1
),
},
1
,
1
,
},
{
[]
api
.
Pod
{
newPod
(
now
,
true
,
2
),
newPod
(
now
,
true
,
11
),
newPod
(
now
,
true
,
5
),
},
10
,
1
,
},
}
for
_
,
test
:=
range
tests
{
if
count
:=
getReadyPodsCount
(
test
.
pods
,
test
.
minReadySeconds
);
count
!=
test
.
expected
{
t
.
Errorf
(
"Pods = %#v, minReadySeconds = %d, expected %d, got %d"
,
test
.
pods
,
test
.
minReadySeconds
,
test
.
expected
,
count
)
}
}
}
test/e2e/deployment.go
View file @
ee8598fd
...
@@ -170,7 +170,7 @@ func testRollingUpdateDeployment(f *Framework) {
...
@@ -170,7 +170,7 @@ func testRollingUpdateDeployment(f *Framework) {
Expect
(
c
.
Deployments
(
ns
)
.
Delete
(
deploymentName
,
nil
))
.
NotTo
(
HaveOccurred
())
Expect
(
c
.
Deployments
(
ns
)
.
Delete
(
deploymentName
,
nil
))
.
NotTo
(
HaveOccurred
())
}()
}()
err
=
waitForDeploymentStatus
(
c
,
ns
,
deploymentName
,
3
,
2
,
4
)
err
=
waitForDeploymentStatus
(
c
,
ns
,
deploymentName
,
3
,
2
,
4
,
0
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
}
}
...
@@ -251,7 +251,7 @@ func testRollingUpdateDeploymentEvents(f *Framework) {
...
@@ -251,7 +251,7 @@ func testRollingUpdateDeploymentEvents(f *Framework) {
Expect
(
c
.
Deployments
(
ns
)
.
Delete
(
deploymentName
,
nil
))
.
NotTo
(
HaveOccurred
())
Expect
(
c
.
Deployments
(
ns
)
.
Delete
(
deploymentName
,
nil
))
.
NotTo
(
HaveOccurred
())
}()
}()
err
=
waitForDeploymentStatus
(
c
,
ns
,
deploymentName
,
1
,
0
,
2
)
err
=
waitForDeploymentStatus
(
c
,
ns
,
deploymentName
,
1
,
0
,
2
,
0
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
// Verify that the pods were scaled up and down as expected. We use events to verify that.
// Verify that the pods were scaled up and down as expected. We use events to verify that.
deployment
,
err
:=
c
.
Deployments
(
ns
)
.
Get
(
deploymentName
)
deployment
,
err
:=
c
.
Deployments
(
ns
)
.
Get
(
deploymentName
)
...
...
test/e2e/util.go
View file @
ee8598fd
...
@@ -1843,7 +1843,7 @@ func waitForRCPodsGone(c *client.Client, rc *api.ReplicationController) error {
...
@@ -1843,7 +1843,7 @@ func waitForRCPodsGone(c *client.Client, rc *api.ReplicationController) error {
// Waits for the deployment to reach desired state.
// Waits for the deployment to reach desired state.
// Returns an error if minAvailable or maxCreated is broken at any times.
// Returns an error if minAvailable or maxCreated is broken at any times.
func
waitForDeploymentStatus
(
c
*
client
.
Client
,
ns
,
deploymentName
string
,
desiredUpdatedReplicas
,
minAvailable
,
maxCreated
int
)
error
{
func
waitForDeploymentStatus
(
c
*
client
.
Client
,
ns
,
deploymentName
string
,
desiredUpdatedReplicas
,
minAvailable
,
maxCreated
,
minReadySeconds
int
)
error
{
return
wait
.
Poll
(
poll
,
5
*
time
.
Minute
,
func
()
(
bool
,
error
)
{
return
wait
.
Poll
(
poll
,
5
*
time
.
Minute
,
func
()
(
bool
,
error
)
{
deployment
,
err
:=
c
.
Deployments
(
ns
)
.
Get
(
deploymentName
)
deployment
,
err
:=
c
.
Deployments
(
ns
)
.
Get
(
deploymentName
)
...
@@ -1864,7 +1864,7 @@ func waitForDeploymentStatus(c *client.Client, ns, deploymentName string, desire
...
@@ -1864,7 +1864,7 @@ func waitForDeploymentStatus(c *client.Client, ns, deploymentName string, desire
}
}
allRCs
:=
append
(
oldRCs
,
newRC
)
allRCs
:=
append
(
oldRCs
,
newRC
)
totalCreated
:=
deploymentutil
.
GetReplicaCountForRCs
(
allRCs
)
totalCreated
:=
deploymentutil
.
GetReplicaCountForRCs
(
allRCs
)
totalAvailable
,
err
:=
deploymentutil
.
GetAvailablePodsForRCs
(
c
,
allRCs
)
totalAvailable
,
err
:=
deploymentutil
.
GetAvailablePodsForRCs
(
c
,
allRCs
,
minReadySeconds
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
false
,
err
}
}
...
...
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