mirror of
https://github.com/containers/podman.git
synced 2025-10-20 12:43:58 +08:00
Ensure that containers in pods properly set hostname
When we moved to the new Namespace types in Specgen, we made a distinction between taking a namespace from a pod, and taking it from another container. Due to this new distinction, some code that previously worked for both `--pod=$ID` and `--uts=container:$ID` has accidentally become conditional on only the latter case. This happened for Hostname - we weren't properly setting it in cases where the container joined a pod. Fortunately, this is an easy fix once we know to check the condition. Also, ensure that `podman pod inspect` actually prints hostname. Fixes #6494 Signed-off-by: Matthew Heon <matthew.heon@pm.me>
This commit is contained in:
@ -171,6 +171,11 @@ func (p *Pod) SharesCgroup() bool {
|
|||||||
return p.config.UsePodCgroupNS
|
return p.config.UsePodCgroupNS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hostname returns the hostname of the pod.
|
||||||
|
func (p *Pod) Hostname() string {
|
||||||
|
return p.config.Hostname
|
||||||
|
}
|
||||||
|
|
||||||
// CgroupPath returns the path to the pod's CGroup
|
// CgroupPath returns the path to the pod's CGroup
|
||||||
func (p *Pod) CgroupPath() (string, error) {
|
func (p *Pod) CgroupPath() (string, error) {
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
|
@ -490,7 +490,7 @@ func (p *Pod) Inspect() (*define.InspectPodData, error) {
|
|||||||
Namespace: p.Namespace(),
|
Namespace: p.Namespace(),
|
||||||
Created: p.CreatedTime(),
|
Created: p.CreatedTime(),
|
||||||
State: podState,
|
State: podState,
|
||||||
Hostname: "",
|
Hostname: p.config.Hostname,
|
||||||
Labels: p.Labels(),
|
Labels: p.Labels(),
|
||||||
CreateCgroup: false,
|
CreateCgroup: false,
|
||||||
CgroupParent: p.CgroupParent(),
|
CgroupParent: p.CgroupParent(),
|
||||||
|
@ -114,7 +114,7 @@ func MakeContainer(ctx context.Context, rt *libpod.Runtime, s *specgen.SpecGener
|
|||||||
}
|
}
|
||||||
options = append(options, libpod.WithExitCommand(exitCommandArgs))
|
options = append(options, libpod.WithExitCommand(exitCommandArgs))
|
||||||
|
|
||||||
runtimeSpec, err := SpecGenToOCI(ctx, s, rt, rtc, newImage, finalMounts)
|
runtimeSpec, err := SpecGenToOCI(ctx, s, rt, rtc, newImage, finalMounts, pod)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -265,7 +265,7 @@ func GenerateNamespaceOptions(ctx context.Context, s *specgen.SpecGenerator, rt
|
|||||||
return toReturn, nil
|
return toReturn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func specConfigureNamespaces(s *specgen.SpecGenerator, g *generate.Generator, rt *libpod.Runtime) error {
|
func specConfigureNamespaces(s *specgen.SpecGenerator, g *generate.Generator, rt *libpod.Runtime, pod *libpod.Pod) error {
|
||||||
// PID
|
// PID
|
||||||
switch s.PidNS.NSMode {
|
switch s.PidNS.NSMode {
|
||||||
case specgen.Path:
|
case specgen.Path:
|
||||||
@ -326,6 +326,8 @@ func specConfigureNamespaces(s *specgen.SpecGenerator, g *generate.Generator, rt
|
|||||||
hostname := s.Hostname
|
hostname := s.Hostname
|
||||||
if hostname == "" {
|
if hostname == "" {
|
||||||
switch {
|
switch {
|
||||||
|
case s.UtsNS.NSMode == specgen.FromPod:
|
||||||
|
hostname = pod.Hostname()
|
||||||
case s.UtsNS.NSMode == specgen.FromContainer:
|
case s.UtsNS.NSMode == specgen.FromContainer:
|
||||||
utsCtr, err := rt.LookupContainer(s.UtsNS.Value)
|
utsCtr, err := rt.LookupContainer(s.UtsNS.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -118,7 +118,7 @@ func makeCommand(ctx context.Context, s *specgen.SpecGenerator, img *image.Image
|
|||||||
return finalCommand, nil
|
return finalCommand, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func SpecGenToOCI(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runtime, rtc *config.Config, newImage *image.Image, mounts []spec.Mount) (*spec.Spec, error) {
|
func SpecGenToOCI(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runtime, rtc *config.Config, newImage *image.Image, mounts []spec.Mount, pod *libpod.Pod) (*spec.Spec, error) {
|
||||||
var (
|
var (
|
||||||
inUserNS bool
|
inUserNS bool
|
||||||
)
|
)
|
||||||
@ -300,7 +300,7 @@ func SpecGenToOCI(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runt
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NAMESPACES
|
// NAMESPACES
|
||||||
if err := specConfigureNamespaces(s, &g, rt); err != nil {
|
if err := specConfigureNamespaces(s, &g, rt, pod); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
configSpec := g.Config
|
configSpec := g.Config
|
||||||
|
Reference in New Issue
Block a user