ci: increase verbosity of load balancer e2e test (#868)

* ci: increase verbosity of load balancer e2e test
* Enable verbose logging in container for e2e-lb test.

Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
Signed-off-by: Fabian Kammel <fk@edgeless.systems>
Co-authored-by: Fabian Kammel <fk@edgeless.systems>
This commit is contained in:
Paul Meyer 2023-01-05 14:12:53 +01:00 committed by GitHub
parent 9c71145862
commit aaa9e01e55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 9 deletions

View File

@ -35,3 +35,5 @@ spec:
image: traefik/whoami:v1.8.7 image: traefik/whoami:v1.8.7
ports: ports:
- containerPort: 80 - containerPort: 80
args:
- "--verbose"

View File

@ -43,15 +43,17 @@ func TestLoadBalancer(t *testing.T) {
k, err := kubectl.New() k, err := kubectl.New()
require.NoError(err) require.NoError(err)
// Wait for external IP to be registered t.Log("Waiting for external IP to be registered")
svc := testEventuallyExternalIPAvailable(t, k) svc := testEventuallyExternalIPAvailable(t, k)
loadBalancerIP := getIPOrHostname(t, svc) loadBalancerIP := getIPOrHostname(t, svc)
loadBalancerPort := svc.Spec.Ports[0].Port loadBalancerPort := svc.Spec.Ports[0].Port
require.Equal(initialPort, loadBalancerPort) require.Equal(initialPort, loadBalancerPort)
url := buildURL(t, loadBalancerIP, loadBalancerPort) url := buildURL(t, loadBalancerIP, loadBalancerPort)
t.Log("Checking service can be reached through LB")
testEventuallyStatusOK(t, url) testEventuallyStatusOK(t, url)
// Check that all pods receive traffic t.Log("Check that all pods receive traffic")
var allHostnames []string var allHostnames []string
for i := 0; i < numRequests; i++ { for i := 0; i < numRequests; i++ {
allHostnames = testEndpointAvailable(t, url, allHostnames) allHostnames = testEndpointAvailable(t, url, allHostnames)
@ -59,17 +61,17 @@ func TestLoadBalancer(t *testing.T) {
assert.True(hasNUniqueStrings(allHostnames, numPods)) assert.True(hasNUniqueStrings(allHostnames, numPods))
allHostnames = allHostnames[:0] allHostnames = allHostnames[:0]
// Change port to 8044 t.Log("Change port of service to 8044")
svc.Spec.Ports[0].Port = newPort svc.Spec.Ports[0].Port = newPort
svc, err = k.CoreV1().Services(namespaceName).Update(context.Background(), svc, v1.UpdateOptions{}) svc, err = k.CoreV1().Services(namespaceName).Update(context.Background(), svc, v1.UpdateOptions{})
require.NoError(err) require.NoError(err)
assert.Equal(newPort, svc.Spec.Ports[0].Port) assert.Equal(newPort, svc.Spec.Ports[0].Port)
// Wait for changed port to be available t.Log("Wait for changed port to be available")
newURL := buildURL(t, loadBalancerIP, newPort) newURL := buildURL(t, loadBalancerIP, newPort)
testEventuallyStatusOK(t, newURL) testEventuallyStatusOK(t, newURL)
// Check again that all pods receive traffic t.Log("Check again that all pods receive traffic")
for i := 0; i < numRequests; i++ { for i := 0; i < numRequests; i++ {
allHostnames = testEndpointAvailable(t, newURL, allHostnames) allHostnames = testEndpointAvailable(t, newURL, allHostnames)
} }
@ -113,10 +115,19 @@ func testEventuallyStatusOK(t *testing.T, url string) {
resp, err := http.DefaultClient.Do(req) resp, err := http.DefaultClient.Do(req)
if err != nil { if err != nil {
t.Log("Request failed: ", err.Error())
return false return false
} }
defer resp.Body.Close() defer resp.Body.Close()
return resp.StatusCode == http.StatusOK
statusOK := resp.StatusCode == http.StatusOK
if !statusOK {
t.Log("Status not OK: ", resp.StatusCode)
return false
}
t.Log("Status OK")
return true
}, timeout, interval) }, timeout, interval)
} }
@ -129,11 +140,19 @@ func testEventuallyExternalIPAvailable(t *testing.T, k *kubernetes.Clientset) *c
var err error var err error
svc, err = k.CoreV1().Services(namespaceName).Get(context.Background(), serviceName, v1.GetOptions{}) svc, err = k.CoreV1().Services(namespaceName).Get(context.Background(), serviceName, v1.GetOptions{})
if err != nil { if err != nil {
fmt.Println(err) t.Log("Getting service failed: ", err.Error())
return false return false
} }
fmt.Printf("Fetched service: %v\n", svc.String()) t.Log("Successfully fetched service: ", svc.String())
return len(svc.Status.LoadBalancer.Ingress) > 0
ingressAvailable := len(svc.Status.LoadBalancer.Ingress) > 0
if !ingressAvailable {
t.Log("Ingress not yet available")
return false
}
t.Log("Ingress available")
return true
}, timeout, interval) }, timeout, interval)
return svc return svc