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
40098179
Unverified
Commit
40098179
authored
Sep 18, 2018
by
k8s-ci-robot
Committed by
GitHub
Sep 18, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #68767 from ravisantoshgudimetla/fix-drain
Fix drain for evicting terminal DS pods and pods with local storage
parents
48203db0
452615c5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
127 additions
and
3 deletions
+127
-3
drain.go
pkg/kubectl/cmd/drain.go
+11
-2
drain_test.go
pkg/kubectl/cmd/drain_test.go
+116
-1
No files found.
pkg/kubectl/cmd/drain.go
View file @
40098179
...
...
@@ -403,8 +403,7 @@ func (o *DrainOptions) unreplicatedFilter(pod corev1.Pod) (bool, *warning, *fata
func
(
o
*
DrainOptions
)
daemonsetFilter
(
pod
corev1
.
Pod
)
(
bool
,
*
warning
,
*
fatal
)
{
// Note that we return false in cases where the pod is DaemonSet managed,
// regardless of flags. We never delete them, the only question is whether
// their presence constitutes an error.
// regardless of flags.
//
// The exception is for pods that are orphaned (the referencing
// management resource - including DaemonSet - is not found).
...
...
@@ -413,12 +412,17 @@ func (o *DrainOptions) daemonsetFilter(pod corev1.Pod) (bool, *warning, *fatal)
if
controllerRef
==
nil
||
controllerRef
.
Kind
!=
"DaemonSet"
{
return
true
,
nil
,
nil
}
// Any finished pod can be removed.
if
pod
.
Status
.
Phase
==
corev1
.
PodSucceeded
||
pod
.
Status
.
Phase
==
corev1
.
PodFailed
{
return
true
,
nil
,
nil
}
if
_
,
err
:=
o
.
client
.
ExtensionsV1beta1
()
.
DaemonSets
(
pod
.
Namespace
)
.
Get
(
controllerRef
.
Name
,
metav1
.
GetOptions
{});
err
!=
nil
{
// remove orphaned pods with a warning if --force is used
if
apierrors
.
IsNotFound
(
err
)
&&
o
.
Force
{
return
true
,
&
warning
{
err
.
Error
()},
nil
}
return
false
,
nil
,
&
fatal
{
err
.
Error
()}
}
...
...
@@ -450,9 +454,14 @@ func (o *DrainOptions) localStorageFilter(pod corev1.Pod) (bool, *warning, *fata
if
!
hasLocalStorage
(
pod
)
{
return
true
,
nil
,
nil
}
// Any finished pod can be removed.
if
pod
.
Status
.
Phase
==
corev1
.
PodSucceeded
||
pod
.
Status
.
Phase
==
corev1
.
PodFailed
{
return
true
,
nil
,
nil
}
if
!
o
.
DeleteLocalData
{
return
false
,
nil
,
&
fatal
{
kLocalStorageFatal
}
}
return
true
,
&
warning
{
kLocalStorageWarning
},
nil
}
...
...
pkg/kubectl/cmd/drain_test.go
View file @
40098179
...
...
@@ -308,6 +308,31 @@ func TestDrain(t *testing.T) {
},
}
ds_terminated_pod
:=
corev1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"bar"
,
Namespace
:
"default"
,
CreationTimestamp
:
metav1
.
Time
{
Time
:
time
.
Now
()},
Labels
:
labels
,
SelfLink
:
testapi
.
Default
.
SelfLink
(
"pods"
,
"bar"
),
OwnerReferences
:
[]
metav1
.
OwnerReference
{
{
APIVersion
:
"extensions/v1beta1"
,
Kind
:
"DaemonSet"
,
Name
:
"ds"
,
BlockOwnerDeletion
:
boolptr
(
true
),
Controller
:
boolptr
(
true
),
},
},
},
Spec
:
corev1
.
PodSpec
{
NodeName
:
"node"
,
},
Status
:
corev1
.
PodStatus
{
Phase
:
corev1
.
PodSucceeded
,
},
}
ds_pod_with_emptyDir
:=
corev1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"bar"
,
...
...
@@ -378,6 +403,46 @@ func TestDrain(t *testing.T) {
},
},
},
Spec
:
corev1
.
PodSpec
{
NodeName
:
"node"
,
Volumes
:
[]
corev1
.
Volume
{
{
Name
:
"scratch"
,
VolumeSource
:
corev1
.
VolumeSource
{
EmptyDir
:
&
corev1
.
EmptyDirVolumeSource
{
Medium
:
""
}},
},
},
},
}
terminated_job_pod_with_local_storage
:=
corev1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"bar"
,
Namespace
:
"default"
,
CreationTimestamp
:
metav1
.
Time
{
Time
:
time
.
Now
()},
Labels
:
labels
,
SelfLink
:
testapi
.
Default
.
SelfLink
(
"pods"
,
"bar"
),
OwnerReferences
:
[]
metav1
.
OwnerReference
{
{
APIVersion
:
"v1"
,
Kind
:
"Job"
,
Name
:
"job"
,
BlockOwnerDeletion
:
boolptr
(
true
),
Controller
:
boolptr
(
true
),
},
},
},
Spec
:
corev1
.
PodSpec
{
NodeName
:
"node"
,
Volumes
:
[]
corev1
.
Volume
{
{
Name
:
"scratch"
,
VolumeSource
:
corev1
.
VolumeSource
{
EmptyDir
:
&
corev1
.
EmptyDirVolumeSource
{
Medium
:
""
}},
},
},
},
Status
:
corev1
.
PodStatus
{
Phase
:
corev1
.
PodSucceeded
,
},
}
rs
:=
extensions
.
ReplicaSet
{
...
...
@@ -444,6 +509,26 @@ func TestDrain(t *testing.T) {
},
},
}
emptydir_terminated_pod
:=
corev1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"bar"
,
Namespace
:
"default"
,
CreationTimestamp
:
metav1
.
Time
{
Time
:
time
.
Now
()},
Labels
:
labels
,
},
Spec
:
corev1
.
PodSpec
{
NodeName
:
"node"
,
Volumes
:
[]
corev1
.
Volume
{
{
Name
:
"scratch"
,
VolumeSource
:
corev1
.
VolumeSource
{
EmptyDir
:
&
corev1
.
EmptyDirVolumeSource
{
Medium
:
""
}},
},
},
},
Status
:
corev1
.
PodStatus
{
Phase
:
corev1
.
PodFailed
,
},
}
tests
:=
[]
struct
{
description
string
...
...
@@ -478,6 +563,16 @@ func TestDrain(t *testing.T) {
expectDelete
:
false
,
},
{
description
:
"DS-managed terminated pod"
,
node
:
node
,
expected
:
cordoned_node
,
pods
:
[]
corev1
.
Pod
{
ds_terminated_pod
},
rcs
:
[]
api
.
ReplicationController
{
rc
},
args
:
[]
string
{
"node"
},
expectFatal
:
false
,
expectDelete
:
true
,
},
{
description
:
"orphaned DS-managed pod"
,
node
:
node
,
expected
:
cordoned_node
,
...
...
@@ -519,11 +614,21 @@ func TestDrain(t *testing.T) {
expectDelete
:
false
,
},
{
description
:
"Job-managed pod"
,
description
:
"Job-managed pod
with local storage
"
,
node
:
node
,
expected
:
cordoned_node
,
pods
:
[]
corev1
.
Pod
{
job_pod
},
rcs
:
[]
api
.
ReplicationController
{
rc
},
args
:
[]
string
{
"node"
,
"--force"
,
"--delete-local-data=true"
},
expectFatal
:
false
,
expectDelete
:
true
,
},
{
description
:
"Job-managed terminated pod"
,
node
:
node
,
expected
:
cordoned_node
,
pods
:
[]
corev1
.
Pod
{
terminated_job_pod_with_local_storage
},
rcs
:
[]
api
.
ReplicationController
{
rc
},
args
:
[]
string
{
"node"
},
expectFatal
:
false
,
expectDelete
:
true
,
...
...
@@ -568,6 +673,16 @@ func TestDrain(t *testing.T) {
expectDelete
:
false
,
},
{
description
:
"terminated pod with emptyDir"
,
node
:
node
,
expected
:
cordoned_node
,
pods
:
[]
corev1
.
Pod
{
emptydir_terminated_pod
},
rcs
:
[]
api
.
ReplicationController
{
rc
},
args
:
[]
string
{
"node"
},
expectFatal
:
false
,
expectDelete
:
true
,
},
{
description
:
"pod with EmptyDir and --delete-local-data"
,
node
:
node
,
expected
:
cordoned_node
,
...
...
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