summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorChen Zhiwei <zhiweik@gmail.com>2019-08-17 02:42:36 +0000
committerChen Zhiwei <zhiweik@gmail.com>2019-08-18 03:48:40 +0000
commit7aefc1ac33ba153f6177e9fe3c4da886de49a9e2 (patch)
treefdd2f01237c17263ea06655321696ac3f9f754e0 /libpod
parent8eab96ec3afdc04c02b5ea1c2067e4a36c14c783 (diff)
downloadpodman-7aefc1ac33ba153f6177e9fe3c4da886de49a9e2.tar.gz
podman-7aefc1ac33ba153f6177e9fe3c4da886de49a9e2.tar.bz2
podman-7aefc1ac33ba153f6177e9fe3c4da886de49a9e2.zip
Allow customizing pod hostname
* set hostname in pod yaml file * set --hostname in pod create command Signed-off-by: Chen Zhiwei <zhiweik@gmail.com>
Diffstat (limited to 'libpod')
-rw-r--r--libpod/options.go18
-rw-r--r--libpod/pod.go2
-rw-r--r--libpod/runtime_pod_infra_linux.go4
-rw-r--r--libpod/runtime_pod_linux.go4
4 files changed, 26 insertions, 2 deletions
diff --git a/libpod/options.go b/libpod/options.go
index 7fbd0016a..bce07f301 100644
--- a/libpod/options.go
+++ b/libpod/options.go
@@ -1488,6 +1488,24 @@ func WithPodName(name string) PodCreateOption {
}
}
+// WithPodHostname sets the hostname of the pod.
+func WithPodHostname(hostname string) PodCreateOption {
+ return func(pod *Pod) error {
+ if pod.valid {
+ return define.ErrPodFinalized
+ }
+
+ // Check the hostname against a regex
+ if !nameRegex.MatchString(hostname) {
+ return regexError
+ }
+
+ pod.config.Hostname = hostname
+
+ return nil
+ }
+}
+
// WithPodLabels sets the labels of a pod.
func WithPodLabels(labels map[string]string) PodCreateOption {
return func(pod *Pod) error {
diff --git a/libpod/pod.go b/libpod/pod.go
index 60626bfd7..3b9bb9c60 100644
--- a/libpod/pod.go
+++ b/libpod/pod.go
@@ -36,6 +36,8 @@ type PodConfig struct {
// Namespace the pod is in
Namespace string `json:"namespace,omitempty"`
+ Hostname string `json:"hostname,omitempty"`
+
// Labels contains labels applied to the pod
Labels map[string]string `json:"labels"`
// CgroupParent contains the pod's CGroup parent
diff --git a/libpod/runtime_pod_infra_linux.go b/libpod/runtime_pod_infra_linux.go
index 24651099f..7cfce8919 100644
--- a/libpod/runtime_pod_infra_linux.go
+++ b/libpod/runtime_pod_infra_linux.go
@@ -30,8 +30,8 @@ func (r *Runtime) makeInfraContainer(ctx context.Context, p *Pod, imgName, imgID
return nil, err
}
- // Set Pod hostname as Pod name
- g.Config.Hostname = p.config.Name
+ // Set Pod hostname
+ g.Config.Hostname = p.config.Hostname
isRootless := rootless.IsRootless()
diff --git a/libpod/runtime_pod_linux.go b/libpod/runtime_pod_linux.go
index f38e6e7c1..073c5054d 100644
--- a/libpod/runtime_pod_linux.go
+++ b/libpod/runtime_pod_linux.go
@@ -52,6 +52,10 @@ func (r *Runtime) NewPod(ctx context.Context, options ...PodCreateOption) (_ *Po
pod.config.Name = name
}
+ if pod.config.Hostname == "" {
+ pod.config.Hostname = pod.config.Name
+ }
+
// Allocate a lock for the pod
lock, err := r.lockManager.AllocateLock()
if err != nil {