forked from bpfman/bpfman
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request bpfman#1041 from anfredette/probe-int-tests
Add kprobe and uprobe k8s integration tests
- Loading branch information
Showing
4 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//go:build integration_tests | ||
// +build integration_tests | ||
|
||
package integration | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"io" | ||
"regexp" | ||
"strconv" | ||
"testing" | ||
"time" | ||
|
||
"github.com/kong/kubernetes-testing-framework/pkg/clusters" | ||
"github.com/stretchr/testify/require" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
const ( | ||
kprobeGoCounterKustomize = "../../../examples/config/default/go-kprobe-counter" | ||
kprobeGoCounterUserspaceNs = "go-kprobe-counter" | ||
kprobeGoCounterUserspaceDsName = "go-kprobe-counter-ds" | ||
) | ||
|
||
func TestKprobeGoCounter(t *testing.T) { | ||
t.Log("deploying kprobe counter program") | ||
require.NoError(t, clusters.KustomizeDeployForCluster(ctx, env.Cluster(), kprobeGoCounterKustomize)) | ||
addCleanup(func(context.Context) error { | ||
cleanupLog("cleaning up kprobe counter program") | ||
return clusters.KustomizeDeleteForCluster(ctx, env.Cluster(), kprobeGoCounterKustomize) | ||
}) | ||
|
||
t.Log("waiting for go kprobe counter userspace daemon to be available") | ||
require.Eventually(t, func() bool { | ||
daemon, err := env.Cluster().Client().AppsV1().DaemonSets(kprobeGoCounterUserspaceNs).Get(ctx, kprobeGoCounterUserspaceDsName, metav1.GetOptions{}) | ||
require.NoError(t, err) | ||
return daemon.Status.DesiredNumberScheduled == daemon.Status.NumberAvailable | ||
}, | ||
// Wait 5 minutes since cosign is slow, https://github.com/bpfman/bpfman/issues/1043 | ||
5*time.Minute, 10*time.Second) | ||
|
||
pods, err := env.Cluster().Client().CoreV1().Pods(kprobeGoCounterUserspaceNs).List(ctx, metav1.ListOptions{LabelSelector: "name=go-kprobe-counter"}) | ||
require.NoError(t, err) | ||
goKprobeCounterPod := pods.Items[0] | ||
|
||
want := regexp.MustCompile(`Kprobe count: ([0-9]+)`) | ||
req := env.Cluster().Client().CoreV1().Pods(kprobeGoCounterUserspaceNs).GetLogs(goKprobeCounterPod.Name, &corev1.PodLogOptions{}) | ||
require.Eventually(t, func() bool { | ||
logs, err := req.Stream(ctx) | ||
require.NoError(t, err) | ||
defer logs.Close() | ||
output := new(bytes.Buffer) | ||
_, err = io.Copy(output, logs) | ||
require.NoError(t, err) | ||
t.Logf("counter pod log %s", output.String()) | ||
|
||
matches := want.FindAllStringSubmatch(output.String(), -1) | ||
if len(matches) >= 1 && len(matches[0]) >= 2 { | ||
count, err := strconv.Atoi(matches[0][1]) | ||
require.NoError(t, err) | ||
if count > 0 { | ||
t.Logf("counted %d kprobe executions so far, BPF program is functioning", count) | ||
return true | ||
} | ||
} | ||
return false | ||
}, 30*time.Second, time.Second) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
//go:build integration_tests | ||
// +build integration_tests | ||
|
||
package integration | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"io" | ||
"regexp" | ||
"strconv" | ||
"testing" | ||
"time" | ||
|
||
"github.com/kong/kubernetes-testing-framework/pkg/clusters" | ||
"github.com/stretchr/testify/require" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
const ( | ||
uprobeGoCounterKustomize = "../../../examples/config/default/go-uprobe-counter" | ||
uprobeGoCounterUserspaceNs = "go-uprobe-counter" | ||
uprobeGoCounterUserspaceDsName = "go-uprobe-counter-ds" | ||
targetKustomize = "../../../examples/config/default/go-target" | ||
targetUserspaceNs = "go-target" | ||
targetUserspaceDsName = "go-target-ds" | ||
) | ||
|
||
func TestUprobeGoCounter(t *testing.T) { | ||
t.Log("deploying target for uprobe counter program") | ||
require.NoError(t, clusters.KustomizeDeployForCluster(ctx, env.Cluster(), targetKustomize)) | ||
addCleanup(func(context.Context) error { | ||
cleanupLog("cleaning up target program") | ||
return clusters.KustomizeDeleteForCluster(ctx, env.Cluster(), targetKustomize) | ||
}) | ||
|
||
t.Log("waiting for go target userspace daemon to be available") | ||
require.Eventually(t, func() bool { | ||
daemon, err := env.Cluster().Client().AppsV1().DaemonSets(targetUserspaceNs).Get(ctx, targetUserspaceDsName, metav1.GetOptions{}) | ||
require.NoError(t, err) | ||
return daemon.Status.DesiredNumberScheduled == daemon.Status.NumberAvailable | ||
}, | ||
// Wait 5 minutes since cosign is slow, https://github.com/bpfman/bpfman/issues/1043 | ||
5*time.Minute, 10*time.Second) | ||
|
||
t.Log("deploying uprobe counter program") | ||
require.NoError(t, clusters.KustomizeDeployForCluster(ctx, env.Cluster(), uprobeGoCounterKustomize)) | ||
addCleanup(func(context.Context) error { | ||
cleanupLog("cleaning up uprobe counter program") | ||
return clusters.KustomizeDeleteForCluster(ctx, env.Cluster(), uprobeGoCounterKustomize) | ||
}) | ||
|
||
t.Log("waiting for go uprobe counter userspace daemon to be available") | ||
require.Eventually(t, func() bool { | ||
daemon, err := env.Cluster().Client().AppsV1().DaemonSets(uprobeGoCounterUserspaceNs).Get(ctx, uprobeGoCounterUserspaceDsName, metav1.GetOptions{}) | ||
require.NoError(t, err) | ||
return daemon.Status.DesiredNumberScheduled == daemon.Status.NumberAvailable | ||
}, | ||
// Wait 5 minutes since cosign is slow, https://github.com/bpfman/bpfman/issues/1043 | ||
5*time.Minute, 10*time.Second) | ||
|
||
pods, err := env.Cluster().Client().CoreV1().Pods(uprobeGoCounterUserspaceNs).List(ctx, metav1.ListOptions{LabelSelector: "name=go-uprobe-counter"}) | ||
require.NoError(t, err) | ||
goUprobeCounterPod := pods.Items[0] | ||
|
||
want := regexp.MustCompile(`Uprobe count: ([0-9]+)`) | ||
req := env.Cluster().Client().CoreV1().Pods(uprobeGoCounterUserspaceNs).GetLogs(goUprobeCounterPod.Name, &corev1.PodLogOptions{}) | ||
require.Eventually(t, func() bool { | ||
logs, err := req.Stream(ctx) | ||
require.NoError(t, err) | ||
defer logs.Close() | ||
output := new(bytes.Buffer) | ||
_, err = io.Copy(output, logs) | ||
require.NoError(t, err) | ||
t.Logf("counter pod log %s", output.String()) | ||
|
||
matches := want.FindAllStringSubmatch(output.String(), -1) | ||
if len(matches) >= 1 && len(matches[0]) >= 2 { | ||
count, err := strconv.Atoi(matches[0][1]) | ||
require.NoError(t, err) | ||
if count > 0 { | ||
t.Logf("counted %d uprobe executions so far, BPF program is functioning", count) | ||
return true | ||
} | ||
} | ||
return false | ||
}, 30*time.Second, time.Second) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
resources: [deployment.yaml] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
# Patch the deployment.yaml to change container image in Daemonset | ||
# to new tag on the image. | ||
images: | ||
- name: quay.io/bpfman-userspace/go-target | ||
newName: quay.io/bpfman-userspace/go-target | ||
newTag: latest | ||
resources: | ||
- ../../base/go-target |