From 0351629517d4d1912d778b112f688538b5f11449 Mon Sep 17 00:00:00 2001 From: Random-Liu Date: Mon, 27 Feb 2017 20:37:49 -0800 Subject: [PATCH] Make dockershim better implements CRI. --- pkg/kubelet/dockershim/docker_sandbox.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/pkg/kubelet/dockershim/docker_sandbox.go b/pkg/kubelet/dockershim/docker_sandbox.go index 1c8fa11f94..c61138a32a 100644 --- a/pkg/kubelet/dockershim/docker_sandbox.go +++ b/pkg/kubelet/dockershim/docker_sandbox.go @@ -297,6 +297,8 @@ func (ds *dockerService) PodSandboxStatus(podSandboxID string) (*runtimeapi.PodS Network: netNS, Options: &runtimeapi.NamespaceOption{ HostNetwork: hostNetwork, + HostPid: sharesHostPid(r), + HostIpc: sharesHostIpc(r), }, }, }, @@ -489,7 +491,7 @@ func (ds *dockerService) makeSandboxDockerConfig(c *runtimeapi.PodSandboxConfig, return createConfig, nil } -// sharesHostNetwork true if the given container is sharing the hosts's +// sharesHostNetwork returns true if the given container is sharing the host's // network namespace. func sharesHostNetwork(container *dockertypes.ContainerJSON) bool { if container != nil && container.HostConfig != nil { @@ -498,6 +500,24 @@ func sharesHostNetwork(container *dockertypes.ContainerJSON) bool { return false } +// sharesHostPid returns true if the given container is sharing the host's pid +// namespace. +func sharesHostPid(container *dockertypes.ContainerJSON) bool { + if container != nil && container.HostConfig != nil { + return string(container.HostConfig.PidMode) == namespaceModeHost + } + return false +} + +// sharesHostIpc returns true if the given container is sharing the host's ipc +// namespace. +func sharesHostIpc(container *dockertypes.ContainerJSON) bool { + if container != nil && container.HostConfig != nil { + return string(container.HostConfig.IpcMode) == namespaceModeHost + } + return false +} + func setSandboxResources(hc *dockercontainer.HostConfig) { hc.Resources = dockercontainer.Resources{ MemorySwap: dockertools.DefaultMemorySwap(),