forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpod_servers.go
52 lines (41 loc) · 1.93 KB
/
pod_servers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package tests
import (
"context"
"fmt"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"kubevirt.io/kubevirt/tests/framework/kubevirt"
"kubevirt.io/kubevirt/tests/libpod"
"kubevirt.io/kubevirt/tests/testsuite"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func NewHTTPServerPod(ipFamily, port int) *corev1.Pod {
serverCommand := fmt.Sprintf("nc -%d -klp %d --sh-exec 'echo -e \"HTTP/1.1 200 OK\\nContent-Length: 12\\n\\nHello World!\"'", ipFamily, port)
return libpod.RenderPrivilegedPod("http-hello-world-server", []string{"/bin/bash"}, []string{"-c", serverCommand})
}
func NewTCPServerPod(ipFamily, port int) *corev1.Pod {
serverCommand := fmt.Sprintf("nc -%d -klp %d --sh-exec 'echo \"Hello World!\"'", ipFamily, port)
return libpod.RenderPrivilegedPod("tcp-hello-world-server", []string{"/bin/bash"}, []string{"-c", serverCommand})
}
func CreatePodAndWaitUntil(pod *corev1.Pod, phaseToWait corev1.PodPhase) *corev1.Pod {
virtClient := kubevirt.Client()
var err error
pod, err = virtClient.CoreV1().Pods(testsuite.GetTestNamespace(pod)).Create(context.Background(), pod, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred(), "should succeed creating pod")
getStatus := func() corev1.PodPhase {
pod, err = virtClient.CoreV1().Pods(testsuite.GetTestNamespace(pod)).Get(context.Background(), pod.Name, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
return pod.Status.Phase
}
Eventually(getStatus, 30, 1).Should(Equal(phaseToWait), "should reach %s phase", phaseToWait)
return pod
}
func StartTCPServerPod(ipFamily, port int) *corev1.Pod {
By(fmt.Sprintf("Start TCP Server pod at port %d", port))
return CreatePodAndWaitUntil(NewTCPServerPod(ipFamily, port), corev1.PodRunning)
}
func StartHTTPServerPod(ipFamily, port int) *corev1.Pod {
By(fmt.Sprintf("Start HTTP Server pod at port %d", port))
return CreatePodAndWaitUntil(NewHTTPServerPod(ipFamily, port), corev1.PodRunning)
}