Skip to content

Commit

Permalink
probes: bind the nc server to the correct ip family
Browse files Browse the repository at this point in the history
Signed-off-by: Alona Paz <[email protected]>
  • Loading branch information
AlonaKaplan committed Jul 17, 2022
1 parent 3ee8f9b commit 1bee65b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
15 changes: 10 additions & 5 deletions tests/network/probes.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,19 @@ var _ = SIGDescribe("[ref_id:1182]Probes", func() {
util.PanicOnError(err)
})

buildProbeBackendPodSpec := func(probe *v1.Probe) (*corev1.Pod, func() error) {
buildProbeBackendPodSpec := func(ipFamily corev1.IPFamily, probe *v1.Probe) (*corev1.Pod, func() error) {
family := 4
if ipFamily == corev1.IPv6Protocol {
family = 6
}

var probeBackendPod *corev1.Pod
if isHTTPProbe(*probe) {
port := probe.HTTPGet.Port.IntVal
probeBackendPod = tests.StartHTTPServerPod(int(port))
probeBackendPod = tests.StartHTTPServerPod(family, int(port))
} else {
port := probe.TCPSocket.Port.IntVal
probeBackendPod = tests.StartTCPServerPod(int(port))
probeBackendPod = tests.StartTCPServerPod(family, int(port))
}
return probeBackendPod, func() error {
return virtClient.CoreV1().Pods(util.NamespaceTestDefault).Delete(context.Background(), probeBackendPod.Name, metav1.DeleteOptions{})
Expand All @@ -75,7 +80,7 @@ var _ = SIGDescribe("[ref_id:1182]Probes", func() {

if ipFamily == corev1.IPv6Protocol {
By("Create a support pod which will reply to kubelet's probes ...")
probeBackendPod, supportPodCleanupFunc := buildProbeBackendPodSpec(readinessProbe)
probeBackendPod, supportPodCleanupFunc := buildProbeBackendPodSpec(ipFamily, readinessProbe)
defer func() {
Expect(supportPodCleanupFunc()).To(Succeed(), "The support pod responding to the probes should be cleaned-up at test tear-down.")
}()
Expand Down Expand Up @@ -180,7 +185,7 @@ var _ = SIGDescribe("[ref_id:1182]Probes", func() {
if ipFamily == corev1.IPv6Protocol {

By("Create a support pod which will reply to kubelet's probes ...")
probeBackendPod, supportPodCleanupFunc := buildProbeBackendPodSpec(livenessProbe)
probeBackendPod, supportPodCleanupFunc := buildProbeBackendPodSpec(ipFamily, livenessProbe)
defer func() {
Expect(supportPodCleanupFunc()).To(Succeed(), "The support pod responding to the probes should be cleaned-up at test tear-down.")
}()
Expand Down
16 changes: 8 additions & 8 deletions tests/pod_servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import (
"kubevirt.io/client-go/kubecli"
)

func NewHTTPServerPod(port int) *corev1.Pod {
serverCommand := fmt.Sprintf("nc -klp %d --sh-exec 'echo -e \"HTTP/1.1 200 OK\\nContent-Length: 12\\n\\nHello World!\"'", port)
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 RenderPrivilegedPod("http-hello-world-server", []string{"/bin/bash"}, []string{"-c", serverCommand})
}

func NewTCPServerPod(port int) *corev1.Pod {
serverCommand := fmt.Sprintf("nc -klp %d --sh-exec 'echo \"Hello World!\"'", port)
func NewTCPServerPod(ipFamily, port int) *corev1.Pod {
serverCommand := fmt.Sprintf("nc -%d -klp %d --sh-exec 'echo \"Hello World!\"'", ipFamily, port)
return RenderPrivilegedPod("tcp-hello-world-server", []string{"/bin/bash"}, []string{"-c", serverCommand})
}

Expand All @@ -41,12 +41,12 @@ func CreatePodAndWaitUntil(pod *corev1.Pod, phaseToWait corev1.PodPhase) *corev1
return pod
}

func StartTCPServerPod(port int) *corev1.Pod {
func StartTCPServerPod(ipFamily, port int) *corev1.Pod {
By(fmt.Sprintf("Start TCP Server pod at port %d", port))
return CreatePodAndWaitUntil(NewTCPServerPod(port), corev1.PodRunning)
return CreatePodAndWaitUntil(NewTCPServerPod(ipFamily, port), corev1.PodRunning)
}

func StartHTTPServerPod(port int) *corev1.Pod {
func StartHTTPServerPod(ipFamily, port int) *corev1.Pod {
By(fmt.Sprintf("Start HTTP Server pod at port %d", port))
return CreatePodAndWaitUntil(NewHTTPServerPod(port), corev1.PodRunning)
return CreatePodAndWaitUntil(NewHTTPServerPod(ipFamily, port), corev1.PodRunning)
}

0 comments on commit 1bee65b

Please sign in to comment.