Skip to content

Commit 95e4b42

Browse files
authored
Merge pull request #421 from msherif1234/intf-regex
Add intefaces match and regex filter to autodiscovery configs
2 parents c9a232d + 978efd1 commit 95e4b42

13 files changed

+287
-38
lines changed

apis/v1alpha1/shared_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ type InterfaceDiscovery struct {
3232
//+kubebuilder:default:={"lo"}
3333
//+optional
3434
ExcludeInterfaces []string `json:"excludeInterfaces,omitempty"`
35+
36+
// allowedInterfaces contains the interface names. If empty, the agent
37+
// fetches all the interfaces in the system, excepting the ones listed in `excludeInterfaces`.
38+
// An entry enclosed by slashes, such as `/br-/`, is matched as a regular expression.
39+
// Otherwise, it is matched as a case-sensitive string.
40+
//+optional
41+
AllowedInterfaces []string `json:"allowedInterfaces,omitempty"`
3542
}
3643

3744
// InterfaceSelector defines interface to attach to.

apis/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundle/manifests/bpfman-operator.clusterserviceversion.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ metadata:
844844
capabilities: Basic Install
845845
categories: OpenShift Optional
846846
containerImage: quay.io/bpfman/bpfman-operator:latest
847-
createdAt: "2025-03-26T15:27:51Z"
847+
createdAt: "2025-03-26T18:33:33Z"
848848
description: The bpfman Operator is designed to manage eBPF programs for applications.
849849
features.operators.openshift.io/cnf: "false"
850850
features.operators.openshift.io/cni: "false"

bundle/manifests/bpfman.io_bpfapplications.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,15 @@ spec:
257257
description: discoveryConfig allow configuring
258258
interface discovery functionality,
259259
properties:
260+
allowedInterfaces:
261+
description: |-
262+
allowedInterfaces contains the interface names. If empty, the agent
263+
fetches all the interfaces in the system, excepting the ones listed in `excludeInterfaces`.
264+
An entry enclosed by slashes, such as `/br-/`, is matched as a regular expression.
265+
Otherwise, it is matched as a case-sensitive string.
266+
items:
267+
type: string
268+
type: array
260269
excludeInterfaces:
261270
default:
262271
- lo
@@ -410,6 +419,15 @@ spec:
410419
description: discoveryConfig allow configuring
411420
interface discovery functionality,
412421
properties:
422+
allowedInterfaces:
423+
description: |-
424+
allowedInterfaces contains the interface names. If empty, the agent
425+
fetches all the interfaces in the system, excepting the ones listed in `excludeInterfaces`.
426+
An entry enclosed by slashes, such as `/br-/`, is matched as a regular expression.
427+
Otherwise, it is matched as a case-sensitive string.
428+
items:
429+
type: string
430+
type: array
413431
excludeInterfaces:
414432
default:
415433
- lo
@@ -746,6 +764,15 @@ spec:
746764
description: discoveryConfig allow configuring
747765
interface discovery functionality,
748766
properties:
767+
allowedInterfaces:
768+
description: |-
769+
allowedInterfaces contains the interface names. If empty, the agent
770+
fetches all the interfaces in the system, excepting the ones listed in `excludeInterfaces`.
771+
An entry enclosed by slashes, such as `/br-/`, is matched as a regular expression.
772+
Otherwise, it is matched as a case-sensitive string.
773+
items:
774+
type: string
775+
type: array
749776
excludeInterfaces:
750777
default:
751778
- lo

bundle/manifests/bpfman.io_clusterbpfapplications.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,15 @@ spec:
374374
description: discoveryConfig allow configuring
375375
interface discovery functionality,
376376
properties:
377+
allowedInterfaces:
378+
description: |-
379+
allowedInterfaces contains the interface names. If empty, the agent
380+
fetches all the interfaces in the system, excepting the ones listed in `excludeInterfaces`.
381+
An entry enclosed by slashes, such as `/br-/`, is matched as a regular expression.
382+
Otherwise, it is matched as a case-sensitive string.
383+
items:
384+
type: string
385+
type: array
377386
excludeInterfaces:
378387
default:
379388
- lo
@@ -529,6 +538,15 @@ spec:
529538
description: discoveryConfig allow configuring
530539
interface discovery functionality,
531540
properties:
541+
allowedInterfaces:
542+
description: |-
543+
allowedInterfaces contains the interface names. If empty, the agent
544+
fetches all the interfaces in the system, excepting the ones listed in `excludeInterfaces`.
545+
An entry enclosed by slashes, such as `/br-/`, is matched as a regular expression.
546+
Otherwise, it is matched as a case-sensitive string.
547+
items:
548+
type: string
549+
type: array
532550
excludeInterfaces:
533551
default:
534552
- lo
@@ -901,6 +919,15 @@ spec:
901919
description: discoveryConfig allow configuring
902920
interface discovery functionality,
903921
properties:
922+
allowedInterfaces:
923+
description: |-
924+
allowedInterfaces contains the interface names. If empty, the agent
925+
fetches all the interfaces in the system, excepting the ones listed in `excludeInterfaces`.
926+
An entry enclosed by slashes, such as `/br-/`, is matched as a regular expression.
927+
Otherwise, it is matched as a case-sensitive string.
928+
items:
929+
type: string
930+
type: array
904931
excludeInterfaces:
905932
default:
906933
- lo

