Skip to content

Make service e2e tests retry to avoid flakes #15957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 32 additions & 27 deletions test/extended/networking/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package networking
import (
"fmt"
"os"
"strings"
"time"

testexutil "github.com/openshift/origin/test/extended/util"
Expand Down Expand Up @@ -163,32 +164,36 @@ func launchWebserverService(f *e2e.Framework, serviceName string, nodeName strin
return
}

func checkConnectivityToHost(f *e2e.Framework, nodeName string, podName string, host string, timeout int) error {
contName := fmt.Sprintf("%s-container", podName)
pod := &kapiv1.Pod{
TypeMeta: metav1.TypeMeta{
Kind: "Pod",
},
ObjectMeta: metav1.ObjectMeta{
Name: podName,
},
Spec: kapiv1.PodSpec{
Containers: []kapiv1.Container{
{
Name: contName,
Image: "gcr.io/google_containers/busybox",
Command: []string{"wget", fmt.Sprintf("--timeout=%d", timeout), "-s", host},
},
},
NodeName: nodeName,
RestartPolicy: kapiv1.RestartPolicyNever,
},
func checkConnectivityToHost(f *e2e.Framework, nodeName string, podName string, host string, timeout time.Duration) error {
e2e.Logf("Creating an exec pod on node %v", nodeName)
execPodName := e2e.CreateExecPodOrFail(f.ClientSet, f.Namespace.Name, fmt.Sprintf("execpod-sourceip-%s", nodeName), func(pod *kapiv1.Pod) {
pod.Spec.NodeName = nodeName
})
defer func() {
e2e.Logf("Cleaning up the exec pod")
err := f.ClientSet.Core().Pods(f.Namespace.Name).Delete(execPodName, nil)
Expect(err).NotTo(HaveOccurred())
}()
execPod, err := f.ClientSet.Core().Pods(f.Namespace.Name).Get(execPodName, metav1.GetOptions{})
e2e.ExpectNoError(err)

var stdout string
e2e.Logf("Waiting up to %v to wget %s", timeout, host)
cmd := fmt.Sprintf("wget -T 30 -qO- %s", host)
for start := time.Now(); time.Since(start) < timeout; time.Sleep(2) {
stdout, err = e2e.RunHostCmd(execPod.Namespace, execPod.Name, cmd)
if err != nil {
e2e.Logf("got err: %v, retry until timeout", err)
continue
}
// Need to check output because wget -q might omit the error.
if strings.TrimSpace(stdout) == "" {
e2e.Logf("got empty stdout, retry until timeout")
continue
}
break
}
podClient := f.ClientSet.CoreV1().Pods(f.Namespace.Name)
_, err := podClient.Create(pod)
expectNoError(err)
defer podClient.Delete(podName, nil)
return waitForPodSuccessInNamespace(f.ClientSet, podName, contName, f.Namespace.Name)
return err
}

func pluginIsolatesNamespaces() bool {
Expand Down Expand Up @@ -226,7 +231,7 @@ func checkPodIsolation(f1, f2 *e2e.Framework, nodeType NodeType) error {
defer f1.ClientSet.CoreV1().Pods(f1.Namespace.Name).Delete(podName, nil)
ip := e2e.LaunchWebserverPod(f1, podName, serverNode.Name)

return checkConnectivityToHost(f2, clientNode.Name, "isolation-wget", ip, 10)
return checkConnectivityToHost(f2, clientNode.Name, "isolation-wget", ip, 10*time.Second)
}

func checkServiceConnectivity(serverFramework, clientFramework *e2e.Framework, nodeType NodeType) error {
Expand All @@ -247,7 +252,7 @@ func checkServiceConnectivity(serverFramework, clientFramework *e2e.Framework, n
defer serverFramework.ClientSet.CoreV1().Services(serverFramework.Namespace.Name).Delete(podName, nil)
ip := launchWebserverService(serverFramework, podName, serverNode.Name)

return checkConnectivityToHost(clientFramework, clientNode.Name, "service-wget", ip, 10)
return checkConnectivityToHost(clientFramework, clientNode.Name, "service-wget", ip, 10*time.Second)
}

func InSingleTenantContext(body func()) {
Expand Down