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
abab9ea3
Commit
abab9ea3
authored
Apr 15, 2015
by
Victor Marmol
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6844 from yifan-gu/cleankube
kubelet: Clean up computePodContainerChanges.
parents
24df692b
3b28c626
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
26 deletions
+30
-26
kubelet.go
pkg/kubelet/kubelet.go
+30
-26
No files found.
pkg/kubelet/kubelet.go
View file @
abab9ea3
...
@@ -1123,16 +1123,42 @@ func (kl *Kubelet) computePodContainerChanges(pod *api.Pod, runningPod kubeconta
...
@@ -1123,16 +1123,42 @@ func (kl *Kubelet) computePodContainerChanges(pod *api.Pod, runningPod kubeconta
expectedHash
:=
dockertools
.
HashContainer
(
&
container
)
expectedHash
:=
dockertools
.
HashContainer
(
&
container
)
c
:=
runningPod
.
FindContainerByName
(
container
.
Name
)
c
:=
runningPod
.
FindContainerByName
(
container
.
Name
)
if
c
!=
nil
{
if
c
==
nil
{
if
kl
.
shouldContainerBeRestarted
(
&
container
,
pod
,
&
podStatus
)
{
// If we are here it means that the container is dead and should be restarted, or never existed and should
// be created. We may be inserting this ID again if the container has changed and it has
// RestartPolicy::Always, but it's not a big deal.
glog
.
V
(
3
)
.
Infof
(
"Container %+v is dead, but RestartPolicy says that we should restart it."
,
container
)
containersToStart
[
index
]
=
empty
{}
}
continue
}
containerID
:=
dockertools
.
DockerID
(
c
.
ID
)
containerID
:=
dockertools
.
DockerID
(
c
.
ID
)
hash
:=
c
.
Hash
hash
:=
c
.
Hash
glog
.
V
(
3
)
.
Infof
(
"pod %q container %q exists as %v"
,
podFullName
,
container
.
Name
,
containerID
)
glog
.
V
(
3
)
.
Infof
(
"pod %q container %q exists as %v"
,
podFullName
,
container
.
Name
,
containerID
)
if
!
createPodInfraContainer
{
if
createPodInfraContainer
{
// look for changes in the container.
// createPodInfraContainer == true and Container exists
// If we're creating infra containere everything will be killed anyway
// If RestartPolicy is Always or OnFailure we restart containers that were running before we
// killed them when restarting Infra Container.
if
pod
.
Spec
.
RestartPolicy
!=
api
.
RestartPolicyNever
{
glog
.
V
(
1
)
.
Infof
(
"Infra Container is being recreated. %q will be restarted."
,
container
.
Name
)
containersToStart
[
index
]
=
empty
{}
}
continue
}
// At this point, the container is running and pod infra container is good.
// We will look for changes and check healthiness for the container.
containerChanged
:=
hash
!=
0
&&
hash
!=
expectedHash
containerChanged
:=
hash
!=
0
&&
hash
!=
expectedHash
if
!
containerChanged
{
if
containerChanged
{
glog
.
Infof
(
"pod %q container %q hash changed (%d vs %d), it will be killed and re-created."
,
podFullName
,
container
.
Name
,
hash
,
expectedHash
)
containersToStart
[
index
]
=
empty
{}
continue
}
result
,
err
:=
kl
.
probeContainer
(
pod
,
podStatus
,
container
,
string
(
c
.
ID
),
c
.
Created
)
result
,
err
:=
kl
.
probeContainer
(
pod
,
podStatus
,
container
,
string
(
c
.
ID
),
c
.
Created
)
if
err
!=
nil
{
if
err
!=
nil
{
// TODO(vmarmol): examine this logic.
// TODO(vmarmol): examine this logic.
...
@@ -1146,29 +1172,7 @@ func (kl *Kubelet) computePodContainerChanges(pod *api.Pod, runningPod kubeconta
...
@@ -1146,29 +1172,7 @@ func (kl *Kubelet) computePodContainerChanges(pod *api.Pod, runningPod kubeconta
continue
continue
}
}
glog
.
Infof
(
"pod %q container %q is unhealthy (probe result: %v), it will be killed and re-created."
,
podFullName
,
container
.
Name
,
result
)
glog
.
Infof
(
"pod %q container %q is unhealthy (probe result: %v), it will be killed and re-created."
,
podFullName
,
container
.
Name
,
result
)
}
else
{
glog
.
Infof
(
"pod %q container %q hash changed (%d vs %d), it will be killed and re-created."
,
podFullName
,
container
.
Name
,
hash
,
expectedHash
)
}
containersToStart
[
index
]
=
empty
{}
containersToStart
[
index
]
=
empty
{}
}
else
{
// createPodInfraContainer == true and Container exists
// If we're creating infra containere everything will be killed anyway
// If RestartPolicy is Always or OnFailure we restart containers that were running before we
// killed them when restarting Infra Container.
if
pod
.
Spec
.
RestartPolicy
!=
api
.
RestartPolicyNever
{
glog
.
V
(
1
)
.
Infof
(
"Infra Container is being recreated. %q will be restarted."
,
container
.
Name
)
containersToStart
[
index
]
=
empty
{}
}
continue
}
}
else
{
if
kl
.
shouldContainerBeRestarted
(
&
container
,
pod
,
&
podStatus
)
{
// If we are here it means that the container is dead and sould be restarted, or never existed and should
// be created. We may be inserting this ID again if the container has changed and it has
// RestartPolicy::Always, but it's not a big deal.
glog
.
V
(
3
)
.
Infof
(
"Container %+v is dead, but RestartPolicy says that we should restart it."
,
container
)
containersToStart
[
index
]
=
empty
{}
}
}
}
}
// After the loop one of the following should be true:
// After the loop one of the following should be true:
...
...
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