Skip to content

Commit cd301fc

Browse files
authored
Merge pull request #407 from msherif1234/test-newapis
Add back xdp go counter
2 parents 0262c86 + a43ea20 commit cd301fc

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

test/integration/xdp_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//go:build integration_tests
2+
// +build integration_tests
3+
4+
package integration
5+
6+
import (
7+
"bytes"
8+
"context"
9+
"io"
10+
"testing"
11+
"time"
12+
13+
"github.com/kong/kubernetes-testing-framework/pkg/clusters"
14+
"github.com/stretchr/testify/require"
15+
corev1 "k8s.io/api/core/v1"
16+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
17+
)
18+
19+
const (
20+
xdpGoCounterKustomize = "https://github.com/bpfman/bpfman/examples/config/default/go-xdp-counter/?timeout=120&ref=main"
21+
xdpGoCounterUserspaceNs = "go-xdp-counter"
22+
xdpGoCounterUserspaceDsName = "go-xdp-counter-ds"
23+
)
24+
25+
func TestXdpGoCounter(t *testing.T) {
26+
t.Log("deploying xdp counter program")
27+
require.NoError(t, clusters.KustomizeDeployForCluster(ctx, env.Cluster(), xdpGoCounterKustomize))
28+
addCleanup(func(context.Context) error {
29+
cleanupLog("cleaning up xdp counter program")
30+
return clusters.KustomizeDeleteForCluster(ctx, env.Cluster(), xdpGoCounterKustomize)
31+
})
32+
33+
t.Log("waiting for go xdp counter userspace daemon to be available")
34+
require.Eventually(t, func() bool {
35+
daemon, err := env.Cluster().Client().AppsV1().DaemonSets(xdpGoCounterUserspaceNs).Get(ctx, xdpGoCounterUserspaceDsName, metav1.GetOptions{})
36+
require.NoError(t, err)
37+
return daemon.Status.DesiredNumberScheduled == daemon.Status.NumberAvailable
38+
},
39+
// Wait 5 minutes since cosign is slow, https://github.com/bpfman/bpfman/issues/1043
40+
5*time.Minute, 10*time.Second)
41+
42+
pods, err := env.Cluster().Client().CoreV1().Pods(xdpGoCounterUserspaceNs).List(ctx, metav1.ListOptions{LabelSelector: "name=go-xdp-counter"})
43+
require.NoError(t, err)
44+
goXdpCounterPod := pods.Items[0]
45+
46+
req := env.Cluster().Client().CoreV1().Pods(xdpGoCounterUserspaceNs).GetLogs(goXdpCounterPod.Name, &corev1.PodLogOptions{})
47+
48+
require.Eventually(t, func() bool {
49+
logs, err := req.Stream(ctx)
50+
require.NoError(t, err)
51+
defer logs.Close()
52+
output := new(bytes.Buffer)
53+
_, err = io.Copy(output, logs)
54+
require.NoError(t, err)
55+
t.Logf("counter pod log %s", output.String())
56+
57+
return doXdpCheck(t, output)
58+
}, 30*time.Second, time.Second)
59+
}

0 commit comments

Comments
 (0)