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

cleanup(pkg/driver): use unix where available. #353

Closed
wants to merge 1 commit into from

Conversation

FedeDP
Copy link
Contributor

@FedeDP FedeDP commented Nov 22, 2023

What type of PR is this?

/kind cleanup

Any specific area of the project related to this PR?

/area library

What this PR does / why we need it:

Small cleanups on top of #343 : use unix golang library where available.
NOTE: reimplementing insmod or modprobe in go, instead of executing it through an exec.Command is pretty convoluted since they do quite lot of things.
See for example how is that implemented in this library: https://github.com/pmorjan/kmod/tree/master
Also, that library itself does not help us much since the job is still pretty complex.
I'd avoid the risk of introducing bugs reimplementing ourselves 2 of the most widely used bash utilities.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

@poiana
Copy link
Contributor

poiana commented Nov 22, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: FedeDP

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

The pull request process is described 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

kmodName := strings.ReplaceAll(driverName, "-", "_")
printer.Logger.Info("Check if kernel module is still loaded.")
lsmodCmdArgs := fmt.Sprintf(`lsmod | cut -d' ' -f1 | grep -qx %q`, kmodName)
_, err = exec.Command("bash", "-c", lsmodCmdArgs).Output() //nolint:gosec // false positive
f, err := os.Open("/proc/modules")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of using lsmod, manually scan /proc/modules.

for i := 0; i < maxRmmodWait; i++ {
printer.Logger.Info("Kernel module is still loaded.")
printer.Logger.Info("Trying to unload it with 'rmmod'.")
if err = unix.DeleteModule(kmodName, 0); err == nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of calling rmmod directly, just use unit.DeleteModule.

@FedeDP
Copy link
Contributor Author

FedeDP commented Nov 22, 2023

/close

This is not worth the trouble IMHO.

@poiana poiana closed this Nov 22, 2023
@poiana
Copy link
Contributor

poiana commented Nov 22, 2023

@FedeDP: Closed this PR.

In response to this:

/close

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/test-infra repository.

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

Successfully merging this pull request may close these issues.

2 participants