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
e3b8ad94
Commit
e3b8ad94
authored
Jul 10, 2015
by
Rohit Jnagal
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11019 from caesarxuchao/e2e_waitforallpods
ignore pods that are failed but controlled by a rc when start e2e tests
parents
a5dac1d9
3db73bbe
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
9 deletions
+46
-9
util.go
test/e2e/util.go
+46
-9
No files found.
test/e2e/util.go
View file @
e3b8ad94
...
@@ -282,11 +282,24 @@ func podRunningReady(p *api.Pod) (bool, error) {
...
@@ -282,11 +282,24 @@ func podRunningReady(p *api.Pod) (bool, error) {
return
true
,
nil
return
true
,
nil
}
}
// check if a Pod is controlled by a Replication Controller in the List
func
hasReplicationControllersForPod
(
rcs
*
api
.
ReplicationControllerList
,
pod
api
.
Pod
)
bool
{
for
_
,
rc
:=
range
rcs
.
Items
{
selector
:=
labels
.
SelectorFromSet
(
rc
.
Spec
.
Selector
)
if
selector
.
Matches
(
labels
.
Set
(
pod
.
ObjectMeta
.
Labels
))
{
return
true
}
}
return
false
}
// waitForPodsRunningReady waits up to timeout to ensure that all pods in
// waitForPodsRunningReady waits up to timeout to ensure that all pods in
// namespace ns are running and ready, requiring that it finds at least minPods.
// namespace ns are either running and ready, or failed but controlled by a
// It has separate behavior from other 'wait for' pods functions in that it re-
// replication controller. Also, it ensures that at least minPods are running
// queries the list of pods on every iteration. This is useful, for example, in
// and ready. It has separate behavior from other 'wait for' pods functions in
// cluster startup, because the number of pods increases while waiting.
// that it requires the list of pods on every iteration. This is useful, for
// example, in cluster startup, because the number of pods increases while
// waiting.
func
waitForPodsRunningReady
(
ns
string
,
minPods
int
,
timeout
time
.
Duration
)
error
{
func
waitForPodsRunningReady
(
ns
string
,
minPods
int
,
timeout
time
.
Duration
)
error
{
c
,
err
:=
loadClient
()
c
,
err
:=
loadClient
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -296,24 +309,48 @@ func waitForPodsRunningReady(ns string, minPods int, timeout time.Duration) erro
...
@@ -296,24 +309,48 @@ func waitForPodsRunningReady(ns string, minPods int, timeout time.Duration) erro
Logf
(
"Waiting up to %v for all pods (need at least %d) in namespace '%s' to be running and ready"
,
Logf
(
"Waiting up to %v for all pods (need at least %d) in namespace '%s' to be running and ready"
,
timeout
,
minPods
,
ns
)
timeout
,
minPods
,
ns
)
if
wait
.
Poll
(
poll
,
timeout
,
func
()
(
bool
,
error
)
{
if
wait
.
Poll
(
poll
,
timeout
,
func
()
(
bool
,
error
)
{
// We get the new list of pods in every iteration beause more pods come
// We get the new list of pods and replication controllers in every
// online during startup and we want to ensure they are also checked.
// iteration because more pods come online during startup and we want to
// ensure they are also checked.
rcList
,
err
:=
c
.
ReplicationControllers
(
ns
)
.
List
(
labels
.
Everything
())
if
err
!=
nil
{
Logf
(
"Error getting replication controllers in namespace '%s': %v"
,
ns
,
err
)
return
false
,
nil
}
replicas
:=
0
for
_
,
rc
:=
range
rcList
.
Items
{
replicas
+=
rc
.
Spec
.
Replicas
}
podList
,
err
:=
c
.
Pods
(
ns
)
.
List
(
labels
.
Everything
(),
fields
.
Everything
())
podList
,
err
:=
c
.
Pods
(
ns
)
.
List
(
labels
.
Everything
(),
fields
.
Everything
())
if
err
!=
nil
{
if
err
!=
nil
{
Logf
(
"Error getting pods in namespace '%s': %v"
,
ns
,
err
)
Logf
(
"Error getting pods in namespace '%s': %v"
,
ns
,
err
)
return
false
,
nil
return
false
,
nil
}
}
nOk
,
badPods
:=
0
,
[]
api
.
Pod
{}
nOk
,
replicaOk
,
badPods
:=
0
,
0
,
[]
api
.
Pod
{}
for
_
,
pod
:=
range
podList
.
Items
{
for
_
,
pod
:=
range
podList
.
Items
{
if
res
,
err
:=
podRunningReady
(
&
pod
);
res
&&
err
==
nil
{
if
res
,
err
:=
podRunningReady
(
&
pod
);
res
&&
err
==
nil
{
nOk
++
nOk
++
if
hasReplicationControllersForPod
(
rcList
,
pod
)
{
replicaOk
++
}
}
else
{
}
else
{
badPods
=
append
(
badPods
,
pod
)
if
pod
.
Status
.
Phase
!=
api
.
PodFailed
{
Logf
(
"The status of Pod %s is %s, waiting for it to be either Running or Failed"
,
pod
.
ObjectMeta
.
Name
,
pod
.
Status
.
Phase
)
badPods
=
append
(
badPods
,
pod
)
}
else
if
!
hasReplicationControllersForPod
(
rcList
,
pod
)
{
Logf
(
"Pod %s is Failed, but it's not controlled by a ReplicationController"
,
pod
.
ObjectMeta
.
Name
)
badPods
=
append
(
badPods
,
pod
)
}
//ignore failed pods that are controlled by a replication controller
}
}
}
}
Logf
(
"%d / %d pods in namespace '%s' are running and ready (%d seconds elapsed)"
,
Logf
(
"%d / %d pods in namespace '%s' are running and ready (%d seconds elapsed)"
,
nOk
,
len
(
podList
.
Items
),
ns
,
int
(
time
.
Since
(
start
)
.
Seconds
()))
nOk
,
len
(
podList
.
Items
),
ns
,
int
(
time
.
Since
(
start
)
.
Seconds
()))
if
nOk
==
len
(
podList
.
Items
)
&&
nOk
>=
minPods
{
Logf
(
"expected %d pod replicas in namespace '%s', %d are Running and Ready."
,
replicas
,
ns
,
replicaOk
)
if
replicaOk
==
replicas
&&
nOk
>=
minPods
&&
len
(
badPods
)
==
0
{
return
true
,
nil
return
true
,
nil
}
}
logPodStates
(
badPods
)
logPodStates
(
badPods
)
...
...
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