summaryrefslogtreecommitdiff
path: root/pkg/spec/spec.go
diff options
context:
space:
mode:
authorPeter Hunt <pehunt@redhat.com>2019-08-06 08:35:59 -0400
committerPeter Hunt <pehunt@redhat.com>2019-08-07 08:44:08 -0400
commita87fb78dd1d7a99b84786364f83f423fdffe892e (patch)
tree10e2442ac94e12214b6b4617626827d92917283e /pkg/spec/spec.go
parent66ea32cbaf926d59fae3345b7e27a15050ab3afe (diff)
downloadpodman-a87fb78dd1d7a99b84786364f83f423fdffe892e.tar.gz
podman-a87fb78dd1d7a99b84786364f83f423fdffe892e.tar.bz2
podman-a87fb78dd1d7a99b84786364f83f423fdffe892e.zip
Properly share UTS namespaces in a pod
Sharing a UTS namespace means sharing the hostname. Fix situations where a container in a pod didn't properly share the hostname of the pod. Signed-off-by: Peter Hunt <pehunt@redhat.com>
Diffstat (limited to 'pkg/spec/spec.go')
-rw-r--r--pkg/spec/spec.go21
1 files changed, 17 insertions, 4 deletions
diff --git a/pkg/spec/spec.go b/pkg/spec/spec.go
index c94746767..c16696ffe 100644
--- a/pkg/spec/spec.go
+++ b/pkg/spec/spec.go
@@ -174,10 +174,20 @@ func (config *CreateConfig) createConfigToOCISpec(runtime *libpod.Runtime, userM
}
hostname := config.Hostname
- if hostname == "" && (config.NetMode.IsHost() || config.UtsMode.IsHost()) {
- hostname, err = os.Hostname()
- if err != nil {
- return nil, errors.Wrap(err, "unable to retrieve hostname")
+ if hostname == "" {
+ if utsCtrID := config.UtsMode.Container(); utsCtrID != "" {
+ utsCtr, err := runtime.GetContainer(utsCtrID)
+ if err != nil {
+ return nil, errors.Wrapf(err, "unable to retrieve hostname from dependency container %s", utsCtrID)
+ }
+ hostname = utsCtr.Hostname()
+ } else if config.NetMode.IsHost() || config.UtsMode.IsHost() {
+ hostname, err = os.Hostname()
+ if err != nil {
+ return nil, errors.Wrap(err, "unable to retrieve hostname of the host")
+ }
+ } else {
+ logrus.Debug("No hostname set; container's hostname will default to runtime default")
}
}
g.RemoveHostname()
@@ -606,6 +616,9 @@ func addUTSNS(config *CreateConfig, g *generate.Generator) error {
if utsMode.IsHost() {
return g.RemoveLinuxNamespace(string(spec.UTSNamespace))
}
+ if utsMode.IsContainer() {
+ logrus.Debug("using container utsmode")
+ }
return nil
}