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
914a6feb
Commit
914a6feb
authored
Apr 22, 2015
by
Victor Marmol
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7010 from yifan-gu/compute
kubelet: Refactor computePodContainerChanges().
parents
fc50201f
55949813
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
39 deletions
+34
-39
kubelet.go
pkg/kubelet/kubelet.go
+14
-19
kubelet_test.go
pkg/kubelet/kubelet_test.go
+20
-20
No files found.
pkg/kubelet/kubelet.go
View file @
914a6feb
...
@@ -1060,20 +1060,16 @@ type podContainerChangesSpec struct {
...
@@ -1060,20 +1060,16 @@ type podContainerChangesSpec struct {
containersToKeep
map
[
dockertools
.
DockerID
]
int
containersToKeep
map
[
dockertools
.
DockerID
]
int
}
}
func
(
kl
*
Kubelet
)
computePodContainerChanges
(
pod
*
api
.
Pod
,
runningPod
kubecontainer
.
Pod
)
(
podContainerChangesSpec
,
error
)
{
func
(
kl
*
Kubelet
)
computePodContainerChanges
(
pod
*
api
.
Pod
,
runningPod
kubecontainer
.
Pod
,
podStatus
api
.
PodStatus
)
(
podContainerChangesSpec
,
error
)
{
podFullName
:=
kubecontainer
.
GetPodFullName
(
pod
)
podFullName
:=
kubecontainer
.
GetPodFullName
(
pod
)
uid
:=
pod
.
UID
uid
:=
pod
.
UID
glog
.
V
(
4
)
.
Infof
(
"Syncing Pod %+v, podFullName: %q, uid: %q"
,
pod
,
podFullName
,
uid
)
glog
.
V
(
4
)
.
Infof
(
"Syncing Pod %+v, podFullName: %q, uid: %q"
,
pod
,
podFullName
,
uid
)
err
:=
kl
.
makePodDataDirs
(
pod
)
if
err
!=
nil
{
return
podContainerChangesSpec
{},
err
}
containersToStart
:=
make
(
map
[
int
]
empty
)
containersToStart
:=
make
(
map
[
int
]
empty
)
containersToKeep
:=
make
(
map
[
dockertools
.
DockerID
]
int
)
containersToKeep
:=
make
(
map
[
dockertools
.
DockerID
]
int
)
createPodInfraContainer
:=
false
createPodInfraContainer
:=
false
var
err
error
var
podInfraContainerID
dockertools
.
DockerID
var
podInfraContainerID
dockertools
.
DockerID
var
changed
bool
var
changed
bool
podInfraContainer
:=
runningPod
.
FindContainerByName
(
dockertools
.
PodInfraContainerName
)
podInfraContainer
:=
runningPod
.
FindContainerByName
(
dockertools
.
PodInfraContainerName
)
...
@@ -1097,18 +1093,6 @@ func (kl *Kubelet) computePodContainerChanges(pod *api.Pod, runningPod kubeconta
...
@@ -1097,18 +1093,6 @@ func (kl *Kubelet) computePodContainerChanges(pod *api.Pod, runningPod kubeconta
containersToKeep
[
podInfraContainerID
]
=
-
1
containersToKeep
[
podInfraContainerID
]
=
-
1
}
}
// Do not use the cache here since we need the newest status to check
// if we need to restart the container below.
pod
,
found
:=
kl
.
GetPodByFullName
(
podFullName
)
if
!
found
{
return
podContainerChangesSpec
{},
fmt
.
Errorf
(
"couldn't find pod %q"
,
podFullName
)
}
podStatus
,
err
:=
kl
.
generatePodStatus
(
pod
)
if
err
!=
nil
{
glog
.
Errorf
(
"Unable to get pod with name %q and uid %q info with error(%v)"
,
podFullName
,
uid
,
err
)
return
podContainerChangesSpec
{},
err
}
for
index
,
container
:=
range
pod
.
Spec
.
Containers
{
for
index
,
container
:=
range
pod
.
Spec
.
Containers
{
expectedHash
:=
dockertools
.
HashContainer
(
&
container
)
expectedHash
:=
dockertools
.
HashContainer
(
&
container
)
...
@@ -1213,7 +1197,18 @@ func (kl *Kubelet) syncPod(pod *api.Pod, mirrorPod *api.Pod, runningPod kubecont
...
@@ -1213,7 +1197,18 @@ func (kl *Kubelet) syncPod(pod *api.Pod, mirrorPod *api.Pod, runningPod kubecont
return
err
return
err
}
}
containerChanges
,
err
:=
kl
.
computePodContainerChanges
(
pod
,
runningPod
)
if
err
:=
kl
.
makePodDataDirs
(
pod
);
err
!=
nil
{
glog
.
Errorf
(
"Unable to make pod data directories for pod %q (uid %q): %v"
,
podFullName
,
uid
,
err
)
return
err
}
podStatus
,
err
:=
kl
.
generatePodStatus
(
pod
)
if
err
!=
nil
{
glog
.
Errorf
(
"Unable to get status for pod %q (uid %q): %v"
,
podFullName
,
uid
,
err
)
return
err
}
containerChanges
,
err
:=
kl
.
computePodContainerChanges
(
pod
,
runningPod
,
podStatus
)
glog
.
V
(
3
)
.
Infof
(
"Got container changes for pod %q: %+v"
,
podFullName
,
containerChanges
)
glog
.
V
(
3
)
.
Infof
(
"Got container changes for pod %q: %+v"
,
podFullName
,
containerChanges
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
pkg/kubelet/kubelet_test.go
View file @
914a6feb
...
@@ -511,10 +511,10 @@ func TestSyncPodsDoesNothing(t *testing.T) {
...
@@ -511,10 +511,10 @@ func TestSyncPodsDoesNothing(t *testing.T) {
waitGroup
.
Wait
()
waitGroup
.
Wait
()
verifyCalls
(
t
,
fakeDocker
,
[]
string
{
verifyCalls
(
t
,
fakeDocker
,
[]
string
{
"list"
,
"list"
,
"list"
,
"list"
,
// Check the pod infra contianer.
"inspect_container"
,
// Get pod status.
// Get pod status.
"list"
,
"inspect_container"
,
"inspect_container"
,
"list"
,
"inspect_container"
,
"inspect_container"
,
// Check the pod infra contianer.
"inspect_container"
,
// Get pod status.
// Get pod status.
"list"
,
"inspect_container"
,
"inspect_container"
})
"list"
,
"inspect_container"
,
"inspect_container"
})
}
}
...
@@ -743,10 +743,10 @@ func TestSyncPodsWithPodInfraCreatesContainer(t *testing.T) {
...
@@ -743,10 +743,10 @@ func TestSyncPodsWithPodInfraCreatesContainer(t *testing.T) {
verifyCalls
(
t
,
fakeDocker
,
[]
string
{
verifyCalls
(
t
,
fakeDocker
,
[]
string
{
"list"
,
"list"
,
"list"
,
"list"
,
// Check the pod infra container.
"inspect_container"
,
// Get pod status.
// Get pod status.
"list"
,
"inspect_container"
,
"inspect_image"
,
"list"
,
"inspect_container"
,
"inspect_image"
,
// Check the pod infra container.
"inspect_container"
,
// Create container.
// Create container.
"create"
,
"start"
,
"create"
,
"start"
,
// Get pod status.
// Get pod status.
...
@@ -818,10 +818,10 @@ func TestSyncPodsWithPodInfraCreatesContainerCallsHandler(t *testing.T) {
...
@@ -818,10 +818,10 @@ func TestSyncPodsWithPodInfraCreatesContainerCallsHandler(t *testing.T) {
verifyCalls
(
t
,
fakeDocker
,
[]
string
{
verifyCalls
(
t
,
fakeDocker
,
[]
string
{
"list"
,
"list"
,
"list"
,
"list"
,
// Check the pod infra container.
"inspect_container"
,
// Get pod status.
// Get pod status.
"list"
,
"inspect_container"
,
"inspect_image"
,
"list"
,
"inspect_container"
,
"inspect_image"
,
// Check the pod infra container.
"inspect_container"
,
// Create container.
// Create container.
"create"
,
"start"
,
"create"
,
"start"
,
// Get pod status.
// Get pod status.
...
@@ -1104,10 +1104,10 @@ func TestSyncPodsDeletesDuplicate(t *testing.T) {
...
@@ -1104,10 +1104,10 @@ func TestSyncPodsDeletesDuplicate(t *testing.T) {
verifyCalls
(
t
,
fakeDocker
,
[]
string
{
verifyCalls
(
t
,
fakeDocker
,
[]
string
{
"list"
,
"list"
,
"list"
,
"list"
,
// Check the pod infra container.
"inspect_container"
,
// Get pod status.
// Get pod status.
"list"
,
"inspect_container"
,
"inspect_container"
,
"inspect_container"
,
"list"
,
"inspect_container"
,
"inspect_container"
,
"inspect_container"
,
// Check the pod infra container.
"inspect_container"
,
// Kill the duplicated container.
// Kill the duplicated container.
"stop"
,
"stop"
,
// Get pod status.
// Get pod status.
...
@@ -1175,10 +1175,10 @@ func TestSyncPodsBadHash(t *testing.T) {
...
@@ -1175,10 +1175,10 @@ func TestSyncPodsBadHash(t *testing.T) {
verifyCalls
(
t
,
fakeDocker
,
[]
string
{
verifyCalls
(
t
,
fakeDocker
,
[]
string
{
"list"
,
"list"
,
"list"
,
"list"
,
// Check the pod infra container.
"inspect_container"
,
// Get pod status.
// Get pod status.
"list"
,
"inspect_container"
,
"inspect_container"
,
"list"
,
"inspect_container"
,
"inspect_container"
,
// Check the pod infra container.
"inspect_container"
,
// Kill and restart the bad hash container.
// Kill and restart the bad hash container.
"stop"
,
"create"
,
"start"
,
"stop"
,
"create"
,
"start"
,
// Get pod status.
// Get pod status.
...
@@ -1249,10 +1249,10 @@ func TestSyncPodsUnhealthy(t *testing.T) {
...
@@ -1249,10 +1249,10 @@ func TestSyncPodsUnhealthy(t *testing.T) {
verifyCalls
(
t
,
fakeDocker
,
[]
string
{
verifyCalls
(
t
,
fakeDocker
,
[]
string
{
"list"
,
"list"
,
"list"
,
"list"
,
// Check the pod infra container.
"inspect_container"
,
// Get pod status.
// Get pod status.
"list"
,
"inspect_container"
,
"inspect_container"
,
"list"
,
"inspect_container"
,
"inspect_container"
,
// Check the pod infra container.
"inspect_container"
,
// Kill the unhealthy container.
// Kill the unhealthy container.
"stop"
,
"stop"
,
// Restart the unhealthy container.
// Restart the unhealthy container.
...
@@ -1864,10 +1864,10 @@ func TestSyncPodEventHandlerFails(t *testing.T) {
...
@@ -1864,10 +1864,10 @@ func TestSyncPodEventHandlerFails(t *testing.T) {
verifyCalls
(
t
,
fakeDocker
,
[]
string
{
verifyCalls
(
t
,
fakeDocker
,
[]
string
{
"list"
,
"list"
,
"list"
,
"list"
,
// Check the pod infra container.
"inspect_container"
,
// Get pod status.
// Get pod status.
"list"
,
"inspect_container"
,
"inspect_image"
,
"list"
,
"inspect_container"
,
"inspect_image"
,
// Check the pod infra container.
"inspect_container"
,
// Create the container.
// Create the container.
"create"
,
"start"
,
"create"
,
"start"
,
// Kill the container since event handler fails.
// Kill the container since event handler fails.
...
@@ -3867,10 +3867,10 @@ func TestSyncPodsWithRestartPolicy(t *testing.T) {
...
@@ -3867,10 +3867,10 @@ func TestSyncPodsWithRestartPolicy(t *testing.T) {
{
{
api
.
RestartPolicyAlways
,
api
.
RestartPolicyAlways
,
[]
string
{
"list"
,
"list"
,
[]
string
{
"list"
,
"list"
,
// Check the pod infra container.
"inspect_container"
,
// Get pod status.
// Get pod status.
"list"
,
"inspect_container"
,
"inspect_container"
,
"inspect_container"
,
"list"
,
"inspect_container"
,
"inspect_container"
,
"inspect_container"
,
// Check the pod infra container.
"inspect_container"
,
// Restart both containers.
// Restart both containers.
"create"
,
"start"
,
"create"
,
"start"
,
"create"
,
"start"
,
"create"
,
"start"
,
// Get pod status.
// Get pod status.
...
@@ -3881,10 +3881,10 @@ func TestSyncPodsWithRestartPolicy(t *testing.T) {
...
@@ -3881,10 +3881,10 @@ func TestSyncPodsWithRestartPolicy(t *testing.T) {
{
{
api
.
RestartPolicyOnFailure
,
api
.
RestartPolicyOnFailure
,
[]
string
{
"list"
,
"list"
,
[]
string
{
"list"
,
"list"
,
// Check the pod infra container.
"inspect_container"
,
// Get pod status.
// Get pod status.
"list"
,
"inspect_container"
,
"inspect_container"
,
"inspect_container"
,
"list"
,
"inspect_container"
,
"inspect_container"
,
"inspect_container"
,
// Check the pod infra container.
"inspect_container"
,
// Restart the failed container.
// Restart the failed container.
"create"
,
"start"
,
"create"
,
"start"
,
// Get pod status.
// Get pod status.
...
@@ -3895,10 +3895,10 @@ func TestSyncPodsWithRestartPolicy(t *testing.T) {
...
@@ -3895,10 +3895,10 @@ func TestSyncPodsWithRestartPolicy(t *testing.T) {
{
{
api
.
RestartPolicyNever
,
api
.
RestartPolicyNever
,
[]
string
{
"list"
,
"list"
,
[]
string
{
"list"
,
"list"
,
// Check the pod infra container.
"inspect_container"
,
// Get pod status.
// Get pod status.
"list"
,
"inspect_container"
,
"inspect_container"
,
"inspect_container"
,
"list"
,
"inspect_container"
,
"inspect_container"
,
"inspect_container"
,
// Check the pod infra container.
"inspect_container"
,
// Stop the last pod infra container.
// Stop the last pod infra container.
"stop"
,
"stop"
,
// Get pod status.
// Get pod status.
...
...
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