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
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
39 deletions
+43
-39
kubelet.go
pkg/kubelet/kubelet.go
+43
-39
No files found.
pkg/kubelet/kubelet.go
View file @
abab9ea3
...
...
@@ -1123,52 +1123,56 @@ func (kl *Kubelet) computePodContainerChanges(pod *api.Pod, runningPod kubeconta
expectedHash
:=
dockertools
.
HashContainer
(
&
container
)
c
:=
runningPod
.
FindContainerByName
(
container
.
Name
)
if
c
!=
nil
{
containerID
:=
dockertools
.
DockerID
(
c
.
ID
)
hash
:=
c
.
Hash
glog
.
V
(
3
)
.
Infof
(
"pod %q container %q exists as %v"
,
podFullName
,
container
.
Name
,
containerID
)
if
!
createPodInfraContainer
{
// look for changes in the container.
containerChanged
:=
hash
!=
0
&&
hash
!=
expectedHash
if
!
containerChanged
{
result
,
err
:=
kl
.
probeContainer
(
pod
,
podStatus
,
container
,
string
(
c
.
ID
),
c
.
Created
)
if
err
!=
nil
{
// TODO(vmarmol): examine this logic.
glog
.
V
(
2
)
.
Infof
(
"probe no-error: %q"
,
container
.
Name
)
containersToKeep
[
containerID
]
=
index
continue
}
if
result
==
probe
.
Success
{
glog
.
V
(
4
)
.
Infof
(
"probe success: %q"
,
container
.
Name
)
containersToKeep
[
containerID
]
=
index
continue
}
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
{}
}
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
c
==
nil
{
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
// If we are here it means that the container is dead and s
h
ould 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
)
hash
:=
c
.
Hash
glog
.
V
(
3
)
.
Infof
(
"pod %q container %q exists as %v"
,
podFullName
,
container
.
Name
,
containerID
)
if
createPodInfraContainer
{
// 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
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
)
if
err
!=
nil
{
// TODO(vmarmol): examine this logic.
glog
.
V
(
2
)
.
Infof
(
"probe no-error: %q"
,
container
.
Name
)
containersToKeep
[
containerID
]
=
index
continue
}
if
result
==
probe
.
Success
{
glog
.
V
(
4
)
.
Infof
(
"probe success: %q"
,
container
.
Name
)
containersToKeep
[
containerID
]
=
index
continue
}
glog
.
Infof
(
"pod %q container %q is unhealthy (probe result: %v), it will be killed and re-created."
,
podFullName
,
container
.
Name
,
result
)
containersToStart
[
index
]
=
empty
{}
}
// 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