aboutsummaryrefslogtreecommitdiff
path: root/exec2
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-11-28 18:30:33 +0100
committerAlex Auvolat <alex@adnab.me>2022-11-28 18:30:33 +0100
commit14bd8f2010c3a1f90c6d1297f47ebbf46ee87dde (patch)
treec3ed1e173f97c8650523afc160e66d0fb41c1d26 /exec2
parentcbde799457a8470cd64a09d10827577d005ca6f8 (diff)
downloadnomad-driver-nix2-14bd8f2010c3a1f90c6d1297f47ebbf46ee87dde.tar.gz
nomad-driver-nix2-14bd8f2010c3a1f90c6d1297f47ebbf46ee87dde.zip
Add support for bind mount declared for all jobs
Diffstat (limited to 'exec2')
-rw-r--r--exec2/driver.go47
1 files changed, 45 insertions, 2 deletions
diff --git a/exec2/driver.go b/exec2/driver.go
index b223faa..fb84f1a 100644
--- a/exec2/driver.go
+++ b/exec2/driver.go
@@ -71,6 +71,15 @@ var (
hclspec.NewAttr("allow_caps", "list(string)", false),
hclspec.NewLiteral(capabilities.HCLSpecLiteral),
),
+ // Default host directories to bind in tasks
+ "bind": hclspec.NewDefault(
+ hclspec.NewAttr("bind", "list(map(string))", false),
+ hclspec.NewLiteral("{}"),
+ ),
+ "bind_read_only": hclspec.NewDefault(
+ hclspec.NewAttr("bind_read_only", "list(map(string))", false),
+ hclspec.NewLiteral("{}"),
+ ),
})
// taskConfigSpec is the hcl specification for the driver config section of
@@ -147,6 +156,12 @@ type Config struct {
// AllowCaps configures which Linux Capabilities are enabled for tasks
// running on this node.
AllowCaps []string `codec:"allow_caps"`
+
+ // Paths to bind for read-write acess in all jobs
+ Bind hclutils.MapStrStr `codec:"bind"`
+
+ // Paths to bind for read-only acess in all jobs
+ BindReadOnly hclutils.MapStrStr `codec:"bind_read_only"`
}
func (c *Config) validate() error {
@@ -288,6 +303,7 @@ func (d *Driver) SetConfig(cfg *base.Config) error {
if err := config.validate(); err != nil {
return err
}
+ d.logger.Info("Got config", "driver_config", hclog.Fmt("%+v", config))
d.config = config
return nil
@@ -445,6 +461,33 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
cfg.Mounts = append(cfg.Mounts, dnsMount)
}
+ // Bind mounts specified in driver config
+ if d.config.Bind != nil {
+ for host, task := range d.config.Bind {
+ mount_config := drivers.MountConfig{
+ TaskPath: task,
+ HostPath: host,
+ Readonly: false,
+ PropagationMode: "private",
+ }
+ d.logger.Info("adding RW mount from driver config", "mount_config", hclog.Fmt("%+v", mount_config))
+ cfg.Mounts = append(cfg.Mounts, &mount_config)
+ }
+ }
+ if d.config.BindReadOnly != nil {
+ for host, task := range d.config.BindReadOnly {
+ mount_config := drivers.MountConfig{
+ TaskPath: task,
+ HostPath: host,
+ Readonly: true,
+ PropagationMode: "private",
+ }
+ d.logger.Info("adding RO mount from driver config", "mount_config", hclog.Fmt("%+v", mount_config))
+ cfg.Mounts = append(cfg.Mounts, &mount_config)
+ }
+ }
+
+ // Bind mounts specified in task config
if driverConfig.Bind != nil {
for host, task := range driverConfig.Bind {
mount_config := drivers.MountConfig{
@@ -453,7 +496,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
Readonly: false,
PropagationMode: "private",
}
- d.logger.Info("got mount (RW)", "mount_config", hclog.Fmt("%+v", mount_config))
+ d.logger.Info("adding RW mount from task spec", "mount_config", hclog.Fmt("%+v", mount_config))
cfg.Mounts = append(cfg.Mounts, &mount_config)
}
}
@@ -465,7 +508,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
Readonly: true,
PropagationMode: "private",
}
- d.logger.Info("got mount (RO)", "mount_config", hclog.Fmt("%+v", mount_config))
+ d.logger.Info("adding RO mount from task spec", "mount_config", hclog.Fmt("%+v", mount_config))
cfg.Mounts = append(cfg.Mounts, &mount_config)
}
}