From 44e391271cb6a83739ff1be7b9f4eece3df459a0 Mon Sep 17 00:00:00 2001 From: ebarrios Date: Mon, 16 Dec 2019 17:56:57 +0100 Subject: [PATCH] Set command stanza to optional in the pot driver --- driver/driver.go | 12 +++++++++--- driver/prepare.go | 20 ++++++++++++++------ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/driver/driver.go b/driver/driver.go index 9c2e04e..2095eb4 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -54,7 +54,7 @@ var ( "image": hclspec.NewAttr("image", "string", true), "pot": hclspec.NewAttr("pot", "string", true), "tag": hclspec.NewAttr("tag", "string", true), - "command": hclspec.NewAttr("command", "string", true), + "command": hclspec.NewAttr("command", "string", false), "args": hclspec.NewAttr("args", "list(string)", false), "port_map": hclspec.NewAttr("port_map", "list(map(string))", false), "network_mode": hclspec.NewAttr("network_mode", "string", false), @@ -281,7 +281,10 @@ func (d *Driver) RecoverTask(handle *drivers.TaskHandle) error { return fmt.Errorf("failed to decode driver config in RESTORETASK: %v", err) }*/ - se := prepareContainer(handle.Config, driverConfig) + se, err := prepareContainer(handle.Config, driverConfig) + if err != nil { + return err + } se.logger = d.logger alive := se.checkContainerAlive(handle.Config) @@ -368,7 +371,10 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive handle := drivers.NewTaskHandle(taskHandleVersion) handle.Config = cfg - se := prepareContainer(cfg, driverConfig) + se, err := prepareContainer(cfg, driverConfig) + if err != nil { + return nil, nil, err + } se.logger = d.logger alive := se.checkContainerAlive(cfg) diff --git a/driver/prepare.go b/driver/prepare.go index 57926c6..ffe4ba8 100644 --- a/driver/prepare.go +++ b/driver/prepare.go @@ -1,6 +1,7 @@ package pot import ( + "errors" "fmt" "io" "io/ioutil" @@ -12,7 +13,7 @@ import ( ) // prepareContainer preloads the taskcnf into args to be passed to a execCmd -func prepareContainer(cfg *drivers.TaskConfig, taskCfg TaskConfig) syexec { +func prepareContainer(cfg *drivers.TaskConfig, taskCfg TaskConfig) (syexec, error) { argv := make([]string, 0, 50) var se syexec se.taskConfig = taskCfg @@ -28,14 +29,21 @@ func prepareContainer(cfg *drivers.TaskConfig, taskCfg TaskConfig) syexec { } if len(taskCfg.Args) > 0 { + if taskCfg.Command == "" { + err := errors.New("command can not be empty if arguments are provided") + fmt.Println("command can not be empty if arguments are provided") + return se, err + } + for _, arg := range taskCfg.Args { taskCfg.Command = taskCfg.Command + " " + arg } } - taskCfg.Command = "\"" + taskCfg.Command + "\"" - argv = append(argv, "-c", taskCfg.Command) - + if taskCfg.Command != "" { + taskCfg.Command = "\"" + taskCfg.Command + "\"" + argv = append(argv, "-c", taskCfg.Command) + } if taskCfg.NetworkMode != "" { argv = append(argv, "-N", taskCfg.NetworkMode) } else if len(taskCfg.PortMap) > 0 { @@ -54,7 +62,7 @@ func prepareContainer(cfg *drivers.TaskConfig, taskCfg TaskConfig) syexec { completeName := cfg.JobName + cfg.Name argv = append(argv, "-n", completeName, "-v") - se.argvCreate = append(argv, taskCfg.Args...) + se.argvCreate = argv potName := completeName + "_" + cfg.AllocID @@ -140,7 +148,7 @@ func prepareContainer(cfg *drivers.TaskConfig, taskCfg TaskConfig) syexec { argvStats = append(argvStats, "get-rss", "-p", potName, "-J") se.argvStats = argvStats - return se + return se, nil } type nopCloser struct {