Skip to content

Commit c9021e5

Browse files
committed
Add Windows Support
Signed-off-by: Olli Janatuinen <[email protected]>
1 parent 8654f7a commit c9021e5

File tree

5 files changed

+45
-18
lines changed

5 files changed

+45
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.vagrant/
22
/containerd-driver
3+
/containerd-driver.exe

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ clean:
1616
.PHONY: build
1717
build:
1818
$(GOLANG) build -o $(BINARY) .
19+
GOOS=windows $(GOLANG) build -o $(BINARY).exe .
1920

2021
.PHONY: test
2122
test:

containerd/driver.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import (
3838
"github.com/hashicorp/nomad/plugins/drivers"
3939
"github.com/hashicorp/nomad/plugins/shared/hclspec"
4040
"github.com/hashicorp/nomad/plugins/shared/structs"
41-
"github.com/opencontainers/runc/libcontainer/cgroups"
4241
)
4342

4443
const (
@@ -263,16 +262,7 @@ type Driver struct {
263262
func NewPlugin(logger log.Logger) drivers.DriverPlugin {
264263
ctx, cancel := context.WithCancel(context.Background())
265264
logger = logger.Named(PluginName)
266-
267-
// Calls to containerd API are namespaced.
268-
// "nomad" is the namespace that will be used for all nomad-driver-containerd
269-
// related containerd API calls.
270-
namespace := "nomad"
271-
// Unless we are operating in cgroups.v2 mode, in which case we use the
272-
// name "nomad.slice", which ends up being the cgroup parent.
273-
if cgroups.IsCgroup2UnifiedMode() {
274-
namespace = "nomad.slice"
275-
}
265+
namespace := getNamespaceName()
276266
ctxContainerd := namespaces.WithNamespace(context.Background(), namespace)
277267

278268
return &Driver{
@@ -451,13 +441,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
451441
handle := drivers.NewTaskHandle(taskHandleVersion)
452442
handle.Config = cfg
453443

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

463447
var err error

containerd/driver_linux.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package containerd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/opencontainers/runc/libcontainer/cgroups"
7+
)
8+
9+
func getNamespaceName() string {
10+
// Calls to containerd API are namespaced.
11+
// "nomad" is the namespace that will be used for all nomad-driver-containerd
12+
// related containerd API calls.
13+
namespace := "nomad"
14+
// Unless we are operating in cgroups.v2 mode, in which case we use the
15+
// name "nomad.slice", which ends up being the cgroup parent.
16+
if cgroups.IsCgroup2UnifiedMode() {
17+
namespace = "nomad.slice"
18+
}
19+
return namespace
20+
}
21+
22+
func getContainerName(name, allocID string) string {
23+
// Use Nomad's docker naming convention for the container name
24+
// https://www.nomadproject.io/docs/drivers/docker#container-name
25+
containerName := name + "-" + allocID
26+
if cgroups.IsCgroup2UnifiedMode() {
27+
// In cgroup.v2 mode, the name is slightly different.
28+
containerName = fmt.Sprintf("%s.%s.scope", allocID, name)
29+
}
30+
return containerName
31+
}

containerd/driver_windows.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package containerd
2+
3+
func getNamespaceName() string {
4+
return "nomad"
5+
}
6+
7+
func getContainerName(name, allocID string) string {
8+
containerName := name + "-" + allocID
9+
return containerName
10+
}

0 commit comments

Comments
 (0)