From 7aefc1ac33ba153f6177e9fe3c4da886de49a9e2 Mon Sep 17 00:00:00 2001
From: Chen Zhiwei <zhiweik@gmail.com>
Date: Sat, 17 Aug 2019 02:42:36 +0000
Subject: Allow customizing pod hostname

* set hostname in pod yaml file
* set --hostname in pod create command

Signed-off-by: Chen Zhiwei <zhiweik@gmail.com>
---
 pkg/adapter/pods.go | 10 ++++++++++
 1 file changed, 10 insertions(+)

(limited to 'pkg/adapter')

diff --git a/pkg/adapter/pods.go b/pkg/adapter/pods.go
index 2743dfdc6..87092b458 100644
--- a/pkg/adapter/pods.go
+++ b/pkg/adapter/pods.go
@@ -255,6 +255,10 @@ func (r *LocalRuntime) CreatePod(ctx context.Context, cli *cliconfig.PodCreateVa
 		options = append(options, libpod.WithPodName(cli.Name))
 	}
 
+	if cli.Flag("hostname").Changed {
+		options = append(options, libpod.WithPodHostname(cli.Hostname))
+	}
+
 	if cli.Infra {
 		options = append(options, libpod.WithInfraContainer())
 		nsOptions, err := shared.GetNamespaceOptions(strings.Split(cli.Share, ","))
@@ -475,6 +479,12 @@ func (r *LocalRuntime) PlayKubeYAML(ctx context.Context, c *cliconfig.KubePlayVa
 	podOptions = append(podOptions, libpod.WithPodName(podName))
 	// TODO for now we just used the default kernel namespaces; we need to add/subtract this from yaml
 
+	hostname := podYAML.Spec.Hostname
+	if hostname == "" {
+		hostname = podName
+	}
+	podOptions = append(podOptions, libpod.WithPodHostname(hostname))
+
 	nsOptions, err := shared.GetNamespaceOptions(strings.Split(shared.DefaultKernelNamespaces, ","))
 	if err != nil {
 		return nil, err
-- 
cgit v1.2.3-54-g00ecf