aboutsummaryrefslogtreecommitdiff
path: root/test/e2e/play_kube_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'test/e2e/play_kube_test.go')
-rw-r--r--test/e2e/play_kube_test.go184
1 files changed, 183 insertions, 1 deletions
diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go
index 053e27126..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 . }}
@@ -94,6 +102,15 @@ spec:
{{ end }}
{{ end }}
{{ end }}
+{{ with .Volumes }}
+ volumes:
+ {{ range . }}
+ - name: {{ .Name }}
+ hostPath:
+ path: {{ .Path }}
+ type: {{ .Type }}
+ {{ end }}
+{{ end }}
status: {}
`
@@ -186,6 +203,7 @@ var (
defaultCtrArg = []string{"-d", "1.5"}
defaultCtrImage = ALPINE
defaultPodName = "testPod"
+ defaultVolName = "testVol"
defaultDeploymentName = "testDeployment"
seccompPwdEPERM = []byte(`{"defaultAction":"SCMP_ACT_ALLOW","syscalls":[{"name":"getcwd","action":"SCMP_ACT_ERRNO"}]}`)
)
@@ -239,15 +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(map[string]string)}
+ p := Pod{defaultPodName, "", nil, make([]*Ctr, 0), make([]*Volume, 0), make(map[string]string)}
for _, option := range options {
option(&p)
}
@@ -265,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)
@@ -277,6 +311,12 @@ func withAnnotation(k, v string) podOption {
}
}
+func withVolume(v *Volume) podOption {
+ return func(pod *Pod) {
+ pod.Volumes = append(pod.Volumes, v)
+ }
+}
+
// Deployment describes the options a kube yaml can be configured at deployment level
type Deployment struct {
Name string
@@ -412,6 +452,22 @@ func getCtrNameInPod(pod *Pod) string {
return fmt.Sprintf("%s-%s", pod.Name, defaultCtrName)
}
+type Volume struct {
+ Name string
+ Path string
+ Type string
+}
+
+// getVolume takes a type and a location for a volume
+// giving it a default name of volName
+func getVolume(vType, vPath string) *Volume {
+ return &Volume{
+ Name: defaultVolName,
+ Path: vPath,
+ Type: vType,
+ }
+}
+
var _ = Describe("Podman generate kube", func() {
var (
tempdir string
@@ -564,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))
@@ -853,4 +933,106 @@ spec:
Expect(inspect.ExitCode()).To(Equal(0))
Expect(inspect.OutputToString()).To(Equal("5000/tcp -> 127.0.0.100:5000"))
})
+
+ It("podman play kube test with non-existent empty HostPath type volume", func() {
+ hostPathLocation := filepath.Join(tempdir, "file")
+
+ pod := getPod(withVolume(getVolume(`""`, hostPathLocation)))
+ err := generatePodKubeYaml(pod, kubeYaml)
+ Expect(err).To(BeNil())
+
+ kube := podmanTest.Podman([]string{"play", "kube", kubeYaml})
+ kube.WaitWithDefaultTimeout()
+ Expect(kube.ExitCode()).NotTo(Equal(0))
+ })
+
+ It("podman play kube test with empty HostPath type volume", func() {
+ hostPathLocation := filepath.Join(tempdir, "file")
+ f, err := os.Create(hostPathLocation)
+ Expect(err).To(BeNil())
+ f.Close()
+
+ pod := getPod(withVolume(getVolume(`""`, hostPathLocation)))
+ err = generatePodKubeYaml(pod, kubeYaml)
+ Expect(err).To(BeNil())
+
+ kube := podmanTest.Podman([]string{"play", "kube", kubeYaml})
+ kube.WaitWithDefaultTimeout()
+ Expect(kube.ExitCode()).To(Equal(0))
+ })
+
+ It("podman play kube test with non-existent File HostPath type volume", func() {
+ hostPathLocation := filepath.Join(tempdir, "file")
+
+ pod := getPod(withVolume(getVolume("File", hostPathLocation)))
+ err := generatePodKubeYaml(pod, kubeYaml)
+ Expect(err).To(BeNil())
+
+ kube := podmanTest.Podman([]string{"play", "kube", kubeYaml})
+ kube.WaitWithDefaultTimeout()
+ Expect(kube.ExitCode()).NotTo(Equal(0))
+ })
+
+ It("podman play kube test with File HostPath type volume", func() {
+ hostPathLocation := filepath.Join(tempdir, "file")
+ f, err := os.Create(hostPathLocation)
+ Expect(err).To(BeNil())
+ f.Close()
+
+ pod := getPod(withVolume(getVolume("File", hostPathLocation)))
+ err = generatePodKubeYaml(pod, kubeYaml)
+ Expect(err).To(BeNil())
+
+ kube := podmanTest.Podman([]string{"play", "kube", kubeYaml})
+ kube.WaitWithDefaultTimeout()
+ Expect(kube.ExitCode()).To(Equal(0))
+ })
+
+ It("podman play kube test with FileOrCreate HostPath type volume", func() {
+ hostPathLocation := filepath.Join(tempdir, "file")
+
+ pod := getPod(withVolume(getVolume("FileOrCreate", hostPathLocation)))
+ err := generatePodKubeYaml(pod, kubeYaml)
+ Expect(err).To(BeNil())
+
+ kube := podmanTest.Podman([]string{"play", "kube", kubeYaml})
+ kube.WaitWithDefaultTimeout()
+ Expect(kube.ExitCode()).To(Equal(0))
+
+ // the file should have been created
+ _, err = os.Stat(hostPathLocation)
+ Expect(err).To(BeNil())
+ })
+
+ It("podman play kube test with DirectoryOrCreate HostPath type volume", func() {
+ hostPathLocation := filepath.Join(tempdir, "file")
+
+ pod := getPod(withVolume(getVolume("DirectoryOrCreate", hostPathLocation)))
+ err := generatePodKubeYaml(pod, kubeYaml)
+ Expect(err).To(BeNil())
+
+ kube := podmanTest.Podman([]string{"play", "kube", kubeYaml})
+ kube.WaitWithDefaultTimeout()
+ Expect(kube.ExitCode()).To(Equal(0))
+
+ // the file should have been created
+ st, err := os.Stat(hostPathLocation)
+ Expect(err).To(BeNil())
+ Expect(st.Mode().IsDir()).To(Equal(true))
+ })
+
+ It("podman play kube test with Socket HostPath type volume should fail if not socket", func() {
+ hostPathLocation := filepath.Join(tempdir, "file")
+ f, err := os.Create(hostPathLocation)
+ Expect(err).To(BeNil())
+ f.Close()
+
+ pod := getPod(withVolume(getVolume("Socket", hostPathLocation)))
+ err = generatePodKubeYaml(pod, kubeYaml)
+ Expect(err).To(BeNil())
+
+ kube := podmanTest.Podman([]string{"play", "kube", kubeYaml})
+ kube.WaitWithDefaultTimeout()
+ Expect(kube.ExitCode()).NotTo(Equal(0))
+ })
})