Skip to content

Commit

Permalink
Add controllers for TCX
Browse files Browse the repository at this point in the history
Signed-off-by: Mohamed Mahmoud <[email protected]>
  • Loading branch information
msherif1234 committed Aug 21, 2024
1 parent e7229b3 commit ddc457e
Show file tree
Hide file tree
Showing 16 changed files with 1,062 additions and 74 deletions.
37 changes: 6 additions & 31 deletions apis/v1alpha1/tcxProgram_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,6 @@ type TcxProgramSpec struct {
BpfAppCommon `json:",inline"`
}

// TCXPositionType defines the TCX position string
type TCXPositionType string

const (
// TCXFirst TCX program will be the first program to execute.
TCXFirst TCXPositionType = "First"

// TCXLast TCX program will be the last program to execute.
TCXLast TCXPositionType = "Last"

// TCXBefore TCX program will be before a specific TCX program
TCXBefore TCXPositionType = "Before"

// TCXAfter TCX program will be after a specific TCX program
TCXAfter TCXPositionType = "After"
)

// TcxProgramInfo defines the tc program details
type TcxProgramInfo struct {
BpfProgramCommon `json:",inline"`
Expand All @@ -79,20 +62,12 @@ type TcxProgramInfo struct {
// +kubebuilder:validation:Enum=ingress;egress
Direction string `json:"direction"`

// TargetProgramName defined the existing TCX program that will be used in case we need set this TCX program
// priority against.
//+optional
TargetProgramName string `json:"targetprogramname,omitempty"`

// Position defines the order of the TCX relative to other TCX attached to the same interface
// +kubebuilder:validation:Enum:="First";"Last";"Before";"After"
//+kubebuilder:default:=Last
//+optional
Position TCXPositionType `json:"position,omitempty"`

// ExpectedRevision Attach TCX hook only if the expected revision matches.
//+optional
ExpectedRevision uint64 `json:"expectedRevision,omitempty"`
// Priority specifies the priority of the tc program in relation to
// other programs of the same type with the same attach point. It is a value
// from 0 to 1000 where lower values have higher precedence.
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=1000
Priority int32 `json:"priority"`
}

// TcxProgramStatus defines the observed state of TcProgram
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ rules:
- get
- list
- watch
- apiGroups:
- bpfman.io
resources:
- tcxprograms/finalizers
verbs:
- update
- apiGroups:
- bpfman.io
resources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ metadata:
capabilities: Basic Install
categories: OpenShift Optional
containerImage: quay.io/bpfman/bpfman-operator:v0.0.0
createdAt: "2024-08-21T20:26:18Z"
createdAt: "2024-08-21T20:57:26Z"
features.operators.openshift.io/cnf: "false"
features.operators.openshift.io/cni: "false"
features.operators.openshift.io/csi: "true"
Expand Down
7 changes: 7 additions & 0 deletions cmd/bpfman-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ func main() {
os.Exit(1)
}

if err = (&bpfmanagent.TcxProgramReconciler{
ReconcilerCommon: common,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create tcxProgram controller", "controller", "BpfProgram")
os.Exit(1)
}

if err = (&bpfmanagent.TracepointProgramReconciler{
ReconcilerCommon: common,
}).SetupWithManager(mgr); err != nil {
Expand Down
7 changes: 7 additions & 0 deletions cmd/bpfman-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ func main() {
os.Exit(1)
}

if err = (&bpfmanoperator.TcxProgramReconciler{
ReconcilerCommon: common,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create tcxProgram controller", "controller", "BpfProgram")
os.Exit(1)
}

if err = (&bpfmanoperator.TracepointProgramReconciler{
ReconcilerCommon: common,
}).SetupWithManager(mgr); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions config/bpfman-operator-deployment/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: quay.io/bpfman/bpfman-operator
newName: quay.io/bpfman/bpfman-operator
newTag: latest
newName: quay.io/mmahmoud/bpfman-opertor
newTag: tcx-support
28 changes: 9 additions & 19 deletions config/crd/bases/bpfman.io_bpfapplications.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -590,11 +590,6 @@ spec:
- ingress
- egress
type: string
expectedRevision:
description: ExpectedRevision Attach TCX hook only if the
expected revision matches.
format: int64
type: integer
interfaceselector:
description: Selector to determine the network interface
(or interfaces)
Expand Down Expand Up @@ -663,25 +658,20 @@ spec:
type: object
type: object
x-kubernetes-map-type: atomic
position:
default: Last
description: Position defines the order of the TCX relative
to other TCX attached to the same interface
enum:
- First
- Last
- Before
- After
type: string
targetprogramname:
priority:
description: |-
TargetProgramName defined the existing TCX program that will be used in case we need set this TCX program
priority against.
type: string
Priority specifies the priority of the tc program in relation to
other programs of the same type with the same attach point. It is a value
from 0 to 1000 where lower values have higher precedence.
format: int32
maximum: 1000
minimum: 0
type: integer
required:
- bpffunctionname
- direction
- interfaceselector
- priority
type: object
tracepoint:
description: tracepoint defines the desired state of the application's
Expand Down
28 changes: 9 additions & 19 deletions config/crd/bases/bpfman.io_tcxprograms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,6 @@ spec:
- ingress
- egress
type: string
expectedRevision:
description: ExpectedRevision Attach TCX hook only if the expected
revision matches.
format: int64
type: integer
globaldata:
additionalProperties:
format: byte
Expand Down Expand Up @@ -250,27 +245,22 @@ spec:
type: object
type: object
x-kubernetes-map-type: atomic
position:
default: Last
description: Position defines the order of the TCX relative to other
TCX attached to the same interface
enum:
- First
- Last
- Before
- After
type: string
targetprogramname:
priority:
description: |-
TargetProgramName defined the existing TCX program that will be used in case we need set this TCX program
priority against.
type: string
Priority specifies the priority of the tc program in relation to
other programs of the same type with the same attach point. It is a value
from 0 to 1000 where lower values have higher precedence.
format: int32
maximum: 1000
minimum: 0
type: integer
required:
- bpffunctionname
- bytecode
- direction
- interfaceselector
- nodeselector
- priority
type: object
status:
description: TcxProgramStatus defines the observed state of TcProgram
Expand Down
6 changes: 6 additions & 0 deletions config/rbac/bpfman-agent/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ rules:
- get
- list
- watch
- apiGroups:
- bpfman.io
resources:
- tcxprograms/finalizers
verbs:
- update
- apiGroups:
- bpfman.io
resources:
Expand Down
31 changes: 29 additions & 2 deletions controllers/bpfman-agent/application-program.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ func (r *BpfApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Reque
// Reconcile TracepointProgram.
complete, res, err = r.reconcileCommon(ctx, rec, tracepointObjects)

case bpfmaniov1alpha1.ProgTypeTC,
bpfmaniov1alpha1.ProgTypeTCX:
case bpfmaniov1alpha1.ProgTypeTC:
interfaces, ifErr := getInterfaces(&p.TC.InterfaceSelector, r.ourNode)
if ifErr != nil {
ctxLogger.Error(ifErr, "failed to get interfaces for TC Program",
Expand Down Expand Up @@ -218,6 +217,34 @@ func (r *BpfApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Reque
// Reconcile TcProgram.
complete, res, err = r.reconcileCommon(ctx, rec, tcObjects)

case bpfmaniov1alpha1.ProgTypeTCX:
interfaces, ifErr := getInterfaces(&p.TCX.InterfaceSelector, r.ourNode)
if ifErr != nil {
ctxLogger.Error(ifErr, "failed to get interfaces for TCX Program",
"app program name", a.Name, "program index", j)
continue
}
appProgramId := fmt.Sprintf("%s-%s-%s", strings.ToLower(string(p.Type)), p.TCX.Direction, interfaces[0])
tcxProgram := bpfmaniov1alpha1.TcxProgram{
ObjectMeta: metav1.ObjectMeta{
Name: buildProgramName(a, p),
Labels: map[string]string{internal.AppProgramId: appProgramId}},
Spec: bpfmaniov1alpha1.TcxProgramSpec{
TcxProgramInfo: *p.TCX,
BpfAppCommon: a.Spec.BpfAppCommon,
},
}
rec := &TcxProgramReconciler{
ReconcilerCommon: r.ReconcilerCommon,
currentTcxProgram: &tcxProgram,
ourNode: r.ourNode,
}
rec.appOwner = &a
tcxObjects := []client.Object{&tcxProgram}
appProgramMap[appProgramId] = true
// Reconcile TcxProgram.
complete, res, err = r.reconcileCommon(ctx, rec, tcxObjects)

case bpfmaniov1alpha1.ProgTypeXDP:
interfaces, ifErr := getInterfaces(&p.XDP.InterfaceSelector, r.ourNode)
if ifErr != nil {
Expand Down
1 change: 1 addition & 0 deletions controllers/bpfman-agent/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import (
//+kubebuilder:rbac:groups=bpfman.io,resources=bpfprograms/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=bpfman.io,resources=bpfprograms/finalizers,verbs=update
//+kubebuilder:rbac:groups=bpfman.io,resources=tcprograms/finalizers,verbs=update
//+kubebuilder:rbac:groups=bpfman.io,resources=tcxprograms/finalizers,verbs=update
//+kubebuilder:rbac:groups=bpfman.io,resources=xdpprograms/finalizers,verbs=update
//+kubebuilder:rbac:groups=bpfman.io,resources=tracepointprograms/finalizers,verbs=update
//+kubebuilder:rbac:groups=bpfman.io,resources=kprobeprograms/finalizers,verbs=update
Expand Down
Loading

0 comments on commit ddc457e

Please sign in to comment.