Skip to content

Commit ebbd7f3

Browse files
Merge pull request #2254 from gtjoseph/main-netavark-hostname
Allow Podman to send the container's hostname to Netavark
2 parents 6ed8cc7 + 2a3e1c1 commit ebbd7f3

File tree

7 files changed

+38
-1
lines changed

7 files changed

+38
-1
lines changed

docs/containers.conf.5.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@ Options are:
124124
`private` Create private Cgroup Namespace for the container.
125125
`host` Share host Cgroup Namespace with the container.
126126

127+
**container_name_as_hostname**=true|false
128+
129+
When no hostname is set for a container, use the container's name, with
130+
characters not valid for a hostname removed, as the hostname instead of
131+
the first 12 characters of the container's ID. Containers not running
132+
in a private UTS namespace will have their hostname set to the host's
133+
hostname regardless of this setting.
134+
135+
Default is false.
136+
127137
**default_capabilities**=[]
128138

129139
List of default capabilities for containers.

libnetwork/types/network.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ type PerNetworkOptions struct {
277277
type NetworkOptions struct {
278278
// ContainerID is the container id, used for iptables comments and ipam allocation.
279279
ContainerID string `json:"container_id"`
280-
// ContainerName is the container name, used as dns name.
280+
// ContainerName is the container name.
281281
ContainerName string `json:"container_name"`
282282
// PortMappings contains the port mappings for this container
283283
PortMappings []PortMapping `json:"port_mappings,omitempty"`
@@ -287,6 +287,8 @@ type NetworkOptions struct {
287287
// List of custom DNS server for podman's DNS resolver.
288288
// Priority order will be kept as defined by user in the configuration.
289289
DNSServers []string `json:"dns_servers,omitempty"`
290+
// ContainerHostname is the configured DNS hostname of the container.
291+
ContainerHostname string `json:"container_hostname"`
290292
}
291293

292294
// PortMapping is one or more ports that will be mapped into the container.

pkg/config/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ type ContainersConfig struct {
9696
// "memory.high=1073741824" sets the memory.high limit to 1GB.
9797
CgroupConf attributedstring.Slice `toml:"cgroup_conf,omitempty"`
9898

99+
// When no hostname is set for a container, use the container's name, with
100+
// characters not valid for a hostname removed, as the hostname instead of
101+
// the first 12 characters of the container's ID. Containers not running
102+
// in a private UTS namespace will have their hostname set to the host's
103+
// hostname regardless of this setting.
104+
ContainerNameAsHostName bool `toml:"container_name_as_hostname,omitempty"`
105+
99106
// Capabilities to add to all containers.
100107
DefaultCapabilities attributedstring.Slice `toml:"default_capabilities,omitempty"`
101108

pkg/config/config_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ image_copy_tmp_dir="storage"`
215215
// prior to reading local config, shows hard coded defaults
216216
gomega.Expect(defaultConfig.Containers.HTTPProxy).To(gomega.BeTrue())
217217
gomega.Expect(defaultConfig.Engine.HealthcheckEvents).To(gomega.BeTrue())
218+
gomega.Expect(defaultConfig.Containers.ContainerNameAsHostName).To(gomega.BeFalse())
218219

219220
err := readConfigFromFile("testdata/containers_default.conf", defaultConfig, false)
220221

@@ -322,6 +323,7 @@ image_copy_tmp_dir="storage"`
322323
// Then
323324
gomega.Expect(err).ToNot(gomega.HaveOccurred())
324325
gomega.Expect(defaultConfig.Engine.CgroupManager).To(gomega.Equal("systemd"))
326+
gomega.Expect(defaultConfig.Containers.ContainerNameAsHostName).To(gomega.BeTrue())
325327
gomega.Expect(defaultConfig.Containers.Env.Get()).To(gomega.BeEquivalentTo(envs))
326328
gomega.Expect(defaultConfig.Containers.Mounts.Get()).To(gomega.BeEquivalentTo(mounts))
327329
gomega.Expect(defaultConfig.Containers.PidsLimit).To(gomega.BeEquivalentTo(2048))

pkg/config/containers.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@
5858
#
5959
#cgroups = "enabled"
6060

61+
# When no hostname is set for a container, use the container's name, with
62+
# characters not valid for a hostname removed, as the hostname instead of
63+
# the first 12 characters of the container's ID. Containers not running
64+
# in a private UTS namespace will have their hostname set to the host's
65+
# hostname regardless of this setting.
66+
#
67+
#container_name_as_hostname = false
68+
6169
# List of default capabilities for containers. If it is empty or commented out,
6270
# the default capabilities defined in the container engine will be added.
6371
#

pkg/config/containers.conf-freebsd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
#
3030
#base_hosts_file = ""
3131

32+
# When no hostname is set for a container, use the container's name, with
33+
# characters not valid for a hostname removed, as the hostname instead of
34+
# the first 12 characters of the container's ID.
35+
#
36+
#container_name_as_hostname = false
37+
3238
# The database backend of Podman. Supported values are "" (default), "boltdb"
3339
# and "sqlite". An empty value means it will check whenever a boltdb already
3440
# exists and use it when it does, otherwise it will use sqlite as default

pkg/config/testdata/containers_default.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ apparmor_profile = "container-default"
2323

2424
base_hosts_file = "/etc/hosts2"
2525

26+
container_name_as_hostname = true
27+
2628
# List of default capabilities for containers. If it is empty or commented out,
2729
# only the capabilities defined in the containers json file by the user/kube
2830
# will be added.

0 commit comments

Comments
 (0)