Skip to content

Commit 5890ce6

Browse files
committed
Merge branch 'master' into server-counter-e2e
2 parents 23a6ed2 + 4171b34 commit 5890ce6

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

e2e/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# End-to-end tests for konnectivity-network-proxy running in a kind cluster
2+
3+
These e2e tests deploy the KNP agent and server to a local [kind](https://kind.sigs.k8s.io/)
4+
cluster to verify their functionality.
5+
6+
These can be run automatically using `make e2e-test`.
7+
8+
## Setup in `main_test.go`
9+
10+
Before any of the actual tests are run, the `TestMain()` function
11+
in `main_test.go` performs the following set up steps:
12+
13+
- Spin up a new kind cluster with the node image provided by the `-kind-image` flag.
14+
- Sideload the KNP agent and server images provided with `-agent-image` and `-server-image` into the cluster.
15+
- Deploy the necessary RBAC and service templates for both the KNP agent and server (see `renderAndApplyManifests`).
16+
17+
## The tests
18+
19+
### `static_count_test.go`
20+
21+
These tests deploy the KNP servers and agents to the previously created kind cluster.
22+
After the deployments are up, the tests check that both the agent and server report
23+
the correct number of connections on their metrics endpoints.

e2e/metrics_assertions_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ func getMetricsGaugeValue(restCfg *rest.Config, namespace string, podName string
3535

3636
metricsParser := &expfmt.TextParser{}
3737
metricsFamilies, err := metricsParser.TextToMetricFamilies(resp.Body)
38-
defer resp.Body.Close()
3938
if err != nil {
4039
return 0, fmt.Errorf("could not parse metrics: %w", err)
4140
}
41+
defer resp.Body.Close()
4242

4343
metricFamily, exists := metricsFamilies[metricName]
4444
if !exists {
@@ -56,7 +56,7 @@ func assertAgentsAreConnected(expectedConnections int) func(context.Context, *te
5656
agentPods := &corev1.PodList{}
5757
err := client.Resources().List(ctx, agentPods, resources.WithLabelSelector("k8s-app=konnectivity-agent"))
5858
if err != nil {
59-
t.Fatalf("couldn't get agent pods: %v", err)
59+
t.Fatalf("couldn't get agent pods (label selector 'k8s-app=konnectivity-agent'): %v", err)
6060
}
6161

6262
for _, agentPod := range agentPods.Items {
@@ -66,7 +66,7 @@ func assertAgentsAreConnected(expectedConnections int) func(context.Context, *te
6666
}
6767

6868
if numConnections != expectedConnections {
69-
t.Errorf("incorrect number of connected servers (want: %v, got: %v)", expectedConnections, numConnections)
69+
t.Errorf("incorrect number of connected servers (want: %d, got: %d)", expectedConnections, numConnections)
7070
}
7171
}
7272

@@ -81,7 +81,7 @@ func assertServersAreConnected(expectedConnections int) func(context.Context, *t
8181
serverPods := &corev1.PodList{}
8282
err := client.Resources().List(ctx, serverPods, resources.WithLabelSelector("k8s-app=konnectivity-server"))
8383
if err != nil {
84-
t.Fatalf("couldn't get server pods: %v", err)
84+
t.Fatalf("couldn't get server pods (label selector 'k8s-app=konnectivity-server'): %v", err)
8585
}
8686

8787
for _, serverPod := range serverPods.Items {
@@ -91,7 +91,7 @@ func assertServersAreConnected(expectedConnections int) func(context.Context, *t
9191
}
9292

9393
if numConnections != expectedConnections {
94-
t.Errorf("incorrect number of connected agents (want: %v, got: %v)", expectedConnections, numConnections)
94+
t.Errorf("incorrect number of connected agents (want: %d, got: %d)", expectedConnections, numConnections)
9595
}
9696
}
9797

0 commit comments

Comments
 (0)