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
d30c709a
Commit
d30c709a
authored
Feb 24, 2016
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #21732 from Random-Liu/terminated_pods
Auto commit by PR queue bot
parents
07e9bd82
a68f5342
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
50 deletions
+31
-50
fake_docker_client.go
pkg/kubelet/dockertools/fake_docker_client.go
+2
-1
kubelet.go
pkg/kubelet/kubelet.go
+7
-29
manager.go
pkg/kubelet/status/manager.go
+22
-20
No files found.
pkg/kubelet/dockertools/fake_docker_client.go
View file @
d30c709a
...
@@ -297,6 +297,8 @@ func (f *FakeDockerClient) StopContainer(id string, timeout uint) error {
...
@@ -297,6 +297,8 @@ func (f *FakeDockerClient) StopContainer(id string, timeout uint) error {
return
err
return
err
}
}
f
.
Stopped
=
append
(
f
.
Stopped
,
id
)
f
.
Stopped
=
append
(
f
.
Stopped
,
id
)
// Container status should be Updated before container moved to ExitedContainerList
f
.
updateContainerStatus
(
id
,
statusExitedPrefix
)
var
newList
[]
docker
.
APIContainers
var
newList
[]
docker
.
APIContainers
for
_
,
container
:=
range
f
.
ContainerList
{
for
_
,
container
:=
range
f
.
ContainerList
{
if
container
.
ID
==
id
{
if
container
.
ID
==
id
{
...
@@ -323,7 +325,6 @@ func (f *FakeDockerClient) StopContainer(id string, timeout uint) error {
...
@@ -323,7 +325,6 @@ func (f *FakeDockerClient) StopContainer(id string, timeout uint) error {
container
.
State
.
Running
=
false
container
.
State
.
Running
=
false
}
}
f
.
ContainerMap
[
id
]
=
container
f
.
ContainerMap
[
id
]
=
container
f
.
updateContainerStatus
(
id
,
statusExitedPrefix
)
f
.
normalSleep
(
200
,
50
,
50
)
f
.
normalSleep
(
200
,
50
,
50
)
return
nil
return
nil
}
}
...
...
pkg/kubelet/kubelet.go
View file @
d30c709a
...
@@ -1932,31 +1932,6 @@ func (kl *Kubelet) cleanupOrphanedVolumes(pods []*api.Pod, runningPods []*kubeco
...
@@ -1932,31 +1932,6 @@ func (kl *Kubelet) cleanupOrphanedVolumes(pods []*api.Pod, runningPods []*kubeco
return
nil
return
nil
}
}
// Delete any pods that are no longer running and are marked for deletion.
func
(
kl
*
Kubelet
)
cleanupTerminatedPods
(
pods
[]
*
api
.
Pod
,
runningPods
[]
*
kubecontainer
.
Pod
)
error
{
var
terminating
[]
*
api
.
Pod
for
_
,
pod
:=
range
pods
{
if
pod
.
DeletionTimestamp
!=
nil
{
found
:=
false
for
_
,
runningPod
:=
range
runningPods
{
if
runningPod
.
ID
==
pod
.
UID
{
found
=
true
break
}
}
if
found
{
glog
.
V
(
5
)
.
Infof
(
"Keeping terminated pod %q, still running"
,
format
.
Pod
(
pod
))
continue
}
terminating
=
append
(
terminating
,
pod
)
}
}
if
!
kl
.
statusManager
.
TerminatePods
(
terminating
)
{
return
errors
.
New
(
"not all pods were successfully terminated"
)
}
return
nil
}
// pastActiveDeadline returns true if the pod has been active for more than
// pastActiveDeadline returns true if the pod has been active for more than
// ActiveDeadlineSeconds.
// ActiveDeadlineSeconds.
func
(
kl
*
Kubelet
)
pastActiveDeadline
(
pod
*
api
.
Pod
)
bool
{
func
(
kl
*
Kubelet
)
pastActiveDeadline
(
pod
*
api
.
Pod
)
bool
{
...
@@ -2148,10 +2123,6 @@ func (kl *Kubelet) HandlePodCleanups() error {
...
@@ -2148,10 +2123,6 @@ func (kl *Kubelet) HandlePodCleanups() error {
// Remove any orphaned mirror pods.
// Remove any orphaned mirror pods.
kl
.
podManager
.
DeleteOrphanedMirrorPods
()
kl
.
podManager
.
DeleteOrphanedMirrorPods
()
if
err
:=
kl
.
cleanupTerminatedPods
(
allPods
,
runningPods
);
err
!=
nil
{
glog
.
Errorf
(
"Failed to cleanup terminated pods: %v"
,
err
)
}
// Clear out any old bandwidth rules
// Clear out any old bandwidth rules
if
err
=
kl
.
cleanupBandwidthLimits
(
allPods
);
err
!=
nil
{
if
err
=
kl
.
cleanupBandwidthLimits
(
allPods
);
err
!=
nil
{
return
err
return
err
...
@@ -2412,6 +2383,13 @@ func (kl *Kubelet) syncLoopIteration(updates <-chan kubetypes.PodUpdate, handler
...
@@ -2412,6 +2383,13 @@ func (kl *Kubelet) syncLoopIteration(updates <-chan kubetypes.PodUpdate, handler
func
(
kl
*
Kubelet
)
dispatchWork
(
pod
*
api
.
Pod
,
syncType
kubetypes
.
SyncPodType
,
mirrorPod
*
api
.
Pod
,
start
time
.
Time
)
{
func
(
kl
*
Kubelet
)
dispatchWork
(
pod
*
api
.
Pod
,
syncType
kubetypes
.
SyncPodType
,
mirrorPod
*
api
.
Pod
,
start
time
.
Time
)
{
if
kl
.
podIsTerminated
(
pod
)
{
if
kl
.
podIsTerminated
(
pod
)
{
if
pod
.
DeletionTimestamp
!=
nil
{
// If the pod is in a termianted state, there is no pod worker to
// handle the work item. Check if the DeletionTimestamp has been
// set, and force a status update to trigger a pod deletion request
// to the apiserver.
kl
.
statusManager
.
TerminatePod
(
pod
)
}
return
return
}
}
// Run the sync in an async worker.
// Run the sync in an async worker.
...
...
pkg/kubelet/status/manager.go
View file @
d30c709a
...
@@ -83,10 +83,9 @@ type Manager interface {
...
@@ -83,10 +83,9 @@ type Manager interface {
// triggers a status update.
// triggers a status update.
SetContainerReadiness
(
podUID
types
.
UID
,
containerID
kubecontainer
.
ContainerID
,
ready
bool
)
SetContainerReadiness
(
podUID
types
.
UID
,
containerID
kubecontainer
.
ContainerID
,
ready
bool
)
// TerminatePods resets the container status for the provided pods to terminated and triggers
// TerminatePod resets the container status for the provided pod to terminated and triggers
// a status update. This function may not enqueue all the provided pods, in which case it will
// a status update.
// return false
TerminatePod
(
pod
*
api
.
Pod
)
TerminatePods
(
pods
[]
*
api
.
Pod
)
bool
// RemoveOrphanedStatuses scans the status cache and removes any entries for pods not included in
// RemoveOrphanedStatuses scans the status cache and removes any entries for pods not included in
// the provided podUIDs.
// the provided podUIDs.
...
@@ -149,7 +148,7 @@ func (m *manager) SetPodStatus(pod *api.Pod, status api.PodStatus) {
...
@@ -149,7 +148,7 @@ func (m *manager) SetPodStatus(pod *api.Pod, status api.PodStatus) {
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
m
.
updateStatusInternal
(
pod
,
status
)
m
.
updateStatusInternal
(
pod
,
status
,
false
)
}
}
func
(
m
*
manager
)
SetContainerReadiness
(
podUID
types
.
UID
,
containerID
kubecontainer
.
ContainerID
,
ready
bool
)
{
func
(
m
*
manager
)
SetContainerReadiness
(
podUID
types
.
UID
,
containerID
kubecontainer
.
ContainerID
,
ready
bool
)
{
...
@@ -212,31 +211,32 @@ func (m *manager) SetContainerReadiness(podUID types.UID, containerID kubecontai
...
@@ -212,31 +211,32 @@ func (m *manager) SetContainerReadiness(podUID types.UID, containerID kubecontai
status
.
Conditions
=
append
(
status
.
Conditions
,
readyCondition
)
status
.
Conditions
=
append
(
status
.
Conditions
,
readyCondition
)
}
}
m
.
updateStatusInternal
(
pod
,
status
)
m
.
updateStatusInternal
(
pod
,
status
,
false
)
}
}
func
(
m
*
manager
)
TerminatePods
(
pods
[]
*
api
.
Pod
)
bool
{
func
(
m
*
manager
)
TerminatePod
(
pod
*
api
.
Pod
)
{
allSent
:=
true
m
.
podStatusesLock
.
Lock
()
m
.
podStatusesLock
.
Lock
()
defer
m
.
podStatusesLock
.
Unlock
()
defer
m
.
podStatusesLock
.
Unlock
()
for
_
,
pod
:=
range
pods
{
oldStatus
:=
&
pod
.
Status
for
i
:=
range
pod
.
Status
.
ContainerStatuses
{
if
cachedStatus
,
ok
:=
m
.
podStatuses
[
pod
.
UID
];
ok
{
pod
.
Status
.
ContainerStatuses
[
i
]
.
State
=
api
.
ContainerState
{
oldStatus
=
&
cachedStatus
.
status
Terminated
:
&
api
.
ContainerStateTerminated
{},
}
}
status
,
err
:=
copyStatus
(
oldStatus
)
}
if
err
!=
nil
{
if
sent
:=
m
.
updateStatusInternal
(
pod
,
pod
.
Status
);
!
sent
{
return
glog
.
V
(
4
)
.
Infof
(
"Termination notice for %q was dropped because the status channel is full"
,
format
.
Pod
(
pod
))
}
allSent
=
false
for
i
:=
range
status
.
ContainerStatuses
{
status
.
ContainerStatuses
[
i
]
.
State
=
api
.
ContainerState
{
Terminated
:
&
api
.
ContainerStateTerminated
{},
}
}
}
}
return
allSent
m
.
updateStatusInternal
(
pod
,
pod
.
Status
,
true
)
}
}
// updateStatusInternal updates the internal status cache, and queues an update to the api server if
// updateStatusInternal updates the internal status cache, and queues an update to the api server if
// necessary. Returns whether an update was triggered.
// necessary. Returns whether an update was triggered.
// This method IS NOT THREAD SAFE and must be called from a locked function.
// This method IS NOT THREAD SAFE and must be called from a locked function.
func
(
m
*
manager
)
updateStatusInternal
(
pod
*
api
.
Pod
,
status
api
.
PodStatus
)
bool
{
func
(
m
*
manager
)
updateStatusInternal
(
pod
*
api
.
Pod
,
status
api
.
PodStatus
,
forceUpdate
bool
)
bool
{
var
oldStatus
api
.
PodStatus
var
oldStatus
api
.
PodStatus
cachedStatus
,
isCached
:=
m
.
podStatuses
[
pod
.
UID
]
cachedStatus
,
isCached
:=
m
.
podStatuses
[
pod
.
UID
]
if
isCached
{
if
isCached
{
...
@@ -270,7 +270,7 @@ func (m *manager) updateStatusInternal(pod *api.Pod, status api.PodStatus) bool
...
@@ -270,7 +270,7 @@ func (m *manager) updateStatusInternal(pod *api.Pod, status api.PodStatus) bool
normalizeStatus
(
&
status
)
normalizeStatus
(
&
status
)
// The intent here is to prevent concurrent updates to a pod's status from
// The intent here is to prevent concurrent updates to a pod's status from
// clobbering each other so the phase of a pod progresses monotonically.
// clobbering each other so the phase of a pod progresses monotonically.
if
isCached
&&
isStatusEqual
(
&
cachedStatus
.
status
,
&
status
)
&&
pod
.
DeletionTimestamp
==
nil
{
if
isCached
&&
isStatusEqual
(
&
cachedStatus
.
status
,
&
status
)
&&
!
forceUpdate
{
glog
.
V
(
3
)
.
Infof
(
"Ignoring same status for pod %q, status: %+v"
,
format
.
Pod
(
pod
),
status
)
glog
.
V
(
3
)
.
Infof
(
"Ignoring same status for pod %q, status: %+v"
,
format
.
Pod
(
pod
),
status
)
return
false
// No new status.
return
false
// No new status.
}
}
...
@@ -289,6 +289,8 @@ func (m *manager) updateStatusInternal(pod *api.Pod, status api.PodStatus) bool
...
@@ -289,6 +289,8 @@ func (m *manager) updateStatusInternal(pod *api.Pod, status api.PodStatus) bool
default
:
default
:
// Let the periodic syncBatch handle the update if the channel is full.
// Let the periodic syncBatch handle the update if the channel is full.
// We can't block, since we hold the mutex lock.
// We can't block, since we hold the mutex lock.
glog
.
V
(
4
)
.
Infof
(
"Skpping the status update for pod %q for now because the channel is full; status: %+v"
,
format
.
Pod
(
pod
),
status
)
return
false
return
false
}
}
}
}
...
...
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