Skip to content

Commit caef7ec

Browse files
committed
Make containerd socket path configurable
1 parent 80b9be1 commit caef7ec

2 files changed

Lines changed: 24 additions & 17 deletions

File tree

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,14 @@ To interact with `images` and `containers` directly, you can use [`nerdctl`](htt
9191

9292
**Driver Config**
9393

94-
| Option | Type | Required | Default | Description |
95-
| :---: | :---: | :---: | :---: | :--- |
96-
| **enabled** | bool | no | true | Enable/Disable task driver. |
97-
| **containerd_runtime** | string | yes | N/A | Runtime for containerd e.g. `io.containerd.runc.v1` or `io.containerd.runc.v2`. |
98-
| **stats_interval** | string | no | 1s | Interval for collecting `TaskStats`. |
99-
| **allow_privileged** | bool | no | true | If set to `false`, driver will deny running privileged jobs. |
100-
| **auth** | block | no | N/A | Provide authentication for a private registry. See [Authentication](#authentication-private-registry) for more details. |
94+
| Option | Type | Required | Default | Description |
95+
|:----------------------:|:------:|:--------:|:---------------------------------:|:------------------------------------------------------------------------------------------------------------------------|
96+
| **enabled** | bool | no | true | Enable/Disable task driver. |
97+
| **containerd_address** | string | no | `/run/containerd/containerd.sock` | Path to containerd socket. |
98+
| **containerd_runtime** | string | yes | N/A | Runtime for containerd e.g. `io.containerd.runc.v1` or `io.containerd.runc.v2`. |
99+
| **stats_interval** | string | no | 1s | Interval for collecting `TaskStats`. |
100+
| **allow_privileged** | bool | no | true | If set to `false`, driver will deny running privileged jobs. |
101+
| **auth** | block | no | N/A | Provide authentication for a private registry. See [Authentication](#authentication-private-registry) for more details. |
101102

102103
**Task Config**
103104

containerd/driver.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package containerd
2020
import (
2121
"context"
2222
"fmt"
23+
"github.com/containerd/containerd/defaults"
2324
"syscall"
2425
"time"
2526

@@ -79,6 +80,10 @@ var (
7980
hclspec.NewAttr("enabled", "bool", false),
8081
hclspec.NewLiteral("true"),
8182
),
83+
"containerd_address": hclspec.NewDefault(
84+
hclspec.NewAttr("containerd_address", "string", false),
85+
hclspec.NewLiteral(defaults.DefaultAddress),
86+
),
8287
"containerd_runtime": hclspec.NewAttr("containerd_runtime", "string", true),
8388
"stats_interval": hclspec.NewAttr("stats_interval", "string", false),
8489
"allow_privileged": hclspec.NewDefault(
@@ -152,6 +157,7 @@ var (
152157
// Config contains configuration information for the plugin
153158
type Config struct {
154159
Enabled bool `codec:"enabled"`
160+
ContainerdAddress string `codec:"containerd_address"`
155161
ContainerdRuntime string `codec:"containerd_runtime"`
156162
StatsInterval string `codec:"stats_interval"`
157163
AllowPrivileged bool `codec:"allow_privileged"`
@@ -249,14 +255,6 @@ func NewPlugin(logger log.Logger) drivers.DriverPlugin {
249255
ctx, cancel := context.WithCancel(context.Background())
250256
logger = logger.Named(PluginName)
251257

252-
// This will create a new containerd client which will talk to
253-
// default containerd socket path.
254-
client, err := containerd.New("/run/containerd/containerd.sock")
255-
if err != nil {
256-
logger.Error("Error in creating containerd client", "err", err)
257-
return nil
258-
}
259-
260258
// Calls to containerd API are namespaced.
261259
// "nomad" is the namespace that will be used for all nomad-driver-containerd
262260
// related containerd API calls.
@@ -274,7 +272,6 @@ func NewPlugin(logger log.Logger) drivers.DriverPlugin {
274272
tasks: newTaskStore(),
275273
ctx: ctx,
276274
ctxContainerd: ctxContainerd,
277-
client: client,
278275
signalShutdown: cancel,
279276
logger: logger,
280277
}
@@ -324,12 +321,21 @@ func (d *Driver) ConfigSchema() (*hclspec.Spec, error) {
324321
// SetConfig is called by the client to pass the configuration for the plugin.
325322
func (d *Driver) SetConfig(cfg *base.Config) error {
326323
var config Config
324+
var err error
327325
if len(cfg.PluginConfig) != 0 {
328-
if err := base.MsgPackDecode(cfg.PluginConfig, &config); err != nil {
326+
if err = base.MsgPackDecode(cfg.PluginConfig, &config); err != nil {
329327
return err
330328
}
331329
}
332330

331+
// This will create a new containerd client which will talk to
332+
// default containerd socket path.
333+
d.client, err = containerd.New(config.ContainerdAddress)
334+
if err != nil {
335+
d.logger.Error("Error in creating containerd client", "err", err)
336+
return err
337+
}
338+
333339
// Save the configuration to the plugin
334340
d.config = &config
335341

0 commit comments

Comments
 (0)