Skip to content

Conversation

@hector-vido
Copy link

@hector-vido hector-vido commented Feb 22, 2025

Description

Verify if the binary exists before running it with sudo.
Actually the exit code is not useful, only show that a result different than 0 was returned.

...
INFO Checking if vsock is correctly configured    
INFO Setting up vsock support                     
INFO Using root access: Setting CAP_NET_BIND_SERVICE capability for /home/hector/Projects/crc/out/linux-amd64/crc executable 
exit status 1

With this tiny modification, is easy for the user to understand what is missing:

...
INFO Checking if vsock is correctly configured    
INFO Setting up vsock support                     
INFO Using root access: Setting CAP_NET_BIND_SERVICE capability for /home/hector/Projects/crc/out/linux-amd64/crc executable 
setcap executable not found

I was testing crc inside an openSUSE Tumbleweed version 20250219.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change
  • Chore (non-breaking change which doesn't affect codebase;
    test, version modification, documentation, etc.)

Proposed changes

Just an extra verification for the existence of binaries used and a small unit test.

Unfortunately with this unit test the sudo command will be invoked in each test call and most of the container images doesn't have it. The solution for this was to use an unexported package-level variable, this variable can be overwritten inside the test, avoiding the use of an interface.

Chapter 11 - The Go Programming Language, page 312

Testing

Added a unit test that should fail trying to find a binary named i-dont-exist.
Thanks to @rohanKanojia who gives me a north on that.

Contribution Checklist

  • I Keep It Small and Simple: The smaller the PR is, the easier it is to review and have it merged
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Which platform have you tested the code changes on?
    • Linux
    • Windows
    • MacOS

@openshift-ci
Copy link

openshift-ci bot commented Feb 22, 2025

Hi @hector-vido. Thanks for your PR.

I'm waiting for a crc-org member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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.

@hector-vido hector-vido force-pushed the verify-binary-existence branch from b8f9bb4 to abf149a Compare February 22, 2025 03:52
@praveenkumar
Copy link
Member

/ok-to-test

@rohanKanojia
Copy link
Contributor

@hector-vido : Thanks for your PR! Is it possible to add a unit test to verify that your changes work as expected?

@hector-vido hector-vido force-pushed the verify-binary-existence branch from abf149a to 28a63b6 Compare February 27, 2025 03:49
@openshift-ci openshift-ci bot removed the lgtm label Feb 27, 2025
@hector-vido hector-vido force-pushed the verify-binary-existence branch from 28a63b6 to 3983c64 Compare February 27, 2025 18:58
@hector-vido
Copy link
Author

hector-vido commented Feb 27, 2025

This is interesting, pull-ci-crc-org-crc-main-images and some other tests are failing because sudo is not present.

=== RUN   TestRunPrivileged
exec_test.go:11: 
  Error Trace:	/go/src/github.com/crc-org/crc/pkg/os/exec_test.go:11
  Error:      	Error "sudo executable not found" does not contain "i-dont-exist executable not found"
  Test:       	TestRunPrivileged

Fixed with an unexported package-level variable

@hector-vido hector-vido force-pushed the verify-binary-existence branch from 3983c64 to 5654a32 Compare February 28, 2025 01:00
@openshift-ci openshift-ci bot removed the lgtm label Feb 28, 2025
@hector-vido
Copy link
Author

/retest

2 similar comments
@hector-vido
Copy link
Author

/retest

@hector-vido
Copy link
Author

/retest

@hector-vido hector-vido force-pushed the verify-binary-existence branch from 5654a32 to 58fa905 Compare February 28, 2025 13:22
@openshift-ci openshift-ci bot added the lgtm label Feb 28, 2025
@openshift-ci
Copy link

openshift-ci bot commented Feb 28, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: praveenkumar, rohanKanojia

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

The pull request process is described here

Details 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

@hector-vido
Copy link
Author

/retest

@hector-vido hector-vido force-pushed the verify-binary-existence branch from 58fa905 to 2906444 Compare March 4, 2025 16:47
@openshift-ci
Copy link

openshift-ci bot commented Mar 4, 2025

New changes are detected. LGTM label has been removed.

@openshift-ci openshift-ci bot removed the lgtm label Mar 4, 2025
@openshift-ci
Copy link

openshift-ci bot commented Mar 4, 2025

@hector-vido: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-crc 2906444 link true /test e2e-crc

Full PR test history. Your PR dashboard.

Details

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. I understand the commands that are listed here.

@praveenkumar praveenkumar merged commit 4bdcc16 into crc-org:main Mar 5, 2025
6 of 8 checks passed
@hector-vido hector-vido deleted the verify-binary-existence branch March 7, 2025 19:52
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.

3 participants