Skip to content

Commit add5a7d

Browse files
authored
Merge pull request #97 from Roblox/pid_mode
Add pid_mode to enable host pid namespace.
2 parents 14ccf66 + c2ee373 commit add5a7d

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ More detailed instructions are in the [`example README.md`](https://github.com/R
101101
| **cwd** | string | no | Specify the current working directory for your container process. If the directory does not exist, one will be created for you. |
102102
| **privileged** | bool | no | Run container in privileged mode. Your container will have all linux capabilities when running in privileged mode. |
103103
| **pids_limit** | int64 | no | An integer value that specifies the pid limit for the container. Defaults to unlimited. |
104+
| **pid_mode** | string | no | `host` or not set (default). Set to `host` to share the PID namespace with the host. |
104105
| **hostname** | string | no | The hostname to assign to the container. When launching more than one of a task (using `count`) with this option set, every container the task starts will have the same hostname. |
105106
| **host_dns** | bool | no | Default (`true`). By default, a container launched using `containerd-driver` will use host `/etc/resolv.conf`. This is similar to [`docker behavior`](https://docs.docker.com/config/containers/container-networking/#dns-services). However, if you don't want to use host DNS, you can turn off this flag by setting `host_dns=false`. |
106107
| **seccomp** | bool | no | Enable default seccomp profile. List of [`allowed syscalls`](https://github.com/containerd/containerd/blob/master/contrib/seccomp/seccomp_default.go#L51-L395). |

containerd/containerd.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package containerd
2020
import (
2121
"context"
2222
"fmt"
23+
"strings"
2324
"time"
2425

2526
etchosts "github.com/Roblox/nomad-driver-containerd/etchosts"
@@ -155,6 +156,14 @@ func (d *Driver) createContainer(containerConfig *ContainerConfig, config *TaskC
155156
opts = append(opts, oci.WithPidsLimit(config.PidsLimit))
156157
}
157158

159+
if config.PidMode != "" {
160+
if strings.ToLower(config.PidMode) != "host" {
161+
return nil, fmt.Errorf("Invalid pid_mode. Set pid_mode=host to enable host pid namespace.")
162+
} else {
163+
opts = append(opts, oci.WithHostNamespace(specs.PIDNamespace))
164+
}
165+
}
166+
158167
// Set sysctls
159168
if len(config.Sysctl) > 0 {
160169
opts = append(opts, WithSysctls(config.Sysctl))

containerd/driver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ var (
104104
"devices": hclspec.NewAttr("devices", "list(string)", false),
105105
"privileged": hclspec.NewAttr("privileged", "bool", false),
106106
"pids_limit": hclspec.NewAttr("pids_limit", "number", false),
107+
"pid_mode": hclspec.NewAttr("pid_mode", "string", false),
107108
"hostname": hclspec.NewAttr("hostname", "string", false),
108109
"host_dns": hclspec.NewDefault(
109110
hclspec.NewAttr("host_dns", "bool", false),
@@ -185,6 +186,7 @@ type TaskConfig struct {
185186
Sysctl hclutils.MapStrStr `codec:"sysctl"`
186187
Privileged bool `codec:"privileged"`
187188
PidsLimit int64 `codec:"pids_limit"`
189+
PidMode string `codec:"pid_mode"`
188190
Hostname string `codec:"hostname"`
189191
HostDNS bool `codec:"host_dns"`
190192
ImagePullTimeout string `codec:"image_pull_timeout"`

0 commit comments

Comments
 (0)