hashicorp / nomad-driver-podman

A nomad task driver plugin for sandboxing workloads in podman containers
https://developer.hashicorp.com/nomad/plugins/drivers/podman
Mozilla Public License 2.0
226 stars 62 forks source link

driver: add support for configuring extra_hosts in podman tasks #255

Closed shoenig closed 1 year ago

shoenig commented 1 year ago

This PR adds support for setting extra_hosts on in podman task configuration, bringing the podman driver support up to par with the docker driver.

Closes #244

shoenig commented 1 year ago

Spot check,

job file

job "sleep" {
  group "group" {
    count = 1

    task "sleep" {
      driver = "podman"

      config {
        image = "docker.io/bash:5"
        args  = ["sleep", "infinity"]

        extra_hosts = ["test4.localhost:127.0.0.2", "test6.localhost:[::1]"]
      }

      resources {
        cores  = 2
        memory = 64
      }
    }
  }
}

exec into the container and cat /etc/hosts, see our extra hosts got added

➜ noamd alloc exec 28 /bin/sh
/ # cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 diablo

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
127.0.0.2 test4.localhost
[::1] test6.localhost
10.88.0.53      581de9968e4c sleep-28c28dd8-62e5-dfbc-6411-54101a77c90e
10.88.0.1 host.containers.internal