Skip to content

gvforwarder as a systemd service #1052

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

Merged
merged 2 commits into from
May 16, 2025

Conversation

praveenkumar
Copy link
Member

@praveenkumar praveenkumar commented Apr 29, 2025

  • Create a tap device using nmcli with a hardcoded mac address
  • Start gvforwarder systemd service which will use this device

Summary by Sourcery

Configure gvforwarder (gvisor-tap-vsock) to run as a native systemd service instead of a container.

Build:

  • Create a tap0 network interface using nmcli with a fixed MAC address during VM setup.
  • Install the gvforwarder binary directly onto the host system.
  • Configure and enable a native systemd service (gv-user-network@.service) to manage the gvforwarder process.
  • Remove the previous container-based systemd service for gvisor-tap-vsock.

Copy link

sourcery-ai bot commented Apr 29, 2025

Reviewer's Guide by Sourcery

This pull request refactors the setup for the gvisor-tap-vsock forwarder. It adds the creation of a tap device using nmcli before setting up the service. The approach for running the forwarder is changed from generating a systemd service directly from a podman container to extracting the forwarder binary from the container and running it via a custom systemd service template unit.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Create a tap device interface using nmcli.
  • Add nmcli command to create a 'tun' type connection named 'tap0' with a specific MAC address.
createdisk.sh
Refactor gvisor-tap-vsock setup to use a custom systemd service template.
  • Remove old podman create and generate systemd commands.
  • Add podman create command to get the image.
  • Add podman cp command to copy the gvforwarder binary.
  • Add podman rm command to clean up the temporary container.
  • Add tee command to write the custom gv-user-network@.service unit file.
  • Remove old systemctl enable for the podman-generated service.
  • Add systemctl enable for the new gv-user-network@tap0.service instance.
createdisk.sh

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@openshift-ci openshift-ci bot requested review from cfergeau and gbraad April 29, 2025 11:33
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @praveenkumar - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider making the hardcoded MAC address 5A:94:EF:E4:0C:EE configurable instead of embedding it directly in the script.
  • Extracting the gvforwarder binary from a container might be fragile; consider alternative methods like packaging or building from source.
  • Creating the systemd unit file via a tee heredoc could be replaced by copying a dedicated unit file for better readability.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +97 to +102
# create the tap device interface with specified mac address
# this mac address is used to allocate a specific IP to the VM
# when tap device is in use.
${SSH} core@${VM_IP} 'sudo bash -x -s' <<EOF
nmcli connection add type tun ifname tap0 con-name tap0 mode tap autoconnect yes 802-3-ethernet.cloned-mac-address 5A:94:EF:E4:0C:EE
EOF
Copy link

Choose a reason for hiding this comment

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

suggestion (bug_risk): Consider handling potential errors when adding the tap device.

Capture and check the nmcli command’s exit status (e.g., check $?) so any failures in creating the tap interface are detected and handled.

Suggested change
# create the tap device interface with specified mac address
# this mac address is used to allocate a specific IP to the VM
# when tap device is in use.
${SSH} core@${VM_IP} 'sudo bash -x -s' <<EOF
nmcli connection add type tun ifname tap0 con-name tap0 mode tap autoconnect yes 802-3-ethernet.cloned-mac-address 5A:94:EF:E4:0C:EE
EOF
# create the tap device interface with specified mac address
# this mac address is used to allocate a specific IP to the VM
# when tap device is in use.
${SSH} core@${VM_IP} 'sudo bash -x -s' <<EOF
nmcli connection add type tun ifname tap0 con-name tap0 mode tap autoconnect yes 802-3-ethernet.cloned-mac-address 5A:94:EF:E4:0C:EE
status=\$?
if [ \$status -ne 0 ]; then
echo "Error: Failed to add tap device interface. nmcli exit status: \$status"
exit \$status
fi
EOF

@praveenkumar
Copy link
Member Author

/retest

@cfergeau
Copy link
Contributor

Is it the same as #1003 but against a different branch? or are there some differences?

@praveenkumar
Copy link
Member Author

Is it the same as #1003 but against a different branch? or are there some differences?

It is same but against release-4.18 branch.

@praveenkumar
Copy link
Member Author

/retest

Description=gvisor-tap-vsock Network Traffic Forwarder
After=NetworkManager.service
BindsTo=sys-devices-virtual-net-%i.device
After=sys-devices-virtual-net-%i.device
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to add Before=nodeip-configuration.service as in #1054 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know but I can try to do that also.

tee /etc/systemd/system/gv-user-network@.service <<TEE
[Unit]
Description=gvisor-tap-vsock Network Traffic Forwarder
After=NetworkManager.service
Copy link
Member

Choose a reason for hiding this comment

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

Should this be Before=NetworkManager.service ? otherwise it starts very late after boot

Copy link
Member Author

Choose a reason for hiding this comment

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

@anjannath networkManager is responsible to activate tun/tap device so it that is not even active how would this work.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be Before=NetworkManager.service ? otherwise it starts very late after boot

Is it NetworkManager.service which would start late? or network-online?
Since we have After=sys-devices-virtual-net-%i.device , do we even need the reference to NetworkManager.service?

Copy link
Collaborator

@gbraad gbraad May 12, 2025

Choose a reason for hiding this comment

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

I spoke with Anjan, and the TAP creation should be independent of the network which configures. But the current, After is too undetermined, as it can start at any point after; anything with priority or dependency goes first.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In short, rather use Before than After statements, as that ensures the order.

Copy link

openshift-ci bot commented May 13, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from praveenkumar. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

vyasgun and others added 2 commits May 13, 2025 21:03
- Create a tap device using nmcli with a hardcoded mac address
- Start gvforwarder systemd service which will use this device

Signed-off-by: vyasgun <vyasgun20@gmail.com>
Signed-off-by: Praveen Kumar <kumarpraveen.nitdgp@gmail.com>
@praveenkumar praveenkumar force-pushed the gvforwarder-service branch from 7669205 to f04603b Compare May 13, 2025 15:34
@praveenkumar
Copy link
Member Author

/retest

@@ -16,7 +16,7 @@ INSTALL_DIR=${1:-crc-tmp-install-data}
OPENSHIFT_VERSION=$(${JQ} -r .clusterInfo.openshiftVersion $INSTALL_DIR/crc-bundle-info.json)
BASE_DOMAIN=$(${JQ} -r .clusterInfo.baseDomain $INSTALL_DIR/crc-bundle-info.json)
BUNDLE_TYPE=$(${JQ} -r .type $INSTALL_DIR/crc-bundle-info.json)
ADDITIONAL_PACKAGES="cloud-init"
ADDITIONAL_PACKAGES="cloud-init gvisor-tap-vsock-gvforwarder"
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Copy link
Collaborator

@gbraad gbraad May 14, 2025

Choose a reason for hiding this comment

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

This does mean we need to keep this package up to date along with Podman's timeline/schedule.

Copy link
Member Author

Choose a reason for hiding this comment

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

@gbraad This is subpackage and I think as of now it is not used by podman machine but build everytime there is release of gvisor-tap-vsock so we can just use it without maintaining (like building ourself).

@praveenkumar praveenkumar changed the title [WIP] gvforwarder as a systemd service gvforwarder as a systemd service May 15, 2025
@praveenkumar
Copy link
Member Author

/cherry-pick release-4.19

@openshift-cherrypick-robot

@praveenkumar: once the present PR merges, I will cherry-pick it on top of release-4.19 in a new PR and assign it to you.

In response to this:

/cherry-pick release-4.19

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@praveenkumar
Copy link
Member Author

/cherry-pick master

@openshift-cherrypick-robot

@praveenkumar: once the present PR merges, I will cherry-pick it on top of master in a new PR and assign it to you.

In response to this:

/cherry-pick master

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@praveenkumar praveenkumar merged commit 4b18682 into crc-org:release-4.18 May 16, 2025
3 of 4 checks passed
@github-project-automation github-project-automation bot moved this from Work In Progress to Done in Project planning: crc May 16, 2025
@openshift-cherrypick-robot

@praveenkumar: new pull request created: #1060

In response to this:

/cherry-pick release-4.19

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@openshift-cherrypick-robot

@praveenkumar: new pull request created: #1061

In response to this:

/cherry-pick master

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

7 participants