Skip to content

Commit

Permalink
Intg with bpfman tcx PR
Browse files Browse the repository at this point in the history
Signed-off-by: Mohamed Mahmoud <[email protected]>
  • Loading branch information
msherif1234 committed Aug 22, 2024
1 parent ddc457e commit 9e361a8
Show file tree
Hide file tree
Showing 7 changed files with 503 additions and 330 deletions.
6 changes: 2 additions & 4 deletions controllers/bpfman-agent/tcx-program.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package bpfmanagent
import (
"context"
"fmt"

bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1"
bpfmanagentinternal "github.com/bpfman/bpfman-operator/controllers/bpfman-agent/internal"
"github.com/bpfman/bpfman-operator/internal"
Expand Down Expand Up @@ -200,14 +199,13 @@ func (r *TcxProgramReconciler) getLoadRequest(bpfProgram *bpfmaniov1alpha1.BpfPr
if err != nil {
return nil, fmt.Errorf("failed to process bytecode selector: %v", err)
}

Check warning on line 201 in controllers/bpfman-agent/tcx-program.go

View check run for this annotation

Codecov / codecov/patch

controllers/bpfman-agent/tcx-program.go#L200-L201

Added lines #L200 - L201 were not covered by tests

loadRequest := gobpfman.LoadRequest{
Bytecode: bytecode,
Name: r.currentTcxProgram.Spec.BpfFunctionName,
ProgramType: uint32(internal.Tc),
Attach: &gobpfman.AttachInfo{
Info: &gobpfman.AttachInfo_TcAttachInfo{
TcAttachInfo: &gobpfman.TCAttachInfo{
Info: &gobpfman.AttachInfo_TcxAttachInfo{
TcxAttachInfo: &gobpfman.TCXAttachInfo{
Priority: r.currentTcxProgram.Spec.Priority,
Iface: bpfProgram.Annotations[internal.TcxProgramInterface],
Direction: r.currentTcxProgram.Spec.Direction,
Expand Down
20 changes: 10 additions & 10 deletions controllers/bpfman-agent/tcx-program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ func TestTcxProgramControllerCreate(t *testing.T) {
Metadata: map[string]string{internal.UuidMetadataKey: string(uuid), internal.ProgramNameKey: name},
MapOwnerId: nil,
Attach: &gobpfman.AttachInfo{
Info: &gobpfman.AttachInfo_TcAttachInfo{
TcAttachInfo: &gobpfman.TCAttachInfo{
Info: &gobpfman.AttachInfo_TcxAttachInfo{
TcxAttachInfo: &gobpfman.TCXAttachInfo{
Iface: fakeInt,
Priority: 0,
Priority: tcx.Spec.Priority,
Direction: direction,
},
},
Expand Down Expand Up @@ -245,7 +245,7 @@ func TestTcxProgramControllerCreateMultiIntf(t *testing.T) {
InterfaceSelector: bpfmaniov1alpha1.InterfaceSelector{
Interfaces: &fakeInts,
},
Priority: 0,
Priority: 10,
Direction: direction,
},
},
Expand Down Expand Up @@ -386,10 +386,10 @@ func TestTcxProgramControllerCreateMultiIntf(t *testing.T) {
Metadata: map[string]string{internal.UuidMetadataKey: string(uuid0), internal.ProgramNameKey: name},
MapOwnerId: nil,
Attach: &gobpfman.AttachInfo{
Info: &gobpfman.AttachInfo_TcAttachInfo{
TcAttachInfo: &gobpfman.TCAttachInfo{
Info: &gobpfman.AttachInfo_TcxAttachInfo{
TcxAttachInfo: &gobpfman.TCXAttachInfo{
Iface: fakeInts[0],
Priority: 0,
Priority: tcx.Spec.Priority,
Direction: direction,
},
},
Expand All @@ -407,10 +407,10 @@ func TestTcxProgramControllerCreateMultiIntf(t *testing.T) {
Metadata: map[string]string{internal.UuidMetadataKey: string(uuid1), internal.ProgramNameKey: name},
MapOwnerId: nil,
Attach: &gobpfman.AttachInfo{
Info: &gobpfman.AttachInfo_TcAttachInfo{
TcAttachInfo: &gobpfman.TCAttachInfo{
Info: &gobpfman.AttachInfo_TcxAttachInfo{
TcxAttachInfo: &gobpfman.TCXAttachInfo{
Iface: fakeInts[1],
Priority: 0,
Priority: tcx.Spec.Priority,
Direction: direction,
},
},
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,6 @@ require (
sigs.k8s.io/kind v0.23.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
)

// HACK
replace github.com/bpfman/bpfman => github.com/anfredette/bpfman v0.0.0-20240821132158-413bb6317dc7
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
github.com/anfredette/bpfman v0.0.0-20240821132158-413bb6317dc7 h1:kBumFY1Q0YroS4sDmMS38USu0gbXDv8AGj2fLNwloLY=
github.com/anfredette/bpfman v0.0.0-20240821132158-413bb6317dc7/go.mod h1:ZBZc5wo+lEQA+w/89Sbjaw5VhuvuLTDS3a3yDjOl81o=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/bpfman/bpfman v0.5.1 h1:nYZl1U5yYj9EFIEUBprcBjIzxeXEI7RylRyyf6erg5k=
github.com/bpfman/bpfman v0.5.1/go.mod h1:ZBZc5wo+lEQA+w/89Sbjaw5VhuvuLTDS3a3yDjOl81o=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
Expand Down
59 changes: 59 additions & 0 deletions test/integration/tcx_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//go:build integration_tests
// +build integration_tests

package integration

import (
"bytes"
"context"
"io"
"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 (
tcxGoCounterKustomize = "https://github.com/bpfman/bpfman/examples/config/default/go-tcx-counter/?timeout=120&ref=main"
tcxGoCounterUserspaceNs = "go-tcx-counter"
tcxGoCounterUserspaceDsName = "go-tcx-counter-ds"
)

func TestTcxGoCounter(t *testing.T) {
t.Log("deploying tcx counter program")
require.NoError(t, clusters.KustomizeDeployForCluster(ctx, env.Cluster(), tcxGoCounterKustomize))
addCleanup(func(context.Context) error {
cleanupLog("cleaning up tcx counter program")
return clusters.KustomizeDeleteForCluster(ctx, env.Cluster(), tcxGoCounterKustomize)
})

t.Log("waiting for go tcx counter userspace daemon to be available")
require.Eventually(t, func() bool {
daemon, err := env.Cluster().Client().AppsV1().DaemonSets(tcxGoCounterUserspaceNs).Get(ctx, tcxGoCounterUserspaceDsName, 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(tcxGoCounterUserspaceNs).List(ctx, metav1.ListOptions{LabelSelector: "name=go-tcx-counter"})
require.NoError(t, err)
gotcCounterPod := pods.Items[0]

req := env.Cluster().Client().CoreV1().Pods(tcxGoCounterUserspaceNs).GetLogs(gotcCounterPod.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())

return doTcCheck(t, output)
}, 30*time.Second, time.Second)
}
Loading

0 comments on commit 9e361a8

Please sign in to comment.