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
1de4c451
Commit
1de4c451
authored
Apr 28, 2015
by
Dawn Chen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7401 from vmarmol/rkt-kill-pod
Kubelet: Move killPod() logic to DockerManager's KillPod()
parents
f2b9b673
6b0db76e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
28 deletions
+51
-28
runtime.go
pkg/kubelet/container/runtime.go
+1
-1
manager.go
pkg/kubelet/dockertools/manager.go
+38
-0
kubelet.go
pkg/kubelet/kubelet.go
+12
-27
No files found.
pkg/kubelet/container/runtime.go
View file @
1de4c451
...
@@ -47,7 +47,7 @@ type Runtime interface {
...
@@ -47,7 +47,7 @@ type Runtime interface {
// RunPod starts all the containers of a pod within a namespace.
// RunPod starts all the containers of a pod within a namespace.
RunPod
(
*
api
.
Pod
,
map
[
string
]
volume
.
Volume
)
error
RunPod
(
*
api
.
Pod
,
map
[
string
]
volume
.
Volume
)
error
// KillPod kills all the containers of a pod.
// KillPod kills all the containers of a pod.
KillPod
(
*
api
.
Pod
)
error
KillPod
(
pod
Pod
)
error
// RunContainerInPod starts a container within the same namespace of a pod.
// RunContainerInPod starts a container within the same namespace of a pod.
RunContainerInPod
(
api
.
Container
,
*
api
.
Pod
,
map
[
string
]
volume
.
Volume
)
error
RunContainerInPod
(
api
.
Container
,
*
api
.
Pod
,
map
[
string
]
volume
.
Volume
)
error
// KillContainerInPod kills a container in the pod.
// KillContainerInPod kills a container in the pod.
...
...
pkg/kubelet/dockertools/manager.go
View file @
1de4c451
...
@@ -433,6 +433,15 @@ func (dm *DockerManager) GetPodStatus(pod *api.Pod) (*api.PodStatus, error) {
...
@@ -433,6 +433,15 @@ func (dm *DockerManager) GetPodStatus(pod *api.Pod) (*api.PodStatus, error) {
return
&
podStatus
,
nil
return
&
podStatus
,
nil
}
}
func
(
dm
*
DockerManager
)
GetPodInfraContainer
(
pod
kubecontainer
.
Pod
)
(
kubecontainer
.
Container
,
error
)
{
for
_
,
container
:=
range
pod
.
Containers
{
if
container
.
Name
==
PodInfraContainerName
{
return
*
container
,
nil
}
}
return
kubecontainer
.
Container
{},
fmt
.
Errorf
(
"unable to find pod infra container for pod %v"
,
pod
.
ID
)
}
func
(
dm
*
DockerManager
)
GetRunningContainers
(
ids
[]
string
)
([]
*
docker
.
Container
,
error
)
{
func
(
dm
*
DockerManager
)
GetRunningContainers
(
ids
[]
string
)
([]
*
docker
.
Container
,
error
)
{
var
result
[]
*
docker
.
Container
var
result
[]
*
docker
.
Container
if
dm
.
client
==
nil
{
if
dm
.
client
==
nil
{
...
@@ -930,6 +939,35 @@ func (dm *DockerManager) PortForward(pod *kubecontainer.Pod, port uint16, stream
...
@@ -930,6 +939,35 @@ func (dm *DockerManager) PortForward(pod *kubecontainer.Pod, port uint16, stream
return
command
.
Run
()
return
command
.
Run
()
}
}
// Kills all containers in the specified pod
func
(
dm
*
DockerManager
)
KillPod
(
pod
kubecontainer
.
Pod
)
error
{
// Send the kills in parallel since they may take a long time.
errs
:=
make
(
chan
error
,
len
(
pod
.
Containers
))
wg
:=
sync
.
WaitGroup
{}
for
_
,
container
:=
range
pod
.
Containers
{
wg
.
Add
(
1
)
go
func
(
container
*
kubecontainer
.
Container
)
{
defer
util
.
HandleCrash
()
err
:=
dm
.
KillContainer
(
container
.
ID
)
if
err
!=
nil
{
glog
.
Errorf
(
"Failed to delete container: %v; Skipping pod %q"
,
err
,
pod
.
ID
)
errs
<-
err
}
wg
.
Done
()
}(
container
)
}
wg
.
Wait
()
close
(
errs
)
if
len
(
errs
)
>
0
{
errList
:=
[]
error
{}
for
err
:=
range
errs
{
errList
=
append
(
errList
,
err
)
}
return
fmt
.
Errorf
(
"failed to delete containers (%v)"
,
errList
)
}
return
nil
}
// KillContainer kills a container identified by containerID.
// KillContainer kills a container identified by containerID.
// Internally, it invokes docker's StopContainer API with a timeout of 10s.
// Internally, it invokes docker's StopContainer API with a timeout of 10s.
// TODO(yifan): Use new ContainerID type.
// TODO(yifan): Use new ContainerID type.
...
...
pkg/kubelet/kubelet.go
View file @
1de4c451
...
@@ -27,7 +27,6 @@ import (
...
@@ -27,7 +27,6 @@ import (
"path"
"path"
"sort"
"sort"
"strings"
"strings"
"sync"
"time"
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
...
@@ -867,39 +866,25 @@ func (kl *Kubelet) pullImage(img string, ref *api.ObjectReference) error {
...
@@ -867,39 +866,25 @@ func (kl *Kubelet) pullImage(img string, ref *api.ObjectReference) error {
// Kill all running containers in a pod (includes the pod infra container).
// Kill all running containers in a pod (includes the pod infra container).
func
(
kl
*
Kubelet
)
killPod
(
pod
kubecontainer
.
Pod
)
error
{
func
(
kl
*
Kubelet
)
killPod
(
pod
kubecontainer
.
Pod
)
error
{
// Send the kills in parallel since they may take a long time.
// TODO(vmarmol): Consider handling non-Docker runtimes, the plugins are not friendly to it today.
errs
:=
make
(
chan
error
,
len
(
pod
.
Containers
))
container
,
err
:=
kl
.
containerManager
.
GetPodInfraContainer
(
pod
)
wg
:=
sync
.
WaitGroup
{}
errList
:=
[]
error
{}
for
_
,
container
:=
range
pod
.
Containers
{
if
err
==
nil
{
wg
.
Add
(
1
)
go
func
(
container
*
kubecontainer
.
Container
)
{
defer
util
.
HandleCrash
()
// Call the networking plugin for teardown.
// Call the networking plugin for teardown.
// TODO: Handle this without signaling the pod infra container to
err
=
kl
.
networkPlugin
.
TearDownPod
(
pod
.
Namespace
,
pod
.
Name
,
dockertools
.
DockerID
(
container
.
ID
))
// adapt to the generic container runtime.
if
container
.
Name
==
dockertools
.
PodInfraContainerName
{
err
:=
kl
.
networkPlugin
.
TearDownPod
(
pod
.
Namespace
,
pod
.
Name
,
dockertools
.
DockerID
(
container
.
ID
))
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Failed tearing down the infra container: %v"
,
err
)
glog
.
Errorf
(
"Failed tearing down the network plugin for pod %q: %v"
,
pod
.
ID
,
err
)
errs
<-
err
errList
=
append
(
errList
,
err
)
}
}
}
}
err
:=
kl
.
containerManager
.
KillContainer
(
container
.
ID
)
err
=
kl
.
containerManager
.
KillPod
(
pod
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Failed to delete container: %v; Skipping pod %q"
,
err
,
pod
.
ID
)
errs
<-
err
}
wg
.
Done
()
}(
container
)
}
wg
.
Wait
()
close
(
errs
)
if
len
(
errs
)
>
0
{
errList
:=
[]
error
{}
for
err
:=
range
errs
{
errList
=
append
(
errList
,
err
)
errList
=
append
(
errList
,
err
)
}
}
return
fmt
.
Errorf
(
"failed to delete containers (%v)"
,
errList
)
if
len
(
errList
)
>
0
{
return
utilErrors
.
NewAggregate
(
errList
)
}
}
return
nil
return
nil
}
}
...
...
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