diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-08-31 13:49:03 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-31 13:49:03 -0400 |
commit | 0c076dbce5fcdc3e1994df099db77c7d51a51dec (patch) | |
tree | 74d452debff1340f1279d0e08a613c05607af999 /test | |
parent | 3352e8b0e6bb77344a4470ef86b2d2dc6262a668 (diff) | |
parent | 9ec8a60eae8987f06d1971634c438586534d2987 (diff) | |
download | podman-0c076dbce5fcdc3e1994df099db77c7d51a51dec.tar.gz podman-0c076dbce5fcdc3e1994df099db77c7d51a51dec.tar.bz2 podman-0c076dbce5fcdc3e1994df099db77c7d51a51dec.zip |
Merge pull request #7496 from zhangguanzhang/play-kube-handle-hostAliases
handle play kube with pod.spec.hostAliases
Diffstat (limited to 'test')
-rw-r--r-- | test/e2e/play_kube_test.go | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go index 1379cb35d..121cea017 100644 --- a/test/e2e/play_kube_test.go +++ b/test/e2e/play_kube_test.go @@ -42,6 +42,14 @@ metadata: spec: hostname: {{ .Hostname }} + hostAliases: +{{ range .HostAliases }} + - hostnames: + {{ range .HostName }} + - {{ . }} + {{ end }} + ip: {{ .IP }} +{{ end }} containers: {{ with .Ctrs }} {{ range . }} @@ -249,16 +257,22 @@ func generateDeploymentKubeYaml(deployment *Deployment, fileName string) error { type Pod struct { Name string Hostname string + HostAliases []HostAlias Ctrs []*Ctr Volumes []*Volume Annotations map[string]string } +type HostAlias struct { + IP string + HostName []string +} + // getPod takes a list of podOptions and returns a pod with sane defaults // and the configured options // if no containers are added, it will add the default container func getPod(options ...podOption) *Pod { - p := Pod{defaultPodName, "", make([]*Ctr, 0), make([]*Volume, 0), make(map[string]string)} + p := Pod{defaultPodName, "", nil, make([]*Ctr, 0), make([]*Volume, 0), make(map[string]string)} for _, option := range options { option(&p) } @@ -276,6 +290,15 @@ func withHostname(h string) podOption { } } +func withHostAliases(ip string, host []string) podOption { + return func(pod *Pod) { + pod.HostAliases = append(pod.HostAliases, HostAlias{ + IP: ip, + HostName: host, + }) + } +} + func withCtr(c *Ctr) podOption { return func(pod *Pod) { pod.Ctrs = append(pod.Ctrs, c) @@ -597,6 +620,30 @@ var _ = Describe("Podman generate kube", func() { Expect(inspect.OutputToString()).To(Equal(hostname)) }) + It("podman play kube test HostAliases", func() { + pod := getPod(withHostAliases("192.168.1.2", []string{ + "test1.podman.io", + "test2.podman.io", + }), + withHostAliases("192.168.1.3", []string{ + "test3.podman.io", + "test4.podman.io", + }), + ) + err := generatePodKubeYaml(pod, kubeYaml) + Expect(err).To(BeNil()) + + kube := podmanTest.Podman([]string{"play", "kube", kubeYaml}) + kube.WaitWithDefaultTimeout() + Expect(kube.ExitCode()).To(Equal(0)) + + inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(pod), "--format", "{{ .HostConfig.ExtraHosts }}"}) + inspect.WaitWithDefaultTimeout() + Expect(inspect.ExitCode()).To(Equal(0)) + Expect(inspect.OutputToString()). + To(Equal("[test1.podman.io:192.168.1.2 test2.podman.io:192.168.1.2 test3.podman.io:192.168.1.3 test4.podman.io:192.168.1.3]")) + }) + It("podman play kube cap add", func() { capAdd := "CAP_SYS_ADMIN" ctr := getCtr(withCapAdd([]string{capAdd}), withCmd([]string{"cat", "/proc/self/status"}), withArg(nil)) |