mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
Transitioning from multiple execs to reading logs
This commit is contained in:
parent
76c19a24db
commit
d4ebc6ff1e
@ -19,6 +19,7 @@ package network
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/onsi/ginkgo"
|
"github.com/onsi/ginkgo"
|
||||||
@ -151,37 +152,55 @@ var _ = common.SIGDescribe("Feature:Topology Hints", func() {
|
|||||||
if !ok {
|
if !ok {
|
||||||
framework.Failf("Expected zone to be specified for %s node", nodeName)
|
framework.Failf("Expected zone to be specified for %s node", nodeName)
|
||||||
}
|
}
|
||||||
execPod := e2epod.CreateExecPodOrFail(f.ClientSet, f.Namespace.Name, "execpod-", func(pod *v1.Pod) {
|
ginkgo.By("creating a client pod for probing the service from " + fromZone)
|
||||||
pod.Spec.NodeName = nodeName
|
podName := "curl-from-" + fromZone
|
||||||
})
|
clientPod := e2epod.NewAgnhostPod(f.Namespace.Name, podName, nil, nil, nil, "serve-hostname")
|
||||||
framework.Logf("Ensuring that requests from %s pod on %s node stay in %s zone", execPod.Name, nodeName, fromZone)
|
nodeSelection := e2epod.NodeSelection{Name: nodeName}
|
||||||
|
e2epod.SetNodeSelection(&clientPod.Spec, nodeSelection)
|
||||||
|
cmd := fmt.Sprintf(`date; for i in $(seq 1 3000); do sleep 1; echo "Date: $(date) Try: ${i}"; curl -q -s --connect-timeout 2 http://%s:80/ ; echo; done`, svc.Name)
|
||||||
|
clientPod.Spec.Containers[0].Command = []string{"/bin/sh", "-c", cmd}
|
||||||
|
clientPod.Spec.Containers[0].Name = clientPod.Name
|
||||||
|
f.PodClient().CreateSync(clientPod)
|
||||||
|
|
||||||
cmd := fmt.Sprintf("curl -q -s --connect-timeout 2 http://%s:80/", svc.Name)
|
framework.Logf("Ensuring that requests from %s pod on %s node stay in %s zone", clientPod.Name, nodeName, fromZone)
|
||||||
consecutiveRequests := 0
|
|
||||||
var stdout string
|
var logs string
|
||||||
if pollErr := wait.PollImmediate(framework.Poll, e2eservice.KubeProxyLagTimeout, func() (bool, error) {
|
if pollErr := wait.Poll(5*time.Second, e2eservice.KubeProxyLagTimeout, func() (bool, error) {
|
||||||
var err error
|
var err error
|
||||||
stdout, err = framework.RunHostCmd(f.Namespace.Name, execPod.Name, cmd)
|
logs, err = e2epod.GetPodLogs(c, f.Namespace.Name, clientPod.Name, clientPod.Name)
|
||||||
if err != nil {
|
framework.ExpectNoError(err)
|
||||||
framework.Logf("unexpected error running %s from %s", cmd, execPod.Name)
|
framework.Logf("Pod client logs: %s", logs)
|
||||||
|
|
||||||
|
logLines := strings.Split(logs, "\n")
|
||||||
|
if len(logLines) < 6 {
|
||||||
|
framework.Logf("only %d log lines, waiting for at least 6", len(logLines))
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
destZone, ok := podsByZone[stdout]
|
|
||||||
|
consecutiveSameZone := 0
|
||||||
|
|
||||||
|
for i := len(logLines) - 1; i > 0; i-- {
|
||||||
|
if logLines[i] == "" || strings.HasPrefix(logLines[i], "Date:") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
destZone, ok := podsByZone[logLines[i]]
|
||||||
if !ok {
|
if !ok {
|
||||||
framework.Logf("could not determine dest zone from output: %s", stdout)
|
framework.Logf("could not determine dest zone from log line: %s", logLines[i])
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
if fromZone != destZone {
|
if fromZone != destZone {
|
||||||
framework.Logf("expected request from %s to stay in %s zone, delivered to %s zone", execPod.Name, fromZone, destZone)
|
framework.Logf("expected request from %s to stay in %s zone, delivered to %s zone", clientPod.Name, fromZone, destZone)
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
consecutiveRequests++
|
|
||||||
if consecutiveRequests < 5 {
|
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
consecutiveSameZone++
|
||||||
|
if consecutiveSameZone >= 5 {
|
||||||
return true, nil
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false, nil
|
||||||
}); pollErr != nil {
|
}); pollErr != nil {
|
||||||
framework.Failf("expected 5 consecutive requests from %s to stay in %s zone %v within %v, stdout: %v", execPod.Name, fromZone, e2eservice.KubeProxyLagTimeout, stdout)
|
framework.Failf("expected 5 consecutive requests from %s to stay in zone %s within %v, stdout: %v", clientPod.Name, fromZone, e2eservice.KubeProxyLagTimeout, logs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user