diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-12-03 14:54:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-03 14:54:47 +0100 |
commit | dd109daa45bafc85487aa2e627202d23b5c76021 (patch) | |
tree | b627ec36853c7cf40b5202c506c367f332c4d31b /test/e2e/play_kube_test.go | |
parent | 999fe0d89355498c1bc77efb8dfc50c5f0bb0efa (diff) | |
parent | 7d331d35ddf5e511bd474505b675191d3f949dc0 (diff) | |
download | podman-dd109daa45bafc85487aa2e627202d23b5c76021.tar.gz podman-dd109daa45bafc85487aa2e627202d23b5c76021.tar.bz2 podman-dd109daa45bafc85487aa2e627202d23b5c76021.zip |
Merge pull request #12440 from umohnani8/cm
Add support for configmap volumes to play kube
Diffstat (limited to 'test/e2e/play_kube_test.go')
-rw-r--r-- | test/e2e/play_kube_test.go | 116 |
1 files changed, 109 insertions, 7 deletions
diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go index 82b543151..96ad2954c 100644 --- a/test/e2e/play_kube_test.go +++ b/test/e2e/play_kube_test.go @@ -380,6 +380,18 @@ spec: persistentVolumeClaim: claimName: {{ .PersistentVolumeClaim.ClaimName }} {{- end }} + {{- if (eq .VolumeType "ConfigMap") }} + configMap: + name: {{ .ConfigMap.Name }} + optional: {{ .ConfigMap.Optional }} + {{- with .ConfigMap.Items }} + items: + {{- range . }} + - key: {{ .key }} + path: {{ .path }} + {{- end }} + {{- end }} + {{- end }} {{ end }} {{ end }} status: {} @@ -619,14 +631,14 @@ func createSecret(podmanTest *PodmanTestIntegration, name string, value []byte) Expect(secret).Should(Exit(0)) } -// ConfigMap describes the options a kube yaml can be configured at configmap level -type ConfigMap struct { +// CM describes the options a kube yaml can be configured at configmap level +type CM struct { Name string Data map[string]string } -func getConfigMap(options ...configMapOption) *ConfigMap { - cm := ConfigMap{ +func getConfigMap(options ...configMapOption) *CM { + cm := CM{ Name: defaultConfigMapName, Data: map[string]string{}, } @@ -638,16 +650,16 @@ func getConfigMap(options ...configMapOption) *ConfigMap { return &cm } -type configMapOption func(*ConfigMap) +type configMapOption func(*CM) func withConfigMapName(name string) configMapOption { - return func(configmap *ConfigMap) { + return func(configmap *CM) { configmap.Name = name } } func withConfigMapData(k, v string) configMapOption { - return func(configmap *ConfigMap) { + return func(configmap *CM) { configmap.Data[k] = v } } @@ -1047,11 +1059,18 @@ type PersistentVolumeClaim struct { ClaimName string } +type ConfigMap struct { + Name string + Items []map[string]string + Optional bool +} + type Volume struct { VolumeType string Name string HostPath PersistentVolumeClaim + ConfigMap } // getHostPathVolume takes a type and a location for a HostPath @@ -1079,6 +1098,20 @@ func getPersistentVolumeClaimVolume(vName string) *Volume { } } +// getConfigMap returns a new ConfigMap Volume given the name and items +// of the ConfigMap. +func getConfigMapVolume(vName string, items []map[string]string, optional bool) *Volume { + return &Volume{ + VolumeType: "ConfigMap", + Name: defaultVolName, + ConfigMap: ConfigMap{ + Name: vName, + Items: items, + Optional: optional, + }, + } +} + type Env struct { Name string Value string @@ -2311,6 +2344,75 @@ VOLUME %s`, ALPINE, hostPathDir+"/") Expect(inspect.OutputToString()).To(Equal(correct)) }) + It("podman play kube ConfigMap volume with no items", func() { + volumeName := "cmVol" + cm := getConfigMap(withConfigMapName(volumeName), withConfigMapData("FOO", "foobar")) + cmYaml, err := getKubeYaml("configmap", cm) + Expect(err).To(BeNil()) + + ctr := getCtr(withVolumeMount("/test", false), withImage(BB)) + pod := getPod(withVolume(getConfigMapVolume(volumeName, []map[string]string{}, false)), withCtr(ctr)) + podYaml, err := getKubeYaml("pod", pod) + Expect(err).To(BeNil()) + yamls := []string{cmYaml, podYaml} + err = generateMultiDocKubeYaml(yamls, kubeYaml) + Expect(err).To(BeNil()) + + kube := podmanTest.Podman([]string{"play", "kube", kubeYaml}) + kube.WaitWithDefaultTimeout() + Expect(kube).Should(Exit(0)) + + cmData := podmanTest.Podman([]string{"exec", getCtrNameInPod(pod), "cat", "/test/FOO"}) + cmData.WaitWithDefaultTimeout() + Expect(cmData).Should(Exit(0)) + Expect(cmData.OutputToString()).To(Equal("foobar")) + }) + + It("podman play kube ConfigMap volume with items", func() { + volumeName := "cmVol" + cm := getConfigMap(withConfigMapName(volumeName), withConfigMapData("FOO", "foobar")) + cmYaml, err := getKubeYaml("configmap", cm) + Expect(err).To(BeNil()) + volumeContents := []map[string]string{{ + "key": "FOO", + "path": "BAR", + }} + + ctr := getCtr(withVolumeMount("/test", false), withImage(BB)) + pod := getPod(withVolume(getConfigMapVolume(volumeName, volumeContents, false)), withCtr(ctr)) + podYaml, err := getKubeYaml("pod", pod) + Expect(err).To(BeNil()) + yamls := []string{cmYaml, podYaml} + err = generateMultiDocKubeYaml(yamls, kubeYaml) + Expect(err).To(BeNil()) + + kube := podmanTest.Podman([]string{"play", "kube", kubeYaml}) + kube.WaitWithDefaultTimeout() + Expect(kube).Should(Exit(0)) + + cmData := podmanTest.Podman([]string{"exec", getCtrNameInPod(pod), "cat", "/test/BAR"}) + cmData.WaitWithDefaultTimeout() + Expect(cmData).Should(Exit(0)) + Expect(cmData.OutputToString()).To(Equal("foobar")) + + cmData = podmanTest.Podman([]string{"exec", getCtrNameInPod(pod), "cat", "/test/FOO"}) + cmData.WaitWithDefaultTimeout() + Expect(cmData).Should(Not(Exit(0))) + }) + + It("podman play kube with a missing optional ConfigMap volume", func() { + volumeName := "cmVol" + + ctr := getCtr(withVolumeMount("/test", false), withImage(BB)) + pod := getPod(withVolume(getConfigMapVolume(volumeName, []map[string]string{}, true)), withCtr(ctr)) + err = generateKubeYaml("pod", pod, kubeYaml) + Expect(err).To(BeNil()) + + kube := podmanTest.Podman([]string{"play", "kube", kubeYaml}) + kube.WaitWithDefaultTimeout() + Expect(kube).Should(Exit(0)) + }) + It("podman play kube applies labels to pods", func() { var numReplicas int32 = 5 expectedLabelKey := "key1" |