Skip to content

Commit

Permalink
Merge pull request #23868 from toadstule/quadlet-pod-dns
Browse files Browse the repository at this point in the history
Add DNS, DNSOption and DNSSearch to quadlet pod
  • Loading branch information
openshift-merge-bot[bot] committed Sep 5, 2024
2 parents ba7d4ed + 15bde1a commit 8578fdd
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 1 deletion.
23 changes: 22 additions & 1 deletion docs/source/markdown/podman-systemd.unit.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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.
Expand Down
18 changes: 18 additions & 0 deletions pkg/systemd/quadlet/quadlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/quadlet/dns-option.pod
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions test/e2e/quadlet/dns-search.pod
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions test/e2e/quadlet/dns.pod
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions test/e2e/quadlet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

1 comment on commit 8578fdd

@packit-as-a-service
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

podman-next COPR build failed. @containers/packit-build please check.

Please sign in to comment.