From 0502b790bcafe0b87ea77290559b0c259586895c Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Thu, 11 Mar 2021 07:28:55 +0100 Subject: [PATCH] config: added tty option (#86) --- CHANGELOG.md | 1 + README.md | 3 +++ config.go | 18 ++++++++++-------- driver.go | 1 + driver_test.go | 9 +++++++++ 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da768655..45b69ee1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## Unreleased +* config: Added tty option * config: Support for sysctl configuration [[GH-82](https://github.com/hashicorp/nomad-driver-podman/issues/82)] * config: Fixed a bug where we always pulled an image if image name has a transport prefix [[GH-88](https://github.com/hashicorp/nomad-driver-podman/pull/88)] diff --git a/README.md b/README.md index e5db9fc5..b01de37c 100644 --- a/README.md +++ b/README.md @@ -287,6 +287,9 @@ config { } ``` +* **tty** - (Optional) true or false (default). Allocate a pseudo-TTY for the container. + + ## Example job ``` diff --git a/config.go b/config.go index 822ad5c7..7810a7a0 100644 --- a/config.go +++ b/config.go @@ -58,6 +58,7 @@ var ( "ports": hclspec.NewAttr("ports", "list(string)", false), "sysctl": hclspec.NewAttr("sysctl", "list(map(string))", false), "tmpfs": hclspec.NewAttr("tmpfs", "list(string)", false), + "tty": hclspec.NewAttr("tty", "bool", false), "volumes": hclspec.NewAttr("volumes", "list(string)", false), }) ) @@ -83,24 +84,25 @@ type PluginConfig struct { // TaskConfig is the driver configuration of a task within a job type TaskConfig struct { + Args []string `codec:"args"` + Ports []string `codec:"ports"` + Tmpfs []string `codec:"tmpfs"` + Volumes []string `codec:"volumes"` + CapAdd []string `codec:"cap_add"` + CapDrop []string `codec:"cap_drop"` + Dns []string `codec:"dns"` Command string `codec:"command"` Entrypoint string `codec:"entrypoint"` - Args []string `codec:"args"` WorkingDir string `codec:"working_dir"` Hostname string `codec:"hostname"` Image string `codec:"image"` - Init bool `codec:"init"` InitPath string `codec:"init_path"` MemoryReservation string `codec:"memory_reservation"` MemorySwap string `codec:"memory_swap"` NetworkMode string `codec:"network_mode"` MemorySwappiness int64 `codec:"memory_swappiness"` PortMap hclutils.MapStrInt `codec:"port_map"` - Ports []string `codec:"ports"` Sysctl hclutils.MapStrStr `codec:"sysctl"` - Tmpfs []string `codec:"tmpfs"` - Volumes []string `codec:"volumes"` - CapAdd []string `codec:"cap_add"` - CapDrop []string `codec:"cap_drop"` - Dns []string `codec:"dns"` + Init bool `codec:"init"` + Tty bool `codec:"tty"` } diff --git a/driver.go b/driver.go index a49534a6..72027929 100644 --- a/driver.go +++ b/driver.go @@ -361,6 +361,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive createOpts.ContainerBasicConfig.Env = cfg.Env createOpts.ContainerBasicConfig.Hostname = driverConfig.Hostname createOpts.ContainerBasicConfig.Sysctl = driverConfig.Sysctl + createOpts.ContainerBasicConfig.Terminal = driverConfig.Tty createOpts.ContainerBasicConfig.LogConfiguration.Path = cfg.StdoutPath diff --git a/driver_test.go b/driver_test.go index 47c53ccd..68b11c0a 100644 --- a/driver_test.go +++ b/driver_test.go @@ -1130,6 +1130,15 @@ func TestPodmanDriver_Caps(t *testing.T) { require.NotContains(t, inspectData.EffectiveCaps, "CAP_CHOWN") } +// check enabled tty option +func TestPodmanDriver_Tty(t *testing.T) { + taskCfg := newTaskConfig("", busyboxLongRunningCmd) + taskCfg.Tty = true + inspectData := startDestroyInspect(t, taskCfg, "tty") + + require.True(t, inspectData.Config.Tty) +} + // check dns server configuration func TestPodmanDriver_Dns(t *testing.T) { if !tu.IsCI() {