當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Framework.WaitForPodReady方法代碼示例

本文整理匯總了Golang中k8s/io/kubernetes/test/e2e/framework.Framework.WaitForPodReady方法的典型用法代碼示例。如果您正苦於以下問題:Golang Framework.WaitForPodReady方法的具體用法?Golang Framework.WaitForPodReady怎麽用?Golang Framework.WaitForPodReady使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在k8s/io/kubernetes/test/e2e/framework.Framework的用法示例。


在下文中一共展示了Framework.WaitForPodReady方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: doTestConnectSendDisconnect

func doTestConnectSendDisconnect(bindAddress string, f *framework.Framework) {
	By("creating the target pod")
	pod := pfPod("", "10", "10", "100", fmt.Sprintf("%s", bindAddress))
	if _, err := f.ClientSet.Core().Pods(f.Namespace.Name).Create(pod); err != nil {
		framework.Failf("Couldn't create pod: %v", err)
	}
	if err := f.WaitForPodReady(pod.Name); err != nil {
		framework.Failf("Pod did not start running: %v", err)
	}
	defer func() {
		logs, err := framework.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, "portforwardtester")
		if err != nil {
			framework.Logf("Error getting pod log: %v", err)
		} else {
			framework.Logf("Pod log:\n%s", logs)
		}
	}()

	By("Running 'kubectl port-forward'")
	cmd := runPortForward(f.Namespace.Name, pod.Name, 80)
	defer cmd.Stop()

	By("Dialing the local port")
	conn, err := net.Dial("tcp", fmt.Sprintf("127.0.0.1:%d", cmd.port))
	if err != nil {
		framework.Failf("Couldn't connect to port %d: %v", cmd.port, err)
	}
	defer func() {
		By("Closing the connection to the local port")
		conn.Close()
	}()

	By("Reading data from the local port")
	fromServer, err := ioutil.ReadAll(conn)
	if err != nil {
		framework.Failf("Unexpected error reading data from the server: %v", err)
	}

	if e, a := strings.Repeat("x", 100), string(fromServer); e != a {
		framework.Failf("Expected %q from server, got %q", e, a)
	}

	By("Waiting for the target pod to stop running")
	if err := WaitForTerminatedContainer(f, pod, "portforwardtester"); err != nil {
		framework.Failf("Container did not terminate: %v", err)
	}

	By("Verifying logs")
	logOutput, err := framework.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, "portforwardtester")
	if err != nil {
		framework.Failf("Error retrieving pod logs: %v", err)
	}
	verifyLogMessage(logOutput, "Accepted client connection")
	verifyLogMessage(logOutput, "Done")
}
開發者ID:kubernetes,項目名稱:kubernetes,代碼行數:55,代碼來源:portforward.go

示例2: doTestMustConnectSendNothing

func doTestMustConnectSendNothing(bindAddress string, f *framework.Framework) {
	By("creating the target pod")
	pod := pfPod("abc", "1", "1", "1", fmt.Sprintf("%s", bindAddress))
	if _, err := f.ClientSet.Core().Pods(f.Namespace.Name).Create(pod); err != nil {
		framework.Failf("Couldn't create pod: %v", err)
	}
	if err := f.WaitForPodReady(pod.Name); err != nil {
		framework.Failf("Pod did not start running: %v", err)
	}
	defer func() {
		logs, err := framework.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, "portforwardtester")
		if err != nil {
			framework.Logf("Error getting pod log: %v", err)
		} else {
			framework.Logf("Pod log:\n%s", logs)
		}
	}()

	By("Running 'kubectl port-forward'")
	cmd := runPortForward(f.Namespace.Name, pod.Name, 80)
	defer cmd.Stop()

	By("Dialing the local port")
	conn, err := net.Dial("tcp", fmt.Sprintf("127.0.0.1:%d", cmd.port))
	if err != nil {
		framework.Failf("Couldn't connect to port %d: %v", cmd.port, err)
	}

	By("Closing the connection to the local port")
	conn.Close()

	By("Waiting for the target pod to stop running")
	if err := WaitForTerminatedContainer(f, pod, "portforwardtester"); err != nil {
		framework.Failf("Container did not terminate: %v", err)
	}

	By("Verifying logs")
	logOutput, err := framework.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, "portforwardtester")
	if err != nil {
		framework.Failf("Error retrieving pod logs: %v", err)
	}
	verifyLogMessage(logOutput, "Accepted client connection")
	verifyLogMessage(logOutput, "Expected to read 3 bytes from client, but got 0 instead")
}
開發者ID:kubernetes,項目名稱:kubernetes,代碼行數:44,代碼來源:portforward.go


注:本文中的k8s/io/kubernetes/test/e2e/framework.Framework.WaitForPodReady方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。