summaryrefslogtreecommitdiff
path: root/test/e2e/play_kube_test.go
diff options
context:
space:
mode:
authorzhangguanzhang <zhangguanzhang@qq.com>2020-09-17 22:18:43 +0800
committerzhangguanzhang <zhangguanzhang@qq.com>2020-09-18 13:28:22 +0800
commitf0ccac199bd500729dabc8948bbd4ddd0124231e (patch)
tree2147f83853330bca3812cd1cdf31176c38c02cfb /test/e2e/play_kube_test.go
parentf84f441bec8d4ad6b6dfce059ca71dbd2b0d9615 (diff)
downloadpodman-f0ccac199bd500729dabc8948bbd4ddd0124231e.tar.gz
podman-f0ccac199bd500729dabc8948bbd4ddd0124231e.tar.bz2
podman-f0ccac199bd500729dabc8948bbd4ddd0124231e.zip
handle the play kube and generate kube for with restartPolicy
Signed-off-by: zhangguanzhang <zhangguanzhang@qq.com>
Diffstat (limited to 'test/e2e/play_kube_test.go')
-rw-r--r--test/e2e/play_kube_test.go68
1 files changed, 54 insertions, 14 deletions
diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go
index f58862ab2..7a5aebcc2 100644
--- a/test/e2e/play_kube_test.go
+++ b/test/e2e/play_kube_test.go
@@ -46,6 +46,7 @@ metadata:
{{ end }}
spec:
+ restartPolicy: {{ .RestartPolicy }}
hostname: {{ .Hostname }}
hostAliases:
{{ range .HostAliases }}
@@ -165,6 +166,7 @@ spec:
{{- end }}
{{- end }}
spec:
+ restartPolicy: {{ .RestartPolicy }}
hostname: {{ .Hostname }}
containers:
{{ with .Ctrs }}
@@ -274,13 +276,14 @@ func generateDeploymentKubeYaml(deployment *Deployment, fileName string) error {
// Pod describes the options a kube yaml can be configured at pod level
type Pod struct {
- Name string
- Hostname string
- HostAliases []HostAlias
- Ctrs []*Ctr
- Volumes []*Volume
- Labels map[string]string
- Annotations map[string]string
+ Name string
+ RestartPolicy string
+ Hostname string
+ HostAliases []HostAlias
+ Ctrs []*Ctr
+ Volumes []*Volume
+ Labels map[string]string
+ Annotations map[string]string
}
type HostAlias struct {
@@ -293,13 +296,14 @@ type HostAlias struct {
// if no containers are added, it will add the default container
func getPod(options ...podOption) *Pod {
p := Pod{
- Name: defaultPodName,
- Hostname: "",
- HostAliases: nil,
- Ctrs: make([]*Ctr, 0),
- Volumes: make([]*Volume, 0),
- Labels: make(map[string]string),
- Annotations: make(map[string]string),
+ Name: defaultPodName,
+ RestartPolicy: "Never",
+ Hostname: "",
+ HostAliases: nil,
+ Ctrs: make([]*Ctr, 0),
+ Volumes: make([]*Volume, 0),
+ Labels: make(map[string]string),
+ Annotations: make(map[string]string),
}
for _, option := range options {
option(&p)
@@ -312,6 +316,12 @@ func getPod(options ...podOption) *Pod {
type podOption func(*Pod)
+func withPodName(name string) podOption {
+ return func(pod *Pod) {
+ pod.Name = name
+ }
+}
+
func withHostname(h string) podOption {
return func(pod *Pod) {
pod.Hostname = h
@@ -333,6 +343,12 @@ func withCtr(c *Ctr) podOption {
}
}
+func withRestartPolicy(policy string) podOption {
+ return func(pod *Pod) {
+ pod.RestartPolicy = policy
+ }
+}
+
func withLabel(k, v string) podOption {
return func(pod *Pod) {
pod.Labels[k] = v
@@ -649,6 +665,30 @@ var _ = Describe("Podman generate kube", func() {
Expect(inspect.OutputToString()).To(ContainSubstring(`[echo hello world]`))
})
+ It("podman play kube test restartPolicy", func() {
+ // podName, set, expect
+ testSli := [][]string{
+ {"testPod1", "", "always"}, // Default eqaul to always
+ {"testPod2", "Always", "always"},
+ {"testPod3", "OnFailure", "on-failure"},
+ {"testPod4", "Never", "no"},
+ }
+ for _, v := range testSli {
+ pod := getPod(withPodName(v[0]), withRestartPolicy(v[1]))
+ 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.RestartPolicy.Name}}"})
+ inspect.WaitWithDefaultTimeout()
+ Expect(inspect.ExitCode()).To(Equal(0))
+ Expect(inspect.OutputToString()).To(Equal(v[2]))
+ }
+ })
+
It("podman play kube test hostname", func() {
pod := getPod()
err := generatePodKubeYaml(pod, kubeYaml)