config/crd/bases/bpfman.io_bpfapplications.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,15 @@ spec:
257257
description: discoveryConfig allow configuring
258258
interface discovery functionality,
259259
properties:
260+
allowedInterfaces:
261+
description: |-
262+
allowedInterfaces contains the interface names. If empty, the agent
263+
fetches all the interfaces in the system, excepting the ones listed in `excludeInterfaces`.
264+
An entry enclosed by slashes, such as `/br-/`, is matched as a regular expression.
265+
Otherwise, it is matched as a case-sensitive string.
266+
items:
267+
type: string
268+
type: array
260269
excludeInterfaces:
261270
default:
262271
- lo
@@ -410,6 +419,15 @@ spec:
410419
description: discoveryConfig allow configuring
411420
interface discovery functionality,
412421
properties:
422+
allowedInterfaces:
423+
description: |-
424+
allowedInterfaces contains the interface names. If empty, the agent
425+
fetches all the interfaces in the system, excepting the ones listed in `excludeInterfaces`.
426+
An entry enclosed by slashes, such as `/br-/`, is matched as a regular expression.
427+
Otherwise, it is matched as a case-sensitive string.
428+
items:
429+
type: string
430+
type: array
413431
excludeInterfaces:
414432
default:
415433
- lo
@@ -746,6 +764,15 @@ spec:
746764
description: discoveryConfig allow configuring
747765
interface discovery functionality,
748766
properties:
767+
allowedInterfaces:
768+
description: |-
769+
allowedInterfaces contains the interface names. If empty, the agent
770+
fetches all the interfaces in the system, excepting the ones listed in `excludeInterfaces`.
771+
An entry enclosed by slashes, such as `/br-/`, is matched as a regular expression.
772+
Otherwise, it is matched as a case-sensitive string.
773+
items:
774+
type: string
775+
type: array
749776
excludeInterfaces:
750777
default:
751778
- lo

config/crd/bases/bpfman.io_clusterbpfapplications.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,15 @@ spec:
374374
description: discoveryConfig allow configuring
375375
interface discovery functionality,
376376
properties:
377+
allowedInterfaces:
378+
description: |-
379+
allowedInterfaces contains the interface names. If empty, the agent
380+
fetches all the interfaces in the system, excepting the ones listed in `excludeInterfaces`.
381+
An entry enclosed by slashes, such as `/br-/`, is matched as a regular expression.
382+
Otherwise, it is matched as a case-sensitive string.
383+
items:
384+
type: string
385+
type: array
377386
excludeInterfaces:
378387
default:
379388
- lo
@@ -529,6 +538,15 @@ spec:
529538
description: discoveryConfig allow configuring
530539
interface discovery functionality,
531540
properties:
541+
allowedInterfaces:
542+
description: |-
543+
allowedInterfaces contains the interface names. If empty, the agent
544+
fetches all the interfaces in the system, excepting the ones listed in `excludeInterfaces`.
545+
An entry enclosed by slashes, such as `/br-/`, is matched as a regular expression.
546+
Otherwise, it is matched as a case-sensitive string.
547+
items:
548+
type: string
549+
type: array
532550
excludeInterfaces:
533551
default:
534552
- lo
@@ -901,6 +919,15 @@ spec:
901919
description: discoveryConfig allow configuring
902920
interface discovery functionality,
903921
properties:
922+
allowedInterfaces:
923+
description: |-
924+
allowedInterfaces contains the interface names. If empty, the agent
925+
fetches all the interfaces in the system, excepting the ones listed in `excludeInterfaces`.
926+
An entry enclosed by slashes, such as `/br-/`, is matched as a regular expression.
927+
Otherwise, it is matched as a case-sensitive string.
928+
items:
929+
type: string
930+
type: array
904931
excludeInterfaces:
905932
default:
906933
- lo

config/samples/bpfman.io_v1alpha1_clusterbpfapplication_with_intf_discovery.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ spec:
2525
- interfaceSelector:
2626
interfacesDiscoveryConfig:
2727
interfaceAutoDiscovery: true
28+
allowedInterfaces:
29+
- "/veth*/"
2830
direction: Ingress
2931
- name: tcx_next_test
3032
type: TCX

controllers/bpfman-agent/cl_tc_program.go

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -322,19 +322,39 @@ func (r *ClTcProgramReconciler) getExpectedLinks(ctx context.Context, attachInfo
322322
}
323323
} else {
324324
for _, iface := range interfaces {
325-
link := bpfmaniov1alpha1.ClTcAttachInfoState{
326-
AttachInfoStateCommon: bpfmaniov1alpha1.AttachInfoStateCommon{
327-
ShouldAttach: true,
328-
UUID: uuid.New().String(),
329-
LinkId: nil,
330-
LinkStatus: bpfmaniov1alpha1.ApAttachNotAttached,
331-
},
332-
InterfaceName: iface,
333-
Priority: attachInfo.Priority,
334-
Direction: attachInfo.Direction,
335-
ProceedOn: attachInfo.ProceedOn,
325+
netnsList := getInterfaceNetNsList(&attachInfo.InterfaceSelector, iface, r.Interfaces)
326+
if len(netnsList) == 0 {
327+
link := bpfmaniov1alpha1.ClTcAttachInfoState{
328+
AttachInfoStateCommon: bpfmaniov1alpha1.AttachInfoStateCommon{
329+
ShouldAttach: true,
330+
UUID: uuid.New().String(),
331+
LinkId: nil,
332+
LinkStatus: bpfmaniov1alpha1.ApAttachNotAttached,
333+
},
334+
InterfaceName: iface,
335+
Priority: attachInfo.Priority,
336+
Direction: attachInfo.Direction,
337+
ProceedOn: attachInfo.ProceedOn,
338+
}
339+
nodeLinks = append(nodeLinks, link)
340+
} else {
341+
for _, netns := range netnsList[iface] {
342+
link := bpfmaniov1alpha1.ClTcAttachInfoState{
343+
AttachInfoStateCommon: bpfmaniov1alpha1.AttachInfoStateCommon{
344+
ShouldAttach: true,
345+
UUID: uuid.New().String(),
346+
LinkId: nil,
347+
LinkStatus: bpfmaniov1alpha1.ApAttachNotAttached,
348+
},
349+
InterfaceName: iface,
350+
Priority: attachInfo.Priority,
351+
Direction: attachInfo.Direction,
352+
ProceedOn: attachInfo.ProceedOn,
353+
NetnsPath: netns,
354+
}
355+
nodeLinks = append(nodeLinks, link)
356+
}
336357
}
337-
nodeLinks = append(nodeLinks, link)
338358
}
339359
}
340360

controllers/bpfman-agent/cl_tcx_program.go

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -284,18 +284,37 @@ func (r *ClTcxProgramReconciler) getExpectedLinks(ctx context.Context, attachInf
284284
}
285285
} else {
286286
for _, iface := range interfaces {
287-
link := bpfmaniov1alpha1.ClTcxAttachInfoState{
288-
AttachInfoStateCommon: bpfmaniov1alpha1.AttachInfoStateCommon{
289-
ShouldAttach: true,
290-
UUID: uuid.New().String(),
291-
LinkId: nil,
292-
LinkStatus: bpfmaniov1alpha1.ApAttachNotAttached,
293-
},
294-
InterfaceName: iface,
295-
Priority: attachInfo.Priority,
296-
Direction: attachInfo.Direction,
287+
netnsList := getInterfaceNetNsList(&attachInfo.InterfaceSelector, iface, r.Interfaces)
288+
if len(netnsList) == 0 {
289+
link := bpfmaniov1alpha1.ClTcxAttachInfoState{
290+
AttachInfoStateCommon: bpfmaniov1alpha1.AttachInfoStateCommon{
291+
ShouldAttach: true,
292+
UUID: uuid.New().String(),
293+
LinkId: nil,
294+
LinkStatus: bpfmaniov1alpha1.ApAttachNotAttached,
295+
},
296+
InterfaceName: iface,
297+
Priority: attachInfo.Priority,
298+
Direction: attachInfo.Direction,
299+
}
300+
nodeLinks = append(nodeLinks, link)
301+
} else {
302+
for _, netns := range netnsList[iface] {
303+
link := bpfmaniov1alpha1.ClTcxAttachInfoState{
304+
AttachInfoStateCommon: bpfmaniov1alpha1.AttachInfoStateCommon{
305+
ShouldAttach: true,
306+
UUID: uuid.New().String(),
307+
LinkId: nil,
308+
LinkStatus: bpfmaniov1alpha1.ApAttachNotAttached,
309+
},
310+
InterfaceName: iface,
311+
Priority: attachInfo.Priority,
312+
Direction: attachInfo.Direction,
313+
NetnsPath: netns,
314+
}
315+
nodeLinks = append(nodeLinks, link)
316+
}
297317
}
298-
nodeLinks = append(nodeLinks, link)
299318
}
300319
}
301320

0 commit comments

Comments
 (0)