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 <mmahmoud@redhat.com>
  • Loading branch information
msherif1234 committed Aug 14, 2024
1 parent c8df9b6 commit 4290d9a
Show file tree
Hide file tree
Showing 6 changed files with 557 additions and 337 deletions.
15 changes: 11 additions & 4 deletions controllers/bpfman-agent/tcx-program.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package bpfmanagent
import (
"context"
"fmt"
"k8s.io/utils/ptr"

bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1"
bpfmanagentinternal "github.com/bpfman/bpfman-operator/controllers/bpfman-agent/internal"
Expand Down Expand Up @@ -200,15 +201,21 @@ 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 203 in controllers/bpfman-agent/tcx-program.go

View check run for this annotation

Codecov / codecov/patch

controllers/bpfman-agent/tcx-program.go#L202-L203

Added lines #L202 - L203 were not covered by tests

action := "last"
// Only if priority set to 0 we mark this program as first for any other value will be marked as "last"
if r.currentTcxProgram.Spec.Priority == 0 {
action = "first"
}
loadRequest := gobpfman.LoadRequest{
Bytecode: bytecode,
Name: r.currentTcxProgram.Spec.BpfFunctionName,
ProgramType: uint32(internal.Tc),
Attach: &gobpfman.AttachInfo{
Info: &gobpfman.AttachInfo_TcAttachInfo{
TcAttachInfo: &gobpfman.TCAttachInfo{
Priority: r.currentTcxProgram.Spec.Priority,
Info: &gobpfman.AttachInfo_TcxAttachInfo{
TcxAttachInfo: &gobpfman.TCXAttachInfo{
LinkOrder: &gobpfman.LinkOrder{
Action: ptr.To[string](action),
},
Iface: bpfProgram.Annotations[internal.TcxProgramInterface],
Direction: r.currentTcxProgram.Spec.Direction,
},
Expand Down
33 changes: 20 additions & 13 deletions controllers/bpfman-agent/tcx-program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package bpfmanagent

import (
"context"
"k8s.io/utils/ptr"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -167,10 +168,12 @@ 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{
Iface: fakeInt,
Priority: 0,
Info: &gobpfman.AttachInfo_TcxAttachInfo{
TcxAttachInfo: &gobpfman.TCXAttachInfo{
Iface: fakeInt,
LinkOrder: &gobpfman.LinkOrder{
Action: ptr.To[string]("first"),
},
Direction: direction,
},
},
Expand Down Expand Up @@ -245,7 +248,7 @@ func TestTcxProgramControllerCreateMultiIntf(t *testing.T) {
InterfaceSelector: bpfmaniov1alpha1.InterfaceSelector{
Interfaces: &fakeInts,
},
Priority: 0,
Priority: 10,
Direction: direction,
},
},
Expand Down Expand Up @@ -386,10 +389,12 @@ 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{
Iface: fakeInts[0],
Priority: 0,
Info: &gobpfman.AttachInfo_TcxAttachInfo{
TcxAttachInfo: &gobpfman.TCXAttachInfo{
Iface: fakeInts[0],
LinkOrder: &gobpfman.LinkOrder{
Action: ptr.To[string]("last"),
},
Direction: direction,
},
},
Expand All @@ -407,10 +412,12 @@ 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{
Iface: fakeInts[1],
Priority: 0,
Info: &gobpfman.AttachInfo_TcxAttachInfo{
TcxAttachInfo: &gobpfman.TCXAttachInfo{
Iface: fakeInts[1],
LinkOrder: &gobpfman.LinkOrder{
Action: ptr.To[string]("last"),
},
Direction: direction,
},
},
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,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-20240813140850-1c5cfc1fdc6b
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-20240813140850-1c5cfc1fdc6b h1:zzAlgnksNpGE9cmZPKmeL/ia2wQLvSVJFJzKhaMRNFw=
github.com/anfredette/bpfman v0.0.0-20240813140850-1c5cfc1fdc6b/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.0 h1:Q4RCeP8EM95AJKyFc2fhiPog3TzWVqrCS3lj19M7FoE=
github.com/bpfman/bpfman v0.5.0/go.mod h1:AizsT1VkMu7ddVT/7RzUcz83smfDuh0FRgzhkZHj6ZE=
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
Loading

0 comments on commit 4290d9a

Please sign in to comment.