Skip to content

Commit

Permalink
Get rid of docker pause containers with a custom runtime. Closes #15086
Browse files Browse the repository at this point in the history
  • Loading branch information
apollo13 committed Nov 4, 2024
1 parent f75e2c2 commit 93c0eee
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
6 changes: 6 additions & 0 deletions drivers/docker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ var (
// task containers. If true, nomad doesn't start docker_logger/logmon processes
"disable_log_collection": hclspec.NewAttr("disable_log_collection", "bool", false),

"new_networking": hclspec.NewAttr("new_networking", "bool", false),

// windows_allow_insecure_container_admin indicates that on windows,
// docker checks the task.user field or, if unset, the container image
// manifest after pulling the container, to see if it's running as
Expand Down Expand Up @@ -675,6 +677,7 @@ type DriverConfig struct {
infraImagePullTimeoutDuration time.Duration `codec:"-"`
ContainerExistsAttempts uint64 `codec:"container_exists_attempts"`
DisableLogCollection bool `codec:"disable_log_collection"`
NewNetworking bool `codec:"new_networking"`
PullActivityTimeout string `codec:"pull_activity_timeout"`
PidsLimit int64 `codec:"pids_limit"`
pullActivityTimeoutDuration time.Duration `codec:"-"`
Expand Down Expand Up @@ -828,5 +831,8 @@ func (d *Driver) TaskConfigSchema() (*hclspec.Spec, error) {
// features this driver supports.
func (d *Driver) Capabilities() (*drivers.Capabilities, error) {
driverCapabilities.DisableLogCollection = d.config != nil && d.config.DisableLogCollection
if d.config != nil {
driverCapabilities.MustInitiateNetwork = !d.config.NewNetworking
}
return driverCapabilities, nil
}
23 changes: 19 additions & 4 deletions drivers/docker/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,13 @@ func (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *T
if _, ok := d.config.allowRuntimes[containerRuntime]; !ok && containerRuntime != "" {
return c, fmt.Errorf("requested runtime %q is not allowed", containerRuntime)
}
if d.config.NewNetworking {
if containerRuntime == "" {
containerRuntime = "nomad"
} else {
return c, fmt.Errorf("new-style networking not compatible with custom runtimess")
}
}

// Validate isolation modes on windows
if runtime.GOOS != "windows" {
Expand Down Expand Up @@ -1038,6 +1045,8 @@ func (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *T

Runtime: containerRuntime,
GroupAdd: driverConfig.GroupAdd,

Annotations: map[string]string{},
}

hostConfig.Resources = containerapi.Resources{
Expand Down Expand Up @@ -1285,10 +1294,16 @@ func (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *T
// shared alloc network
if hostConfig.NetworkMode == "" {
if task.NetworkIsolation != nil && task.NetworkIsolation.Path != "" {
// find the previously created parent container to join networks with
netMode := fmt.Sprintf("container:%s", task.NetworkIsolation.Labels[dockerNetSpecLabelKey])
logger.Debug("configuring network mode for task group", "network_mode", netMode)
hostConfig.NetworkMode = containerapi.NetworkMode(netMode)
if d.config.NewNetworking {
// "host" is not actually true here, it will cause joining the existing namespace
hostConfig.NetworkMode = "host"
hostConfig.Annotations["network_ns"] = task.NetworkIsolation.Path
} else {
// find the previously created parent container to join networks with
netMode := fmt.Sprintf("container:%s", task.NetworkIsolation.Labels[dockerNetSpecLabelKey])
logger.Debug("configuring network mode for task group", "network_mode", netMode)
hostConfig.NetworkMode = containerapi.NetworkMode(netMode)
}
} else {
// docker default
logger.Debug("networking mode not specified; using default")
Expand Down

0 comments on commit 93c0eee

Please sign in to comment.