Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable compatibility with Nomad in cgroups.v2 mode #133

Merged
merged 1 commit into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion containerd/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/hashicorp/nomad/plugins/drivers"
"github.com/hashicorp/nomad/plugins/shared/hclspec"
"github.com/hashicorp/nomad/plugins/shared/structs"
"github.com/opencontainers/runc/libcontainer/cgroups"
)

const (
Expand Down Expand Up @@ -259,7 +260,13 @@ func NewPlugin(logger log.Logger) drivers.DriverPlugin {
// Calls to containerd API are namespaced.
// "nomad" is the namespace that will be used for all nomad-driver-containerd
// related containerd API calls.
ctxContainerd := namespaces.WithNamespace(context.Background(), "nomad")
namespace := "nomad"
// Unless we are operating in cgroups.v2 mode, in which case we use the
// name "nomad.slice", which ends up being the cgroup parent.
if cgroups.IsCgroup2UnifiedMode() {
namespace = "nomad.slice"
}
ctxContainerd := namespaces.WithNamespace(context.Background(), namespace)

return &Driver{
eventer: eventer.NewEventer(ctx, logger),
Expand Down Expand Up @@ -428,8 +435,13 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
handle := drivers.NewTaskHandle(taskHandleVersion)
handle.Config = cfg

// Use Nomad's docker naming convention for the container name
// https://www.nomadproject.io/docs/drivers/docker#container-name
containerName := cfg.Name + "-" + cfg.AllocID
if cgroups.IsCgroup2UnifiedMode() {
// In cgroup.v2 mode, the name is slightly different.
containerName = fmt.Sprintf("%s.%s.scope", cfg.AllocID, cfg.Name)
}
containerConfig.ContainerName = containerName

var err error
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/hashicorp/go-hclog v0.14.1
github.com/hashicorp/go-uuid v1.0.2
github.com/hashicorp/nomad v1.1.12
github.com/opencontainers/runc v1.1.0
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417
github.com/spf13/cobra v1.1.3
)
Expand All @@ -28,12 +29,15 @@ require (
github.com/containerd/continuity v0.2.2 // indirect
github.com/containerd/fifo v1.0.0 // indirect
github.com/containerd/ttrpc v1.1.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect
github.com/docker/libnetwork v0.8.0-dev.2.0.20200612180813-9e99af28df21 // indirect
github.com/fatih/color v1.9.0 // indirect
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/godbus/dbus/v5 v5.0.6 // indirect
github.com/gogo/googleapis v1.4.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand Down Expand Up @@ -79,7 +83,6 @@ require (
github.com/oklog/run v1.0.1-0.20180308005104-6934b124db28 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2-0.20211117181255-693428a734f5 // indirect
github.com/opencontainers/runc v1.1.0 // indirect
github.com/opencontainers/selinux v1.10.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down