@@ -24,6 +24,7 @@ import (
2424 "time"
2525
2626 "github.com/containerd/containerd"
27+ "github.com/containerd/containerd/defaults"
2728 "github.com/containerd/containerd/namespaces"
2829 "github.com/hashicorp/consul-template/signals"
2930 "github.com/hashicorp/go-hclog"
@@ -37,7 +38,6 @@ import (
3738 "github.com/hashicorp/nomad/plugins/drivers"
3839 "github.com/hashicorp/nomad/plugins/shared/hclspec"
3940 "github.com/hashicorp/nomad/plugins/shared/structs"
40- "github.com/opencontainers/runc/libcontainer/cgroups"
4141)
4242
4343const (
@@ -260,21 +260,12 @@ func NewPlugin(logger log.Logger) drivers.DriverPlugin {
260260
261261 // This will create a new containerd client which will talk to
262262 // default containerd socket path.
263- client , err := containerd .New ("/run/containerd/containerd.sock" )
263+ client , err := containerd .New (defaults . DefaultAddress )
264264 if err != nil {
265265 logger .Error ("Error in creating containerd client" , "err" , err )
266266 return nil
267267 }
268-
269- // Calls to containerd API are namespaced.
270- // "nomad" is the namespace that will be used for all nomad-driver-containerd
271- // related containerd API calls.
272- namespace := "nomad"
273- // Unless we are operating in cgroups.v2 mode, in which case we use the
274- // name "nomad.slice", which ends up being the cgroup parent.
275- if cgroups .IsCgroup2UnifiedMode () {
276- namespace = "nomad.slice"
277- }
268+ namespace := getNamespaceName ()
278269 ctxContainerd := namespaces .WithNamespace (context .Background (), namespace )
279270
280271 return & Driver {
@@ -445,13 +436,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
445436 handle := drivers .NewTaskHandle (taskHandleVersion )
446437 handle .Config = cfg
447438
448- // Use Nomad's docker naming convention for the container name
449- // https://www.nomadproject.io/docs/drivers/docker#container-name
450- containerName := cfg .Name + "-" + cfg .AllocID
451- if cgroups .IsCgroup2UnifiedMode () {
452- // In cgroup.v2 mode, the name is slightly different.
453- containerName = fmt .Sprintf ("%s.%s.scope" , cfg .AllocID , cfg .Name )
454- }
439+ containerName := getContainerName (cfg .Name , cfg .AllocID )
455440 containerConfig .ContainerName = containerName
456441
457442 var err error
0 commit comments