mirror of
https://github.com/containers/podman.git
synced 2025-07-15 03:02:52 +08:00
kube-play: add support for HostIPC in pod.Spec
* play_kube_test: add tests Signed-off-by: danishprakash <danish.prakash@suse.com>
This commit is contained in:
@ -48,7 +48,7 @@ Note: **N/A** means that the option cannot be supported in a single-node Podman
|
|||||||
| dnsPolicy | |
|
| dnsPolicy | |
|
||||||
| hostNetwork | ✅ |
|
| hostNetwork | ✅ |
|
||||||
| hostPID | ✅ |
|
| hostPID | ✅ |
|
||||||
| hostIPC | |
|
| hostIPC | ✅ |
|
||||||
| shareProcessNamespace | ✅ |
|
| shareProcessNamespace | ✅ |
|
||||||
| serviceAccountName | |
|
| serviceAccountName | |
|
||||||
| automountServiceAccountToken | |
|
| automountServiceAccountToken | |
|
||||||
|
@ -129,6 +129,7 @@ type PodCreateOptions struct {
|
|||||||
InfraName string `json:"container_name,omitempty"`
|
InfraName string `json:"container_name,omitempty"`
|
||||||
InfraCommand *string `json:"container_command,omitempty"`
|
InfraCommand *string `json:"container_command,omitempty"`
|
||||||
InfraConmonPidFile string `json:"container_conmon_pidfile,omitempty"`
|
InfraConmonPidFile string `json:"container_conmon_pidfile,omitempty"`
|
||||||
|
Ipc string `json:"ipc,omitempty"`
|
||||||
Labels map[string]string `json:"labels,omitempty"`
|
Labels map[string]string `json:"labels,omitempty"`
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Net *NetOptions `json:"net,omitempty"`
|
Net *NetOptions `json:"net,omitempty"`
|
||||||
@ -349,6 +350,12 @@ func ToPodSpecGen(s specgen.PodSpecGenerator, p *PodCreateOptions) (*specgen.Pod
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
s.Pid = out
|
s.Pid = out
|
||||||
|
|
||||||
|
out, err = specgen.ParseNamespace(p.Ipc)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
s.Ipc = out
|
||||||
s.Hostname = p.Hostname
|
s.Hostname = p.Hostname
|
||||||
s.ExitPolicy = p.ExitPolicy
|
s.ExitPolicy = p.ExitPolicy
|
||||||
s.Labels = p.Labels
|
s.Labels = p.Labels
|
||||||
|
@ -710,10 +710,12 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY
|
|||||||
ConfigMaps: configMaps,
|
ConfigMaps: configMaps,
|
||||||
Container: container,
|
Container: container,
|
||||||
Image: pulledImage,
|
Image: pulledImage,
|
||||||
|
IpcNSIsHost: p.Ipc.IsHost(),
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
LogDriver: options.LogDriver,
|
LogDriver: options.LogDriver,
|
||||||
LogOptions: options.LogOptions,
|
LogOptions: options.LogOptions,
|
||||||
NetNSIsHost: p.NetNS.IsHost(),
|
NetNSIsHost: p.NetNS.IsHost(),
|
||||||
|
PidNSIsHost: p.Pid.IsHost(),
|
||||||
PodID: pod.ID(),
|
PodID: pod.ID(),
|
||||||
PodInfraID: podInfraID,
|
PodInfraID: podInfraID,
|
||||||
PodName: podName,
|
PodName: podName,
|
||||||
@ -722,7 +724,6 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY
|
|||||||
RestartPolicy: ctrRestartPolicy,
|
RestartPolicy: ctrRestartPolicy,
|
||||||
SeccompPaths: seccompPaths,
|
SeccompPaths: seccompPaths,
|
||||||
SecretsManager: secretsManager,
|
SecretsManager: secretsManager,
|
||||||
PidNSIsHost: p.Pid.IsHost(),
|
|
||||||
UserNSIsHost: p.Userns.IsHost(),
|
UserNSIsHost: p.Userns.IsHost(),
|
||||||
Volumes: volumes,
|
Volumes: volumes,
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,9 @@ func ToPodOpt(ctx context.Context, podName string, p entities.PodCreateOptions,
|
|||||||
if podYAML.Spec.HostPID {
|
if podYAML.Spec.HostPID {
|
||||||
p.Pid = "host"
|
p.Pid = "host"
|
||||||
}
|
}
|
||||||
|
if podYAML.Spec.HostIPC {
|
||||||
|
p.Ipc = "host"
|
||||||
|
}
|
||||||
p.Hostname = podYAML.Spec.Hostname
|
p.Hostname = podYAML.Spec.Hostname
|
||||||
if p.Hostname == "" {
|
if p.Hostname == "" {
|
||||||
p.Hostname = podName
|
p.Hostname = podName
|
||||||
@ -114,6 +117,8 @@ type CtrSpecGenOptions struct {
|
|||||||
Container v1.Container
|
Container v1.Container
|
||||||
// Image available to use (pulled or found local)
|
// Image available to use (pulled or found local)
|
||||||
Image *libimage.Image
|
Image *libimage.Image
|
||||||
|
// IPCNSIsHost tells the container to use the host ipcns
|
||||||
|
IpcNSIsHost bool
|
||||||
// Volumes for all containers
|
// Volumes for all containers
|
||||||
Volumes map[string]*KubeVolume
|
Volumes map[string]*KubeVolume
|
||||||
// PodID of the parent pod
|
// PodID of the parent pod
|
||||||
@ -470,6 +475,9 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener
|
|||||||
if opts.PidNSIsHost {
|
if opts.PidNSIsHost {
|
||||||
s.PidNS.NSMode = specgen.Host
|
s.PidNS.NSMode = specgen.Host
|
||||||
}
|
}
|
||||||
|
if opts.IpcNSIsHost {
|
||||||
|
s.IpcNS.NSMode = specgen.Host
|
||||||
|
}
|
||||||
|
|
||||||
// Add labels that come from kube
|
// Add labels that come from kube
|
||||||
if len(s.Labels) == 0 {
|
if len(s.Labels) == 0 {
|
||||||
|
@ -53,6 +53,9 @@ type PodBasicConfig struct {
|
|||||||
// Conflicts with NoInfra=true.
|
// Conflicts with NoInfra=true.
|
||||||
// Optional.
|
// Optional.
|
||||||
InfraName string `json:"infra_name,omitempty"`
|
InfraName string `json:"infra_name,omitempty"`
|
||||||
|
// Ipc sets the IPC namespace of the pod, set to private by default.
|
||||||
|
// This configuration will then be shared with the entire pod if PID namespace sharing is enabled via --share
|
||||||
|
Ipc Namespace `json:"ipcns,omitempty"`
|
||||||
// SharedNamespaces instructs the pod to share a set of namespaces.
|
// SharedNamespaces instructs the pod to share a set of namespaces.
|
||||||
// Shared namespaces will be joined (by default) by every container
|
// Shared namespaces will be joined (by default) by every container
|
||||||
// which joins the pod.
|
// which joins the pod.
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -953,6 +954,19 @@ spec:
|
|||||||
command: ['sh', '-c', 'echo $$']
|
command: ['sh', '-c', 'echo $$']
|
||||||
`
|
`
|
||||||
|
|
||||||
|
var podWithHostIPCDefined = `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Pod
|
||||||
|
metadata:
|
||||||
|
name: test-hostipc
|
||||||
|
spec:
|
||||||
|
hostIPC: true
|
||||||
|
containers:
|
||||||
|
- name: alpine
|
||||||
|
image: quay.io/libpod/alpine:latest
|
||||||
|
command: ['sh', '-c', 'ls -l /proc/self/ns/ipc']
|
||||||
|
`
|
||||||
|
|
||||||
var (
|
var (
|
||||||
defaultCtrName = "testCtr"
|
defaultCtrName = "testCtr"
|
||||||
defaultCtrCmd = []string{"top"}
|
defaultCtrCmd = []string{"top"}
|
||||||
@ -4964,4 +4978,32 @@ spec:
|
|||||||
Expect(inspect.OutputToString()).To(Equal("host"))
|
Expect(inspect.OutputToString()).To(Equal("host"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman play kube test with hostIPC", func() {
|
||||||
|
err := writeYaml(podWithHostIPCDefined, kubeYaml)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
kube := podmanTest.Podman([]string{"play", "kube", kubeYaml})
|
||||||
|
kube.WaitWithDefaultTimeout()
|
||||||
|
Expect(kube).Should(Exit(0))
|
||||||
|
|
||||||
|
inspect := podmanTest.Podman([]string{"inspect", "test-hostipc-alpine", "--format", "{{ .HostConfig.IpcMode }}"})
|
||||||
|
inspect.WaitWithDefaultTimeout()
|
||||||
|
Expect(inspect).Should(Exit(0))
|
||||||
|
Expect(inspect.OutputToString()).To(Equal("shareable"))
|
||||||
|
|
||||||
|
cmd := exec.Command("ls", "-l", "/proc/self/ns/ipc")
|
||||||
|
res, err := cmd.Output()
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
fields := strings.Split(string(res), " ")
|
||||||
|
hostIpcNS := strings.TrimSuffix(fields[len(fields)-1], "\n")
|
||||||
|
|
||||||
|
logs := podmanTest.Podman([]string{"pod", "logs", "-c", "test-hostipc-alpine", "test-hostipc"})
|
||||||
|
logs.WaitWithDefaultTimeout()
|
||||||
|
Expect(logs).Should(Exit(0))
|
||||||
|
fields = strings.Split(logs.OutputToString(), " ")
|
||||||
|
ctrIpcNS := strings.TrimSuffix(fields[len(fields)-1], "\n")
|
||||||
|
|
||||||
|
Expect(hostIpcNS).To(Equal(ctrIpcNS))
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user