mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-12-03 06:43:53 +00:00
Merge pull request #81693 from oomichi/replace-e2elog-framework-c-n
Use log functions of core framework on [c-n]
This commit is contained in:
@@ -38,7 +38,6 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
coreclientset "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
|
||||
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
|
||||
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
|
||||
imageutils "k8s.io/kubernetes/test/utils/image"
|
||||
@@ -172,10 +171,10 @@ func (config *NetworkingTestConfig) diagnoseMissingEndpoints(foundEndpoints sets
|
||||
if foundEndpoints.Has(e.Name) {
|
||||
continue
|
||||
}
|
||||
e2elog.Logf("\nOutput of kubectl describe pod %v/%v:\n", e.Namespace, e.Name)
|
||||
Logf("\nOutput of kubectl describe pod %v/%v:\n", e.Namespace, e.Name)
|
||||
desc, _ := RunKubectl(
|
||||
"describe", "pod", e.Name, fmt.Sprintf("--namespace=%v", e.Namespace))
|
||||
e2elog.Logf(desc)
|
||||
Logf(desc)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,11 +219,11 @@ func (config *NetworkingTestConfig) DialFromContainer(protocol, containerIP, tar
|
||||
// A failure to kubectl exec counts as a try, not a hard fail.
|
||||
// Also note that we will keep failing for maxTries in tests where
|
||||
// we confirm unreachability.
|
||||
e2elog.Logf("Failed to execute %q: %v, stdout: %q, stderr %q", cmd, err, stdout, stderr)
|
||||
Logf("Failed to execute %q: %v, stdout: %q, stderr %q", cmd, err, stdout, stderr)
|
||||
} else {
|
||||
var output map[string][]string
|
||||
if err := json.Unmarshal([]byte(stdout), &output); err != nil {
|
||||
e2elog.Logf("WARNING: Failed to unmarshal curl response. Cmd %v run in %v, output: %s, err: %v",
|
||||
Logf("WARNING: Failed to unmarshal curl response. Cmd %v run in %v, output: %s, err: %v",
|
||||
cmd, config.HostTestContainerPod.Name, stdout, err)
|
||||
continue
|
||||
}
|
||||
@@ -236,7 +235,7 @@ func (config *NetworkingTestConfig) DialFromContainer(protocol, containerIP, tar
|
||||
}
|
||||
}
|
||||
}
|
||||
e2elog.Logf("Waiting for endpoints: %v", expectedEps.Difference(eps))
|
||||
Logf("Waiting for endpoints: %v", expectedEps.Difference(eps))
|
||||
|
||||
// Check against i+1 so we exit if minTries == maxTries.
|
||||
if (eps.Equal(expectedEps) || eps.Len() == 0 && expectedEps.Len() == 0) && i+1 >= minTries {
|
||||
@@ -247,7 +246,7 @@ func (config *NetworkingTestConfig) DialFromContainer(protocol, containerIP, tar
|
||||
}
|
||||
|
||||
config.diagnoseMissingEndpoints(eps)
|
||||
e2elog.Failf("Failed to find expected endpoints:\nTries %d\nCommand %v\nretrieved %v\nexpected %v\n", maxTries, cmd, eps, expectedEps)
|
||||
Failf("Failed to find expected endpoints:\nTries %d\nCommand %v\nretrieved %v\nexpected %v\n", maxTries, cmd, eps, expectedEps)
|
||||
}
|
||||
|
||||
// GetEndpointsFromTestContainer executes a curl via kubectl exec in a test container.
|
||||
@@ -279,12 +278,12 @@ func (config *NetworkingTestConfig) GetEndpointsFromContainer(protocol, containe
|
||||
// A failure to kubectl exec counts as a try, not a hard fail.
|
||||
// Also note that we will keep failing for maxTries in tests where
|
||||
// we confirm unreachability.
|
||||
e2elog.Logf("Failed to execute %q: %v, stdout: %q, stderr: %q", cmd, err, stdout, stderr)
|
||||
Logf("Failed to execute %q: %v, stdout: %q, stderr: %q", cmd, err, stdout, stderr)
|
||||
} else {
|
||||
e2elog.Logf("Tries: %d, in try: %d, stdout: %v, stderr: %v, command run in: %#v", tries, i, stdout, stderr, config.HostTestContainerPod)
|
||||
Logf("Tries: %d, in try: %d, stdout: %v, stderr: %v, command run in: %#v", tries, i, stdout, stderr, config.HostTestContainerPod)
|
||||
var output map[string][]string
|
||||
if err := json.Unmarshal([]byte(stdout), &output); err != nil {
|
||||
e2elog.Logf("WARNING: Failed to unmarshal curl response. Cmd %v run in %v, output: %s, err: %v",
|
||||
Logf("WARNING: Failed to unmarshal curl response. Cmd %v run in %v, output: %s, err: %v",
|
||||
cmd, config.HostTestContainerPod.Name, stdout, err)
|
||||
continue
|
||||
}
|
||||
@@ -338,7 +337,7 @@ func (config *NetworkingTestConfig) DialFromNode(protocol, targetIP string, targ
|
||||
// A failure to exec command counts as a try, not a hard fail.
|
||||
// Also note that we will keep failing for maxTries in tests where
|
||||
// we confirm unreachability.
|
||||
e2elog.Logf("Failed to execute %q: %v, stdout: %q, stderr: %q", filterCmd, err, stdout, stderr)
|
||||
Logf("Failed to execute %q: %v, stdout: %q, stderr: %q", filterCmd, err, stdout, stderr)
|
||||
} else {
|
||||
trimmed := strings.TrimSpace(stdout)
|
||||
if trimmed != "" {
|
||||
@@ -348,18 +347,18 @@ func (config *NetworkingTestConfig) DialFromNode(protocol, targetIP string, targ
|
||||
|
||||
// Check against i+1 so we exit if minTries == maxTries.
|
||||
if eps.Equal(expectedEps) && i+1 >= minTries {
|
||||
e2elog.Logf("Found all expected endpoints: %+v", eps.List())
|
||||
Logf("Found all expected endpoints: %+v", eps.List())
|
||||
return
|
||||
}
|
||||
|
||||
e2elog.Logf("Waiting for %+v endpoints (expected=%+v, actual=%+v)", expectedEps.Difference(eps).List(), expectedEps.List(), eps.List())
|
||||
Logf("Waiting for %+v endpoints (expected=%+v, actual=%+v)", expectedEps.Difference(eps).List(), expectedEps.List(), eps.List())
|
||||
|
||||
// TODO: get rid of this delay #36281
|
||||
time.Sleep(hitEndpointRetryDelay)
|
||||
}
|
||||
|
||||
config.diagnoseMissingEndpoints(eps)
|
||||
e2elog.Failf("Failed to find expected endpoints:\nTries %d\nCommand %v\nretrieved %v\nexpected %v\n", maxTries, cmd, eps, expectedEps)
|
||||
Failf("Failed to find expected endpoints:\nTries %d\nCommand %v\nretrieved %v\nexpected %v\n", maxTries, cmd, eps, expectedEps)
|
||||
}
|
||||
|
||||
// GetSelfURL executes a curl against the given path via kubectl exec into a
|
||||
@@ -392,21 +391,21 @@ func (config *NetworkingTestConfig) executeCurlCmd(cmd string, expected string)
|
||||
stdout, err := RunHostCmd(config.Namespace, podName, cmd)
|
||||
if err != nil {
|
||||
msg = fmt.Sprintf("failed executing cmd %v in %v/%v: %v", cmd, config.Namespace, podName, err)
|
||||
e2elog.Logf(msg)
|
||||
Logf(msg)
|
||||
return false, nil
|
||||
}
|
||||
if !strings.Contains(stdout, expected) {
|
||||
msg = fmt.Sprintf("successfully executed %v in %v/%v, but output '%v' doesn't contain expected string '%v'", cmd, config.Namespace, podName, stdout, expected)
|
||||
e2elog.Logf(msg)
|
||||
Logf(msg)
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
}); pollErr != nil {
|
||||
e2elog.Logf("\nOutput of kubectl describe pod %v/%v:\n", config.Namespace, podName)
|
||||
Logf("\nOutput of kubectl describe pod %v/%v:\n", config.Namespace, podName)
|
||||
desc, _ := RunKubectl(
|
||||
"describe", "pod", podName, fmt.Sprintf("--namespace=%v", config.Namespace))
|
||||
e2elog.Logf("%s", desc)
|
||||
e2elog.Failf("Timed out in %v: %v", retryTimeout, msg)
|
||||
Logf("%s", desc)
|
||||
Failf("Timed out in %v: %v", retryTimeout, msg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -550,12 +549,12 @@ func (config *NetworkingTestConfig) createTestPods() {
|
||||
var err error
|
||||
config.TestContainerPod, err = config.getPodClient().Get(testContainerPod.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
e2elog.Failf("Failed to retrieve %s pod: %v", testContainerPod.Name, err)
|
||||
Failf("Failed to retrieve %s pod: %v", testContainerPod.Name, err)
|
||||
}
|
||||
|
||||
config.HostTestContainerPod, err = config.getPodClient().Get(hostTestContainerPod.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
e2elog.Failf("Failed to retrieve %s pod: %v", hostTestContainerPod.Name, err)
|
||||
Failf("Failed to retrieve %s pod: %v", hostTestContainerPod.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -675,12 +674,12 @@ func (config *NetworkingTestConfig) DeleteNetProxyPod() {
|
||||
// wait for pod being deleted.
|
||||
err := e2epod.WaitForPodToDisappear(config.f.ClientSet, config.Namespace, pod.Name, labels.Everything(), time.Second, wait.ForeverTestTimeout)
|
||||
if err != nil {
|
||||
e2elog.Failf("Failed to delete %s pod: %v", pod.Name, err)
|
||||
Failf("Failed to delete %s pod: %v", pod.Name, err)
|
||||
}
|
||||
// wait for endpoint being removed.
|
||||
err = WaitForServiceEndpointsNum(config.f.ClientSet, config.Namespace, nodePortServiceName, len(config.EndpointPods), time.Second, wait.ForeverTestTimeout)
|
||||
if err != nil {
|
||||
e2elog.Failf("Failed to remove endpoint from service: %s", nodePortServiceName)
|
||||
Failf("Failed to remove endpoint from service: %s", nodePortServiceName)
|
||||
}
|
||||
// wait for kube-proxy to catch up with the pod being deleted.
|
||||
time.Sleep(5 * time.Second)
|
||||
@@ -707,12 +706,12 @@ func CheckReachabilityFromPod(expectToBeReachable bool, timeout time.Duration, n
|
||||
err := wait.PollImmediate(Poll, timeout, func() (bool, error) {
|
||||
_, err := RunHostCmd(namespace, pod, cmd)
|
||||
if expectToBeReachable && err != nil {
|
||||
e2elog.Logf("Expect target to be reachable. But got err: %v. Retry until timeout", err)
|
||||
Logf("Expect target to be reachable. But got err: %v. Retry until timeout", err)
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if !expectToBeReachable && err == nil {
|
||||
e2elog.Logf("Expect target NOT to be reachable. But it is reachable. Retry until timeout")
|
||||
Logf("Expect target NOT to be reachable. But it is reachable. Retry until timeout")
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
@@ -780,11 +779,11 @@ func PokeHTTP(host string, port int, path string, params *HTTPPokeParams) HTTPPo
|
||||
// Sanity check inputs, because it has happened. These are the only things
|
||||
// that should hard fail the test - they are basically ASSERT()s.
|
||||
if host == "" {
|
||||
e2elog.Failf("Got empty host for HTTP poke (%s)", url)
|
||||
Failf("Got empty host for HTTP poke (%s)", url)
|
||||
return ret
|
||||
}
|
||||
if port == 0 {
|
||||
e2elog.Failf("Got port==0 for HTTP poke (%s)", url)
|
||||
Failf("Got port==0 for HTTP poke (%s)", url)
|
||||
return ret
|
||||
}
|
||||
|
||||
@@ -796,7 +795,7 @@ func PokeHTTP(host string, port int, path string, params *HTTPPokeParams) HTTPPo
|
||||
params.ExpectCode = http.StatusOK
|
||||
}
|
||||
|
||||
e2elog.Logf("Poking %q", url)
|
||||
Logf("Poking %q", url)
|
||||
|
||||
resp, err := httpGetNoConnectionPoolTimeout(url, params.Timeout)
|
||||
if err != nil {
|
||||
@@ -809,7 +808,7 @@ func PokeHTTP(host string, port int, path string, params *HTTPPokeParams) HTTPPo
|
||||
} else {
|
||||
ret.Status = HTTPError
|
||||
}
|
||||
e2elog.Logf("Poke(%q): %v", url, err)
|
||||
Logf("Poke(%q): %v", url, err)
|
||||
return ret
|
||||
}
|
||||
|
||||
@@ -820,7 +819,7 @@ func PokeHTTP(host string, port int, path string, params *HTTPPokeParams) HTTPPo
|
||||
if err != nil {
|
||||
ret.Status = HTTPError
|
||||
ret.Error = fmt.Errorf("error reading HTTP body: %v", err)
|
||||
e2elog.Logf("Poke(%q): %v", url, ret.Error)
|
||||
Logf("Poke(%q): %v", url, ret.Error)
|
||||
return ret
|
||||
}
|
||||
ret.Body = make([]byte, len(body))
|
||||
@@ -831,25 +830,25 @@ func PokeHTTP(host string, port int, path string, params *HTTPPokeParams) HTTPPo
|
||||
if resp.StatusCode == code {
|
||||
ret.Error = fmt.Errorf("retriable status code: %d", resp.StatusCode)
|
||||
ret.Status = HTTPRetryCode
|
||||
e2elog.Logf("Poke(%q): %v", url, ret.Error)
|
||||
Logf("Poke(%q): %v", url, ret.Error)
|
||||
return ret
|
||||
}
|
||||
}
|
||||
ret.Status = HTTPWrongCode
|
||||
ret.Error = fmt.Errorf("bad status code: %d", resp.StatusCode)
|
||||
e2elog.Logf("Poke(%q): %v", url, ret.Error)
|
||||
Logf("Poke(%q): %v", url, ret.Error)
|
||||
return ret
|
||||
}
|
||||
|
||||
if params.BodyContains != "" && !strings.Contains(string(body), params.BodyContains) {
|
||||
ret.Status = HTTPBadResponse
|
||||
ret.Error = fmt.Errorf("response does not contain expected substring: %q", string(body))
|
||||
e2elog.Logf("Poke(%q): %v", url, ret.Error)
|
||||
Logf("Poke(%q): %v", url, ret.Error)
|
||||
return ret
|
||||
}
|
||||
|
||||
ret.Status = HTTPSuccess
|
||||
e2elog.Logf("Poke(%q): success", url)
|
||||
Logf("Poke(%q): success", url)
|
||||
return ret
|
||||
}
|
||||
|
||||
@@ -916,11 +915,11 @@ func PokeUDP(host string, port int, request string, params *UDPPokeParams) UDPPo
|
||||
// Sanity check inputs, because it has happened. These are the only things
|
||||
// that should hard fail the test - they are basically ASSERT()s.
|
||||
if host == "" {
|
||||
e2elog.Failf("Got empty host for UDP poke (%s)", url)
|
||||
Failf("Got empty host for UDP poke (%s)", url)
|
||||
return ret
|
||||
}
|
||||
if port == 0 {
|
||||
e2elog.Failf("Got port==0 for UDP poke (%s)", url)
|
||||
Failf("Got port==0 for UDP poke (%s)", url)
|
||||
return ret
|
||||
}
|
||||
|
||||
@@ -929,13 +928,13 @@ func PokeUDP(host string, port int, request string, params *UDPPokeParams) UDPPo
|
||||
params = &UDPPokeParams{}
|
||||
}
|
||||
|
||||
e2elog.Logf("Poking %v", url)
|
||||
Logf("Poking %v", url)
|
||||
|
||||
con, err := net.Dial("udp", hostPort)
|
||||
if err != nil {
|
||||
ret.Status = UDPError
|
||||
ret.Error = err
|
||||
e2elog.Logf("Poke(%q): %v", url, err)
|
||||
Logf("Poke(%q): %v", url, err)
|
||||
return ret
|
||||
}
|
||||
|
||||
@@ -950,7 +949,7 @@ func PokeUDP(host string, port int, request string, params *UDPPokeParams) UDPPo
|
||||
} else {
|
||||
ret.Status = UDPError
|
||||
}
|
||||
e2elog.Logf("Poke(%q): %v", url, err)
|
||||
Logf("Poke(%q): %v", url, err)
|
||||
return ret
|
||||
}
|
||||
|
||||
@@ -959,7 +958,7 @@ func PokeUDP(host string, port int, request string, params *UDPPokeParams) UDPPo
|
||||
if err != nil {
|
||||
ret.Status = UDPError
|
||||
ret.Error = err
|
||||
e2elog.Logf("Poke(%q): %v", url, err)
|
||||
Logf("Poke(%q): %v", url, err)
|
||||
return ret
|
||||
}
|
||||
}
|
||||
@@ -980,7 +979,7 @@ func PokeUDP(host string, port int, request string, params *UDPPokeParams) UDPPo
|
||||
} else {
|
||||
ret.Status = UDPError
|
||||
}
|
||||
e2elog.Logf("Poke(%q): %v", url, err)
|
||||
Logf("Poke(%q): %v", url, err)
|
||||
return ret
|
||||
}
|
||||
ret.Response = buf[0:n]
|
||||
@@ -988,12 +987,12 @@ func PokeUDP(host string, port int, request string, params *UDPPokeParams) UDPPo
|
||||
if params.Response != "" && string(ret.Response) != params.Response {
|
||||
ret.Status = UDPBadResponse
|
||||
ret.Error = fmt.Errorf("response does not match expected string: %q", string(ret.Response))
|
||||
e2elog.Logf("Poke(%q): %v", url, ret.Error)
|
||||
Logf("Poke(%q): %v", url, ret.Error)
|
||||
return ret
|
||||
}
|
||||
|
||||
ret.Status = UDPSuccess
|
||||
e2elog.Logf("Poke(%q): success", url)
|
||||
Logf("Poke(%q): success", url)
|
||||
return ret
|
||||
}
|
||||
|
||||
@@ -1005,7 +1004,7 @@ func TestHitNodesFromOutside(externalIP string, httpPort int32, timeout time.Dur
|
||||
// TestHitNodesFromOutsideWithCount checkes HTTP connectivity from outside with count.
|
||||
func TestHitNodesFromOutsideWithCount(externalIP string, httpPort int32, timeout time.Duration, expectedHosts sets.String,
|
||||
countToSucceed int) error {
|
||||
e2elog.Logf("Waiting up to %v for satisfying expectedHosts for %v times", timeout, countToSucceed)
|
||||
Logf("Waiting up to %v for satisfying expectedHosts for %v times", timeout, countToSucceed)
|
||||
hittedHosts := sets.NewString()
|
||||
count := 0
|
||||
condition := func() (bool, error) {
|
||||
@@ -1016,13 +1015,13 @@ func TestHitNodesFromOutsideWithCount(externalIP string, httpPort int32, timeout
|
||||
|
||||
hittedHost := strings.TrimSpace(string(result.Body))
|
||||
if !expectedHosts.Has(hittedHost) {
|
||||
e2elog.Logf("Error hitting unexpected host: %v, reset counter: %v", hittedHost, count)
|
||||
Logf("Error hitting unexpected host: %v, reset counter: %v", hittedHost, count)
|
||||
count = 0
|
||||
return false, nil
|
||||
}
|
||||
if !hittedHosts.Has(hittedHost) {
|
||||
hittedHosts.Insert(hittedHost)
|
||||
e2elog.Logf("Missing %+v, got %+v", expectedHosts.Difference(hittedHosts), hittedHosts)
|
||||
Logf("Missing %+v, got %+v", expectedHosts.Difference(hittedHosts), hittedHosts)
|
||||
}
|
||||
if hittedHosts.Equal(expectedHosts) {
|
||||
count++
|
||||
@@ -1047,7 +1046,7 @@ func TestHitNodesFromOutsideWithCount(externalIP string, httpPort int32, timeout
|
||||
func TestUnderTemporaryNetworkFailure(c clientset.Interface, ns string, node *v1.Node, testFunc func()) {
|
||||
host, err := e2enode.GetExternalIP(node)
|
||||
if err != nil {
|
||||
e2elog.Failf("Error getting node external ip : %v", err)
|
||||
Failf("Error getting node external ip : %v", err)
|
||||
}
|
||||
masterAddresses := GetAllMasterAddresses(c)
|
||||
ginkgo.By(fmt.Sprintf("block network traffic from node %s to the master", node.Name))
|
||||
@@ -1062,17 +1061,17 @@ func TestUnderTemporaryNetworkFailure(c clientset.Interface, ns string, node *v1
|
||||
}
|
||||
}()
|
||||
|
||||
e2elog.Logf("Waiting %v to ensure node %s is ready before beginning test...", resizeNodeReadyTimeout, node.Name)
|
||||
Logf("Waiting %v to ensure node %s is ready before beginning test...", resizeNodeReadyTimeout, node.Name)
|
||||
if !e2enode.WaitConditionToBe(c, node.Name, v1.NodeReady, true, resizeNodeReadyTimeout) {
|
||||
e2elog.Failf("Node %s did not become ready within %v", node.Name, resizeNodeReadyTimeout)
|
||||
Failf("Node %s did not become ready within %v", node.Name, resizeNodeReadyTimeout)
|
||||
}
|
||||
for _, masterAddress := range masterAddresses {
|
||||
BlockNetwork(host, masterAddress)
|
||||
}
|
||||
|
||||
e2elog.Logf("Waiting %v for node %s to be not ready after simulated network failure", resizeNodeNotReadyTimeout, node.Name)
|
||||
Logf("Waiting %v for node %s to be not ready after simulated network failure", resizeNodeNotReadyTimeout, node.Name)
|
||||
if !e2enode.WaitConditionToBe(c, node.Name, v1.NodeReady, false, resizeNodeNotReadyTimeout) {
|
||||
e2elog.Failf("Node %s did not become not-ready within %v", node.Name, resizeNodeNotReadyTimeout)
|
||||
Failf("Node %s did not become not-ready within %v", node.Name, resizeNodeNotReadyTimeout)
|
||||
}
|
||||
|
||||
testFunc()
|
||||
|
||||
Reference in New Issue
Block a user