mirror of https://github.com/containers/podman.git
libpod: set hostname from joined container
when joining a UTS namespace, take the hostname from the destination container. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
parent
d227d44fd6
commit
b69ba30b14
|
@ -385,6 +385,16 @@ func (c *Container) generateSpec(ctx context.Context) (*spec.Spec, error) {
|
||||||
g.AddLinuxGIDMapping(uint32(0), uint32(0), uint32(1))
|
g.AddLinuxGIDMapping(uint32(0), uint32(0), uint32(1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, i := range c.config.Spec.Linux.Namespaces {
|
||||||
|
if i.Type == spec.UTSNamespace {
|
||||||
|
hostname := c.Hostname()
|
||||||
|
g.SetHostname(hostname)
|
||||||
|
g.AddProcessEnv("HOSTNAME", hostname)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if c.config.UTSNsCtr != "" {
|
if c.config.UTSNsCtr != "" {
|
||||||
if err := c.addNamespaceContainer(&g, UTSNS, c.config.UTSNsCtr, spec.UTSNamespace); err != nil {
|
if err := c.addNamespaceContainer(&g, UTSNS, c.config.UTSNsCtr, spec.UTSNamespace); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -418,15 +428,6 @@ func (c *Container) generateSpec(ctx context.Context) (*spec.Spec, error) {
|
||||||
g.AddAnnotation(annotations.ContainerManager, annotations.ContainerManagerLibpod)
|
g.AddAnnotation(annotations.ContainerManager, annotations.ContainerManagerLibpod)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, i := range c.config.Spec.Linux.Namespaces {
|
|
||||||
if i.Type == spec.UTSNamespace {
|
|
||||||
hostname := c.Hostname()
|
|
||||||
g.SetHostname(hostname)
|
|
||||||
g.AddProcessEnv("HOSTNAME", hostname)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only add container environment variable if not already present
|
// Only add container environment variable if not already present
|
||||||
foundContainerEnv := false
|
foundContainerEnv := false
|
||||||
for _, env := range g.Config.Process.Env {
|
for _, env := range g.Config.Process.Env {
|
||||||
|
@ -583,6 +584,12 @@ func (c *Container) addNamespaceContainer(g *generate.Generator, ns LinuxNS, ctr
|
||||||
return errors.Wrapf(err, "error retrieving dependency %s of container %s from state", ctr, c.ID())
|
return errors.Wrapf(err, "error retrieving dependency %s of container %s from state", ctr, c.ID())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if specNS == spec.UTSNamespace {
|
||||||
|
hostname := nsCtr.Hostname()
|
||||||
|
g.SetHostname(hostname)
|
||||||
|
g.AddProcessEnv("HOSTNAME", hostname)
|
||||||
|
}
|
||||||
|
|
||||||
// TODO need unlocked version of this for use in pods
|
// TODO need unlocked version of this for use in pods
|
||||||
nsPath, err := nsCtr.NamespacePath(ns)
|
nsPath, err := nsCtr.NamespacePath(ns)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue