Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for attaching TCX, TC and XDP programs inside containers. #345

Merged
merged 2 commits into from
Dec 6, 2024

Conversation

anfredette
Copy link
Contributor

To achieve this support, an optional container selector has been added to the TCX, TC and XDP attach info. The agent code then finds the network namespaces of the containers and passes them to bpfman using code that already existed for attaching uprobes inside containers.

One caveat is that GetPrimaryNodeInterface() only finds the primary "node" interface, which may or may not be the name of the primary interface inside of a container. As a side note, it probably works for many cases, especially when running on kind, where both the node's primary interface and containers' primary interfaces are typically named "eth0".

I propose that we leave it as-is for now, and either generalize this function to GetPrimaryInterface(), or add a GetPrimaryPodInterface() when we implement interface discovery. We can also expand the interface selection options to include wildcards and regular expressions at that time.

Copy link

codecov bot commented Dec 4, 2024

Codecov Report

Attention: Patch coverage is 18.04511% with 218 lines in your changes missing coverage. Please review.

Project coverage is 27.10%. Comparing base (db645d4) to head (d5cb7ad).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
controllers/bpfman-agent/tc-program.go 20.77% 58 Missing and 3 partials ⚠️
controllers/bpfman-agent/tcx-program.go 19.73% 58 Missing and 3 partials ⚠️
controllers/bpfman-agent/xdp-program.go 20.54% 55 Missing and 3 partials ⚠️
controllers/bpfman-agent/containers.go 0.00% 17 Missing ⚠️
apis/v1alpha1/zz_generated.deepcopy.go 0.00% 12 Missing and 3 partials ⚠️
controllers/bpfman-agent/uprobe-program.go 25.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #345      +/-   ##
==========================================
- Coverage   27.66%   27.10%   -0.57%     
==========================================
  Files          87       87              
  Lines        7503     7711     +208     
==========================================
+ Hits         2076     2090      +14     
- Misses       5227     5412     +185     
- Partials      200      209       +9     
Flag Coverage Δ
unittests 27.10% <18.04%> (-0.57%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@Billy99 Billy99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I'm testing now, but no real issues.

@@ -97,12 +97,9 @@ spec:
name: mountpoint-dir
- mountPath: /tmp
name: tmp-dir
# host-proc is used to attach programs inside of containers
# Used to attach programs inside of containers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes were added in commit 1, then backed out in commit 2. I assume this was on purpose and the daemonset doesn't need this volume?

}
} else {
for _, iface := range r.interfaces {
attachPoint := iface + "-" + r.currentTcProgram.Spec.Direction
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like patterns, easier to follow. Can you make this of the form attachPoint := fmt.Sprintf("%s-%s", ... like the previous attachPoint creations? Just for readability. Same for other files that do this.

Copy link
Contributor

mergify bot commented Dec 5, 2024

@anfredette, this pull request is now in conflict and requires a rebase.

@mergify mergify bot added the needs-rebase label Dec 5, 2024
Signed-off-by: Andre Fredette <afredette@redhat.com>
GetPrimaryNodeInterface() only finds the primary "node" interface, which
may or may not be the name of the primary interface inside of a container.

Signed-off-by: Andre Fredette <afredette@redhat.com>
@mergify mergify bot removed the needs-rebase label Dec 6, 2024
@Billy99 Billy99 merged commit 1165a8c into bpfman:main Dec 6, 2024
15 checks passed
Billy99 pushed a commit to Billy99/bpfman-operator that referenced this pull request Dec 9, 2024
…bpfman#345)

* Add ContainerSelector to tc, tcx, and xdp programs
* Add netns support for TCX, TC and XDP  programs.

GetPrimaryNodeInterface() only finds the primary "node" interface, which
may or may not be the name of the primary interface inside of a container.

Signed-off-by: Andre Fredette <afredette@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants