mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #109039 from mkimuram/issue/109037
Use WaitForPodRunningInNamespace for proxy e2e tests
This commit is contained in:
commit
9568dca969
@ -39,6 +39,7 @@ import (
|
||||
"k8s.io/client-go/transport"
|
||||
"k8s.io/kubernetes/test/e2e/framework"
|
||||
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
|
||||
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
|
||||
e2erc "k8s.io/kubernetes/test/e2e/framework/rc"
|
||||
"k8s.io/kubernetes/test/e2e/network/common"
|
||||
testutils "k8s.io/kubernetes/test/utils"
|
||||
@ -57,8 +58,6 @@ const (
|
||||
|
||||
// We have seen one of these calls take just over 15 seconds, so putting this at 30.
|
||||
proxyHTTPCallTimeout = 30 * time.Second
|
||||
podRetryPeriod = 1 * time.Second
|
||||
podRetryTimeout = 1 * time.Minute
|
||||
|
||||
requestRetryPeriod = 10 * time.Millisecond
|
||||
requestRetryTimeout = 1 * time.Minute
|
||||
@ -290,9 +289,10 @@ var _ = common.SIGDescribe("Proxy", func() {
|
||||
testSvcLabels := map[string]string{"test": "response"}
|
||||
|
||||
framework.Logf("Creating pod...")
|
||||
_, err := f.ClientSet.CoreV1().Pods(ns).Create(context.TODO(), &v1.Pod{
|
||||
pod := &v1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "agnhost",
|
||||
Name: "agnhost",
|
||||
Namespace: ns,
|
||||
Labels: map[string]string{
|
||||
"test": "response"},
|
||||
},
|
||||
@ -307,11 +307,10 @@ var _ = common.SIGDescribe("Proxy", func() {
|
||||
}},
|
||||
}},
|
||||
RestartPolicy: v1.RestartPolicyNever,
|
||||
}}, metav1.CreateOptions{})
|
||||
}}
|
||||
_, err := f.ClientSet.CoreV1().Pods(ns).Create(context.TODO(), pod, metav1.CreateOptions{})
|
||||
framework.ExpectNoError(err, "failed to create pod")
|
||||
|
||||
err = wait.PollImmediate(podRetryPeriod, podRetryTimeout, checkPodStatus(f, "test=response"))
|
||||
framework.ExpectNoError(err, "Pod didn't start within time out period")
|
||||
framework.ExpectNoError(e2epod.WaitForPodRunningInNamespace(f.ClientSet, pod), "Pod didn't start within time out period")
|
||||
|
||||
framework.Logf("Creating service...")
|
||||
_, err = f.ClientSet.CoreV1().Services(ns).Create(context.TODO(), &v1.Service{
|
||||
@ -384,9 +383,10 @@ var _ = common.SIGDescribe("Proxy", func() {
|
||||
testSvcLabels := map[string]string{"e2e-test": "proxy-endpoints"}
|
||||
|
||||
framework.Logf("Creating pod...")
|
||||
_, err := f.ClientSet.CoreV1().Pods(ns).Create(context.TODO(), &v1.Pod{
|
||||
pod := &v1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "agnhost",
|
||||
Name: "agnhost",
|
||||
Namespace: ns,
|
||||
Labels: map[string]string{
|
||||
"e2e-test": "proxy-endpoints"},
|
||||
},
|
||||
@ -401,11 +401,10 @@ var _ = common.SIGDescribe("Proxy", func() {
|
||||
}},
|
||||
}},
|
||||
RestartPolicy: v1.RestartPolicyNever,
|
||||
}}, metav1.CreateOptions{})
|
||||
}}
|
||||
_, err := f.ClientSet.CoreV1().Pods(ns).Create(context.TODO(), pod, metav1.CreateOptions{})
|
||||
framework.ExpectNoError(err, "failed to create pod")
|
||||
|
||||
err = wait.PollImmediate(podRetryPeriod, podRetryTimeout, checkPodStatus(f, "e2e-test=proxy-endpoints"))
|
||||
framework.ExpectNoError(err, "Pod didn't start within time out period")
|
||||
framework.ExpectNoError(e2epod.WaitForPodRunningInNamespace(f.ClientSet, pod), "Pod didn't start within time out period")
|
||||
|
||||
framework.Logf("Creating service...")
|
||||
_, err = f.ClientSet.CoreV1().Services(ns).Create(context.TODO(), &v1.Service{
|
||||
@ -487,26 +486,6 @@ func validateRedirectRequest(client *http.Client, redirectVerb string, urlString
|
||||
framework.ExpectEqual(resp.StatusCode, 301, "The resp.StatusCode returned: %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
func checkPodStatus(f *framework.Framework, label string) func() (bool, error) {
|
||||
return func() (bool, error) {
|
||||
var err error
|
||||
|
||||
list, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).List(context.TODO(), metav1.ListOptions{
|
||||
LabelSelector: label})
|
||||
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if list.Items[0].Status.Phase != "Running" {
|
||||
framework.Logf("Pod Quantity: %d Status: %s", len(list.Items), list.Items[0].Status.Phase)
|
||||
return false, err
|
||||
}
|
||||
framework.Logf("Pod Status: %v", list.Items[0].Status.Phase)
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// validateProxyVerbRequest checks that a http request to a pod
|
||||
// or service was valid for any http verb. Requires agnhost image
|
||||
// with porter --json-response
|
||||
|
Loading…
Reference in New Issue
Block a user