diff --git a/driver/driver.go b/driver/driver.go index 34603fb..280d1d0 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -71,6 +71,7 @@ var ( "mount_read_only": hclspec.NewAttr("mount_read_only", "list(string)", false), "extra_hosts": hclspec.NewAttr("extra_hosts", "list(string)", false), "attributes": hclspec.NewAttr("attributes", "list(string)", false), + "aliases": hclspec.NewAttr("aliases", "list(string)", false), }) // capabilities is returned by the Capabilities RPC and indicates what @@ -142,6 +143,7 @@ type TaskConfig struct { Copy []string `codec:"copy"` // Files in host to copy in, syntax: /path/to/host/file.ext:/destination/path/in/container/file.ext ExtraHosts []string `codec:"extra_hosts"` // ExtraHosts a list of hosts, given as host:IP, to be added to /etc/hosts Attributes []string `codec:"attributes"` // Pot attributes, syntax: Attribute:Value + Aliases []string `codec:"aliases"` // List of pot aliases } // TaskState is the state which is encoded in the handle returned in diff --git a/driver/pot.go b/driver/pot.go index 68974a0..d0cf623 100644 --- a/driver/pot.go +++ b/driver/pot.go @@ -36,6 +36,7 @@ type syexec struct { argvMem string argvEnv string argvExtraHosts string + argvAliases string argvStart []string argvStats []string argvLastRunStats []string @@ -306,6 +307,16 @@ func (s *syexec) createContainer(commandCfg *drivers.TaskConfig) error { return errors.New(string(message)) } + // Setting aliases for the pot + aliasesMessage := "Setting pot aliases: " + s.argvAliases + s.logger.Debug(aliasesMessage) + + _, err = exec.Command("sh", "-c", s.argvAliases).Output() + if err != nil { + message := "Error setting aliases for pot with err: " + err.Error() + return errors.New(string(message)) + } + //Set memory limit for pot message := "Setting memory soft limit on jail: " + s.argvMem s.logger.Debug(message) diff --git a/driver/prepare.go b/driver/prepare.go index 5a86622..180bea2 100644 --- a/driver/prepare.go +++ b/driver/prepare.go @@ -153,6 +153,13 @@ func prepareContainer(cfg *drivers.TaskConfig, taskCfg TaskConfig) (syexec, erro se.argvExtraHosts = hostCommand } + if len(taskCfg.Aliases) > 0 { + aliasesCommand := shellescape.Quote(potBIN) + " set-aliases -p " + shellescape.Quote(potName) + for _, alias := range taskCfg.Aliases { + aliasesCommand = aliasesCommand + " -A " + shellescape.Quote(alias) + } + se.argvAliases = aliasesCommand + } //Set soft memory limit memoryLimit := cfg.Resources.NomadResources.Memory.MemoryMB sMemoryLimit := strconv.FormatInt(memoryLimit, 10)