summaryrefslogtreecommitdiff
path: root/test/e2e
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2021-01-28 15:20:15 -0600
committerbaude <bbaude@redhat.com>2021-01-29 08:49:45 -0600
commitca0dd76bf3b98d1ebe25813a8b15361d58dc75ed (patch)
treee399fc29cf31d599f3af48e59875319424aa48fd /test/e2e
parent2ee034c1e6ddd9918b97ddea2fd3e6388ec8f60b (diff)
downloadpodman-ca0dd76bf3b98d1ebe25813a8b15361d58dc75ed.tar.gz
podman-ca0dd76bf3b98d1ebe25813a8b15361d58dc75ed.tar.bz2
podman-ca0dd76bf3b98d1ebe25813a8b15361d58dc75ed.zip
Honor custom DNS in play|generate kube
when creating kubernetes yaml from containers and pods, we should honor any custom dns settings the user provided. in the case of generate kube, these would be provided by --dns, --dns-search, and --dns-opt. if multiple containers are involved in the generate, the options will be cumulative and unique with the exception of dns-opt. when replaying a kube file that has kubernetes dns information, we now also add that information to the pod creation. the options for dnspolicy is not enabled as there seemed to be no direct correlation between kubernetes and podman. Fixes: #9132 Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'test/e2e')
-rw-r--r--test/e2e/generate_kube_test.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/test/e2e/generate_kube_test.go b/test/e2e/generate_kube_test.go
index 239817e6c..8800f9057 100644
--- a/test/e2e/generate_kube_test.go
+++ b/test/e2e/generate_kube_test.go
@@ -540,4 +540,67 @@ var _ = Describe("Podman generate kube", func() {
kube.WaitWithDefaultTimeout()
Expect(kube.ExitCode()).ToNot(Equal(0))
})
+
+ It("podman generate kube on a container with dns options", func() {
+ top := podmanTest.Podman([]string{"run", "-dt", "--name", "top", "--dns", "8.8.8.8", "--dns-search", "foobar.com", "--dns-opt", "color:blue", ALPINE, "top"})
+ top.WaitWithDefaultTimeout()
+ Expect(top.ExitCode()).To(BeZero())
+
+ kube := podmanTest.Podman([]string{"generate", "kube", "top"})
+ kube.WaitWithDefaultTimeout()
+ Expect(kube.ExitCode()).To(Equal(0))
+
+ pod := new(v1.Pod)
+ err := yaml.Unmarshal(kube.Out.Contents(), pod)
+ Expect(err).To(BeNil())
+
+ Expect(StringInSlice("8.8.8.8", pod.Spec.DNSConfig.Nameservers)).To(BeTrue())
+ Expect(StringInSlice("foobar.com", pod.Spec.DNSConfig.Searches)).To(BeTrue())
+ Expect(len(pod.Spec.DNSConfig.Options)).To(BeNumerically(">", 0))
+ Expect(pod.Spec.DNSConfig.Options[0].Name).To(Equal("color"))
+ Expect(*pod.Spec.DNSConfig.Options[0].Value).To(Equal("blue"))
+ })
+
+ It("podman generate kube multiple contianer dns servers and options are cumulative", func() {
+ top1 := podmanTest.Podman([]string{"run", "-dt", "--name", "top1", "--dns", "8.8.8.8", "--dns-search", "foobar.com", ALPINE, "top"})
+ top1.WaitWithDefaultTimeout()
+ Expect(top1.ExitCode()).To(BeZero())
+
+ top2 := podmanTest.Podman([]string{"run", "-dt", "--name", "top2", "--dns", "8.7.7.7", "--dns-search", "homer.com", ALPINE, "top"})
+ top2.WaitWithDefaultTimeout()
+ Expect(top2.ExitCode()).To(BeZero())
+
+ kube := podmanTest.Podman([]string{"generate", "kube", "top1", "top2"})
+ kube.WaitWithDefaultTimeout()
+ Expect(kube.ExitCode()).To(Equal(0))
+
+ pod := new(v1.Pod)
+ err := yaml.Unmarshal(kube.Out.Contents(), pod)
+ Expect(err).To(BeNil())
+
+ Expect(StringInSlice("8.8.8.8", pod.Spec.DNSConfig.Nameservers)).To(BeTrue())
+ Expect(StringInSlice("8.7.7.7", pod.Spec.DNSConfig.Nameservers)).To(BeTrue())
+ Expect(StringInSlice("foobar.com", pod.Spec.DNSConfig.Searches)).To(BeTrue())
+ Expect(StringInSlice("homer.com", pod.Spec.DNSConfig.Searches)).To(BeTrue())
+ })
+
+ It("podman generate kube on a pod with dns options", func() {
+ top := podmanTest.Podman([]string{"run", "--pod", "new:pod1", "-dt", "--name", "top", "--dns", "8.8.8.8", "--dns-search", "foobar.com", "--dns-opt", "color:blue", ALPINE, "top"})
+ top.WaitWithDefaultTimeout()
+ Expect(top.ExitCode()).To(BeZero())
+
+ kube := podmanTest.Podman([]string{"generate", "kube", "pod1"})
+ kube.WaitWithDefaultTimeout()
+ Expect(kube.ExitCode()).To(Equal(0))
+
+ pod := new(v1.Pod)
+ err := yaml.Unmarshal(kube.Out.Contents(), pod)
+ Expect(err).To(BeNil())
+
+ Expect(StringInSlice("8.8.8.8", pod.Spec.DNSConfig.Nameservers)).To(BeTrue())
+ Expect(StringInSlice("foobar.com", pod.Spec.DNSConfig.Searches)).To(BeTrue())
+ Expect(len(pod.Spec.DNSConfig.Options)).To(BeNumerically(">", 0))
+ Expect(pod.Spec.DNSConfig.Options[0].Name).To(Equal("color"))
+ Expect(*pod.Spec.DNSConfig.Options[0].Value).To(Equal("blue"))
+ })
})