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
5b4770e0
Commit
5b4770e0
authored
Jun 25, 2018
by
Ryan Phillips
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kubectl: wait for all errors and successes on podEviction
parent
7786bd8c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
14 deletions
+16
-14
drain.go
pkg/kubectl/cmd/drain.go
+16
-14
No files found.
pkg/kubectl/cmd/drain.go
View file @
5b4770e0
...
...
@@ -34,6 +34,7 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
utilerrors
"k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/json"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/strategicpatch"
...
...
@@ -572,38 +573,39 @@ func (o *DrainOptions) deleteOrEvictPods(pods []corev1.Pod) error {
}
func
(
o
*
DrainOptions
)
evictPods
(
pods
[]
corev1
.
Pod
,
policyGroupVersion
string
,
getPodFn
func
(
namespace
,
name
string
)
(
*
corev1
.
Pod
,
error
))
error
{
doneCh
:=
make
(
chan
bool
,
len
(
pods
))
errCh
:=
make
(
chan
error
,
1
)
returnCh
:=
make
(
chan
error
,
1
)
for
_
,
pod
:=
range
pods
{
go
func
(
pod
corev1
.
Pod
,
doneCh
chan
bool
,
err
Ch
chan
error
)
{
go
func
(
pod
corev1
.
Pod
,
return
Ch
chan
error
)
{
var
err
error
for
{
err
=
o
.
evictPod
(
pod
,
policyGroupVersion
)
if
err
==
nil
{
break
}
else
if
apierrors
.
IsNotFound
(
err
)
{
doneCh
<-
true
returnCh
<-
nil
return
}
else
if
apierrors
.
IsTooManyRequests
(
err
)
{
fmt
.
Fprintf
(
o
.
ErrOut
,
"error when evicting pod %q (will retry after 5s): %v
\n
"
,
pod
.
Name
,
err
)
time
.
Sleep
(
5
*
time
.
Second
)
}
else
{
err
Ch
<-
fmt
.
Errorf
(
"error when evicting pod %q: %v"
,
pod
.
Name
,
err
)
return
Ch
<-
fmt
.
Errorf
(
"error when evicting pod %q: %v"
,
pod
.
Name
,
err
)
return
}
}
podArray
:=
[]
corev1
.
Pod
{
pod
}
_
,
err
=
o
.
waitForDelete
(
podArray
,
1
*
time
.
Second
,
time
.
Duration
(
math
.
MaxInt64
),
true
,
getPodFn
)
if
err
==
nil
{
doneCh
<-
true
returnCh
<-
nil
}
else
{
err
Ch
<-
fmt
.
Errorf
(
"error when waiting for pod %q terminating: %v"
,
pod
.
Name
,
err
)
return
Ch
<-
fmt
.
Errorf
(
"error when waiting for pod %q terminating: %v"
,
pod
.
Name
,
err
)
}
}(
pod
,
doneCh
,
err
Ch
)
}(
pod
,
return
Ch
)
}
doneCount
:=
0
var
errors
[]
error
// 0 timeout means infinite, we use MaxInt64 to represent it.
var
globalTimeout
time
.
Duration
if
o
.
Timeout
==
0
{
...
...
@@ -612,19 +614,19 @@ func (o *DrainOptions) evictPods(pods []corev1.Pod, policyGroupVersion string, g
globalTimeout
=
o
.
Timeout
}
globalTimeoutCh
:=
time
.
After
(
globalTimeout
)
for
{
numPods
:=
len
(
pods
)
for
doneCount
<
numPods
{
select
{
case
err
:=
<-
errCh
:
return
err
case
<-
doneCh
:
case
err
:=
<-
returnCh
:
doneCount
++
if
doneCount
==
len
(
pods
)
{
return
nil
if
err
!=
nil
{
errors
=
append
(
errors
,
err
)
}
case
<-
globalTimeoutCh
:
return
fmt
.
Errorf
(
"Drain did not complete within %v"
,
globalTimeout
)
}
}
return
utilerrors
.
NewAggregate
(
errors
)
}
func
(
o
*
DrainOptions
)
deletePods
(
pods
[]
corev1
.
Pod
,
getPodFn
func
(
namespace
,
name
string
)
(
*
corev1
.
Pod
,
error
))
error
{
...
...
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