Skip to content

Commit

Permalink
bsdpot#55 adding aliases as pot driver attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
RP committed Apr 30, 2024
1 parent ac537ed commit a14f0ef
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions driver/pot.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type syexec struct {
argvMem string
argvEnv string
argvExtraHosts string
argvAliases string
argvStart []string
argvStats []string
argvLastRunStats []string
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions driver/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a14f0ef

Please sign in to comment.