Use node hostname in kube play when hostNetwork=true

When the hostNetwork option is set to true in the k8s yaml,
set the pod's hostname to the name of the machine/node as is
done in k8s. Also set the utsns to host.

Signed-off-by: Urvashi Mohnani <umohnani@redhat.com>
This commit is contained in:
Urvashi Mohnani
2023-10-17 11:27:24 -04:00
parent 0b0f128bfb
commit 936e30f68b
4 changed files with 101 additions and 0 deletions

View File

@@ -146,6 +146,7 @@ type PodCreateOptions struct {
VolumesFrom []string `json:"volumes_from,omitempty"`
SecurityOpt []string `json:"security_opt,omitempty"`
Sysctl []string `json:"sysctl,omitempty"`
Uts string `json:"uts,omitempty"`
}
// PodLogsOptions describes the options to extract pod logs.
@@ -362,6 +363,12 @@ func ToPodSpecGen(s specgen.PodSpecGenerator, p *PodCreateOptions) (*specgen.Pod
return nil, err
}
s.Ipc = out
out, err = specgen.ParseNamespace(p.Uts)
if err != nil {
return nil, err
}
s.UtsNs = out
s.Hostname = p.Hostname
s.ExitPolicy = p.ExitPolicy
s.Labels = p.Labels