diff options
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | GNUmakefile | 2 | ||||
-rw-r--r-- | main.go | 4 | ||||
-rw-r--r-- | nix2/driver.go (renamed from exec2/driver.go) | 90 | ||||
-rw-r--r-- | nix2/handle.go (renamed from exec2/handle.go) | 2 | ||||
-rwxr-xr-x | nix2/pull-upstream.sh (renamed from exec2/pull-upstream.sh) | 0 | ||||
-rw-r--r-- | nix2/state.go (renamed from exec2/state.go) | 2 |
7 files changed, 39 insertions, 65 deletions
@@ -1,2 +1,2 @@ -nomad-driver-exec2 -exec2-driver +nomad-driver-* +*-driver diff --git a/GNUmakefile b/GNUmakefile index 6d84e6b..fc9e222 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,4 +1,4 @@ -PLUGIN_BINARY=hello-driver +PLUGIN_BINARY=nix2-driver export GO111MODULE=on default: build @@ -1,7 +1,7 @@ package main import ( - "github.com/Alexis211/nomad-driver-exec2/exec2" + "github.com/Alexis211/nomad-driver-exec2/nix2" "github.com/hashicorp/go-hclog" "github.com/hashicorp/nomad/plugins" @@ -14,5 +14,5 @@ func main() { // factory returns a new instance of a nomad driver plugin func factory(log hclog.Logger) interface{} { - return exec2.NewPlugin(log) + return nix2.NewPlugin(log) } diff --git a/exec2/driver.go b/nix2/driver.go index 38d5415..c97efc5 100644 --- a/exec2/driver.go +++ b/nix2/driver.go @@ -1,4 +1,4 @@ -package exec2 +package nix2 import ( "context" @@ -28,7 +28,7 @@ import ( const ( // pluginName is the name of the plugin - pluginName = "exec2" + pluginName = "nix2" // fingerprintPeriod is the interval at which the driver will send fingerprint responses fingerprintPeriod = 30 * time.Second @@ -72,14 +72,9 @@ 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("{}"), + "allow_bind": hclspec.NewDefault( + hclspec.NewAttr("allow_bind", "bool", false), + hclspec.NewLiteral("true"), ), }) @@ -161,11 +156,8 @@ type Config struct { // 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"` + // AllowBind defines whether users may bind host directories + AllowBind bool `codec:"allow_bind"` } func (c *Config) validate() error { @@ -492,54 +484,36 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive } // 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{ - TaskPath: task, - HostPath: host, - Readonly: false, - PropagationMode: "private", + if d.config.AllowBind { + if driverConfig.Bind != nil { + for host, task := range driverConfig.Bind { + mount_config := drivers.MountConfig{ + TaskPath: task, + HostPath: host, + Readonly: false, + PropagationMode: "private", + } + d.logger.Info("adding RW mount from task spec", "mount_config", hclog.Fmt("%+v", mount_config)) + cfg.Mounts = append(cfg.Mounts, &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) } - } - if driverConfig.BindReadOnly != nil { - for host, task := range driverConfig.BindReadOnly { - mount_config := drivers.MountConfig{ - TaskPath: task, - HostPath: host, - Readonly: true, - PropagationMode: "private", + if driverConfig.BindReadOnly != nil { + for host, task := range driverConfig.BindReadOnly { + mount_config := drivers.MountConfig{ + TaskPath: task, + HostPath: host, + Readonly: true, + PropagationMode: "private", + } + d.logger.Info("adding RO mount from task spec", "mount_config", hclog.Fmt("%+v", mount_config)) + cfg.Mounts = append(cfg.Mounts, &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) + } + } else { + if len(driverConfig.Bind) > 0 || len(driverConfig.BindReadOnly) > 0 { + return nil, nil, fmt.Errorf("bind and bind_read_only are deactivated for the %s driver", pluginName) } } diff --git a/exec2/handle.go b/nix2/handle.go index edb3346..0e54f4e 100644 --- a/exec2/handle.go +++ b/nix2/handle.go @@ -1,4 +1,4 @@ -package exec2 +package nix2 import ( "context" diff --git a/exec2/pull-upstream.sh b/nix2/pull-upstream.sh index a797951..a797951 100755 --- a/exec2/pull-upstream.sh +++ b/nix2/pull-upstream.sh diff --git a/exec2/state.go b/nix2/state.go index 277e336..a846ea4 100644 --- a/exec2/state.go +++ b/nix2/state.go @@ -1,4 +1,4 @@ -package exec2 +package nix2 import ( "sync" |