From 15bde1abdb00d5aa00c1e9d92802d99ddc13d4a0 Mon Sep 17 00:00:00 2001 From: Steve Jibson Date: Wed, 4 Sep 2024 11:31:32 -0600 Subject: [PATCH] Add DNS, DNSOption and DNSSearch to quadlet pod Signed-off-by: Steve Jibson --- docs/source/markdown/podman-systemd.unit.5.md | 23 ++++++++++++++++++- pkg/systemd/quadlet/quadlet.go | 18 +++++++++++++++ test/e2e/quadlet/dns-option.pod | 6 +++++ test/e2e/quadlet/dns-search.pod | 6 +++++ test/e2e/quadlet/dns.pod | 6 +++++ test/e2e/quadlet_test.go | 3 +++ 6 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 test/e2e/quadlet/dns-option.pod create mode 100644 test/e2e/quadlet/dns-search.pod create mode 100644 test/e2e/quadlet/dns.pod diff --git a/docs/source/markdown/podman-systemd.unit.5.md b/docs/source/markdown/podman-systemd.unit.5.md index db6f79af2d..846fdb97ba 100644 --- a/docs/source/markdown/podman-systemd.unit.5.md +++ b/docs/source/markdown/podman-systemd.unit.5.md @@ -892,7 +892,10 @@ Valid options for `[Pod]` are listed below: |-------------------------------------|----------------------------------------| | AddHost=hostname:192.168.10.11 | --add-host=hostname:192.168.10.11 | | ContainersConfModule=/etc/nvd\.conf | --module=/etc/nvd\.conf | -| GIDMap=0:10000:10 | --gidmap=0:10000:10 | +| DNS=192.168.55.1 | --dns=192.168.55.1 | +| DNSOption=ndots:1 | --dns-option=ndots:1 | +| DNSSearch=foo.com | --dns-search=foo.com | +| GIDMap=0:10000:10 | --gidmap=0:10000:10 | | GlobalArgs=--log-level=debug | --log-level=debug | | IP=192.5.0.1 | --ip 192.5.0.1 | | IP6=2001:db8::1 | --ip6 2001:db8::1 | @@ -924,6 +927,24 @@ Load the specified containers.conf(5) module. Equivalent to the Podman `--module This key can be listed multiple times. +### `DNS=` + +Set network-scoped DNS resolver/nameserver for containers in this pod. + +This key can be listed multiple times. + +### `DNSOption=` + +Set custom DNS options. + +This key can be listed multiple times. + +### `DNSSearch=` + +Set custom DNS search domains. Use **DNSSearch=.** to remove the search domain. + +This key can be listed multiple times. + ### `GIDMap=` Create the pod in a new user namespace using the supplied GID mapping. diff --git a/pkg/systemd/quadlet/quadlet.go b/pkg/systemd/quadlet/quadlet.go index 57b79be2d2..092256ec35 100644 --- a/pkg/systemd/quadlet/quadlet.go +++ b/pkg/systemd/quadlet/quadlet.go @@ -385,6 +385,9 @@ var ( supportedPodKeys = map[string]bool{ KeyAddHost: true, KeyContainersConfModule: true, + KeyDNS: true, + KeyDNSOption: true, + KeyDNSSearch: true, KeyGIDMap: true, KeyGlobalArgs: true, KeyIP: true, @@ -1700,6 +1703,21 @@ func ConvertPod(podUnit *parser.UnitFile, name string, unitsInfoMap map[string]* execStartPre.addf("--infra-name=%s-infra", podName) execStartPre.addf("--name=%s", podName) + dns := podUnit.LookupAll(PodGroup, KeyDNS) + for _, ipAddr := range dns { + execStartPre.addf("--dns=%s", ipAddr) + } + + dnsOptions := podUnit.LookupAll(PodGroup, KeyDNSOption) + for _, dnsOption := range dnsOptions { + execStartPre.addf("--dns-option=%s", dnsOption) + } + + dnsSearches := podUnit.LookupAll(PodGroup, KeyDNSSearch) + for _, dnsSearch := range dnsSearches { + execStartPre.addf("--dns-search=%s", dnsSearch) + } + ip, ok := podUnit.Lookup(PodGroup, KeyIP) if ok && len(ip) > 0 { execStartPre.addf("--ip=%s", ip) diff --git a/test/e2e/quadlet/dns-option.pod b/test/e2e/quadlet/dns-option.pod new file mode 100644 index 0000000000..05ceddcf8c --- /dev/null +++ b/test/e2e/quadlet/dns-option.pod @@ -0,0 +1,6 @@ +## assert-podman-pre-args "--dns-option=ndots:1" +## assert-podman-pre-args "--dns-option=color:blue" + +[Pod] +DNSOption=ndots:1 +DNSOption=color:blue diff --git a/test/e2e/quadlet/dns-search.pod b/test/e2e/quadlet/dns-search.pod new file mode 100644 index 0000000000..fb3aae6521 --- /dev/null +++ b/test/e2e/quadlet/dns-search.pod @@ -0,0 +1,6 @@ +## assert-podman-pre-args "--dns-search=foo.com" +## assert-podman-pre-args "--dns-search=bar.com" + +[Pod] +DNSSearch=foo.com +DNSSearch=bar.com diff --git a/test/e2e/quadlet/dns.pod b/test/e2e/quadlet/dns.pod new file mode 100644 index 0000000000..965dd32a42 --- /dev/null +++ b/test/e2e/quadlet/dns.pod @@ -0,0 +1,6 @@ +## assert-podman-pre-args "--dns=8.7.7.7" +## assert-podman-pre-args "--dns=8.8.8.8" + +[Pod] +DNS=8.7.7.7 +DNS=8.8.8.8 diff --git a/test/e2e/quadlet_test.go b/test/e2e/quadlet_test.go index 639d06457e..51897716ed 100644 --- a/test/e2e/quadlet_test.go +++ b/test/e2e/quadlet_test.go @@ -1002,6 +1002,9 @@ BOGUS=foo Entry("Build - Variant Key", "variant.build"), Entry("Pod - Basic", "basic.pod"), + Entry("Pod - DNS", "dns.pod"), + Entry("Pod - DNS Option", "dns-option.pod"), + Entry("Pod - DNS Search", "dns-search.pod"), Entry("Pod - Host", "host.pod"), Entry("Pod - IP", "ip.pod"), Entry("Pod - Name", "name.pod"),