func checkServiceConnectivity(serverFramework, clientFramework *e2e.Framework, numNodes int) error { nodes, err := e2e.GetReadyNodes(serverFramework) if err != nil { e2e.Failf("Failed to list nodes: %v", err) } var serverNode, clientNode *api.Node serverNode = &nodes.Items[0] if numNodes == 2 { if len(nodes.Items) == 1 { e2e.Skipf("Only one node is available in this environment") } clientNode = &nodes.Items[1] } else { clientNode = serverNode } podName := "service-webserver" defer serverFramework.Client.Pods(serverFramework.Namespace.Name).Delete(podName, nil) ip := launchWebserverService(serverFramework, podName, serverNode.Name) return checkConnectivityToHost(clientFramework, clientNode.Name, "service-wget", ip, 10) }
func checkPodIsolation(f1, f2 *e2e.Framework, numNodes int) error { nodes, err := e2e.GetReadyNodes(f1) if err != nil { e2e.Failf("Failed to list nodes: %v", err) } var serverNode, clientNode *api.Node serverNode = &nodes.Items[0] if numNodes == 2 { if len(nodes.Items) == 1 { e2e.Skipf("Only one node is available in this environment") } clientNode = &nodes.Items[1] } else { clientNode = serverNode } podName := "isolation-webserver" defer f1.Client.Pods(f1.Namespace.Name).Delete(podName, nil) ip := e2e.LaunchWebserverPod(f1, podName, serverNode.Name) return checkConnectivityToHost(f2, clientNode.Name, "isolation-wget", ip, 10) }
}) if err != nil { framework.Failf("unable to create test service named [%s] %v", svc.Name, err) } // Clean up service defer func() { By("Cleaning up the service") if err = f.Client.Services(f.Namespace.Name).Delete(svc.Name); err != nil { framework.Failf("unable to delete svc %v: %v", svc.Name, err) } }() By("Creating a webserver (pending) pod on each node") nodes, err := framework.GetReadyNodes(f) framework.ExpectNoError(err) if len(nodes.Items) == 1 { // in general, the test requires two nodes. But for local development, often a one node cluster // is created, for simplicity and speed. (see issue #10012). We permit one-node test // only in some cases if !framework.ProviderIs("local") { framework.Failf(fmt.Sprintf("The test requires two Ready nodes on %s, but found just one.", framework.TestContext.Provider)) } framework.Logf("Only one ready node is detected. The test has limited scope in such setting. " + "Rerun it with at least two nodes to get complete coverage.") } podNames := LaunchNetTestPodPerNode(f, nodes, svcname, "1.8")
func runClientServerBandwidthMeasurement(f *framework.Framework, numClient int, maxBandwidthBits int64) { // TODO: Make this a function parameter, once we distribute iperf endpoints, possibly via session affinity. numServer := 1 It(fmt.Sprintf("should transfer ~ 1GB onto the service endpoint %v servers (maximum of %v clients)", numServer, numClient), func() { nodes := framework.ListSchedulableNodesOrDie(f.Client) totalPods := len(nodes.Items) // for a single service, we expect to divide bandwidth between the network. Very crude estimate. expectedBandwidth := int(float64(maxBandwidthBits) / float64(totalPods)) Expect(totalPods).NotTo(Equal(0)) appName := "iperf-e2e" err, _ := f.CreateServiceForSimpleAppWithPods( 8001, 8002, appName, func(n api.Node) api.PodSpec { return api.PodSpec{ Containers: []api.Container{{ Name: "iperf-server", Image: "gcr.io/google_containers/iperf:e2e", Args: []string{ "/bin/sh", "-c", "/usr/local/bin/iperf -s -p 8001 ", }, Ports: []api.ContainerPort{{ContainerPort: 8001}}, }}, NodeName: n.Name, RestartPolicy: api.RestartPolicyOnFailure, } }, // this will be used to generate the -service name which all iperf clients point at. numServer, // Generally should be 1 server unless we do affinity or use a version of iperf that supports LB true, // Make sure we wait, otherwise all the clients will die and need to restart. ) if err != nil { framework.Failf("Fatal error waiting for iperf server endpoint : %v", err) } iperfClientPodLabels := f.CreatePodsPerNodeForSimpleApp( "iperf-e2e-cli", func(n api.Node) api.PodSpec { return api.PodSpec{ Containers: []api.Container{ { Name: "iperf-client", Image: "gcr.io/google_containers/iperf:e2e", Args: []string{ "/bin/sh", "-c", "/usr/local/bin/iperf -c service-for-" + appName + " -p 8002 --reportstyle C && sleep 5", }, }, }, RestartPolicy: api.RestartPolicyOnFailure, // let them successfully die. } }, numClient, ) framework.Logf("Reading all perf results to stdout.") framework.Logf("date,cli,cliPort,server,serverPort,id,interval,transferBits,bandwidthBits") // Calculate expected number of clients based on total nodes. expectedCli := func() int { nodes, err := framework.GetReadyNodes(f) framework.ExpectNoError(err) return int(math.Min(float64(len(nodes.Items)), float64(numClient))) }() // Extra 1/10 second per client. iperfTimeout := smallClusterTimeout + (time.Duration(expectedCli/10) * time.Second) iperfResults := &IPerfResults{} iperfClusterVerification := f.NewClusterVerification( framework.PodStateVerification{ Selectors: iperfClientPodLabels, ValidPhases: []api.PodPhase{api.PodSucceeded}, }, ) pods, err2 := iperfClusterVerification.WaitFor(expectedCli, iperfTimeout) if err2 != nil { framework.Failf("Error in wait...") } else if len(pods) < expectedCli { framework.Failf("IPerf restuls : Only got %v out of %v, after waiting %v", len(pods), expectedCli, iperfTimeout) } else { // For each builds up a collection of IPerfRecords iperfClusterVerification.ForEach( func(p api.Pod) { resultS, err := framework.LookForStringInLog(f.Namespace.Name, p.Name, "iperf-client", "0-", 1*time.Second) if err == nil { framework.Logf(resultS) iperfResults.Add(NewIPerf(resultS)) } else { framework.Failf("Unexpected error, %v when running forEach on the pods.", err) } }) } fmt.Println("[begin] Node,Bandwith CSV") fmt.Println(iperfResults.ToTSV()) fmt.Println("[end] Node,Bandwith CSV") for ipClient, bandwidth := range iperfResults.BandwidthMap { framework.Logf("%v had bandwidth %v. Ratio to expected (%v) was %f", ipClient, bandwidth, expectedBandwidth, float64(bandwidth)/float64(expectedBandwidth)) } }) }