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

rosetta: add option to ignore rosetta failure when installation cancelled #202

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lstocchi
Copy link

@lstocchi lstocchi commented Oct 4, 2024

This adds a ignore-if-missing option that allows vfkit to not fail if the rosetta installation is cancelled by the user.
So far, if the rosetta installation was cancelled vfkit exited with an error. This behavior still exists if ignore-if-missing option is not set.
it fixes #160

Copy link

openshift-ci bot commented Oct 4, 2024

[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 assign baude for approval. For more information see the Kubernetes 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

Copy link
Collaborator

@cfergeau cfergeau left a comment

Choose a reason for hiding this comment

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

Haven't tested this extensively, but looks good to me.
It would be nice to update the documentation as well to mention the new option, and to add a Fixes https://github.com/crc-org/vfkit/issues/160 in the commit log so that the corresponding issue is automatically fixed.

return fmt.Errorf("rosetta is not installed")
}
log.Debugf("installing rosetta")
if err := vz.LinuxRosettaDirectoryShareInstallRosetta(); err != nil {
if err := doInstallRosetta(); err != nil {
if dev.IgnoreIfMissing && strings.Contains(err.Error(), fmt.Sprintf("VZErrorDomain Code=%d", vz.ErrorOperationCancelled)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of strings.Contains, maybe you can make use of errors.As to cast err to vz.NSError ( https://go.dev/blog/go1.13-errors ), and then check nsErr.Domain and nsErr.Code?
It will be a bit more verbose, but in a way "more correct".

However, maybe we want to ignore all errors in this situation, even failures to install not related to a cancellation?

Copy link
Author

Choose a reason for hiding this comment

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

I think I tried the errors.As without success but you made a nice observation, I agree we should ignore all errors, makes sense. Updating it

if err := vz.LinuxRosettaDirectoryShareInstallRosetta(); err != nil {
if err := doInstallRosetta(); err != nil {
if dev.IgnoreIfMissing && strings.Contains(err.Error(), fmt.Sprintf("VZErrorDomain Code=%d", vz.ErrorOperationCancelled)) {
log.Debugf("user cancelled rosetta installation but ignoreIfMissing option is true")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a way for (eg) podman to detect the rosetta installation failed? If not, we need to print something to stdout or stderr, which is not great, but will allow podman to know what happened.

Copy link
Author

@lstocchi lstocchi Oct 8, 2024

Choose a reason for hiding this comment

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

So, not sure what to do here and what's the suggested way to handle it. I just added a generic message to the stdout end the error on stderr

defer func() {
checkRosettaDirectoryShareAvailability = origCheckRosettaDirectoryShareAvailability
doInstallRosetta = origDoInstallRosetta
}()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure you need to restore the initial values after running the test? I'd expect each xxx_test.go file to run in its own process (to be checked though ;)

Copy link
Author

Choose a reason for hiding this comment

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

So, I've been digging on it a bit and I didn't find any clear response but by looking at the code it seems that each test is run by launching a go routine https://github.com/golang/go/blob/182bdbb1e1d62fe53f8386e7b02c7738898d373b/src/testing/testing.go#L555 and from what I read all goroutines within a Go program share the same process so all tests run in the same process.
By creating a new test file I can see it to be true so I think it's better to keep the defer to avoid problems for future tests.

@lstocchi
Copy link
Author

lstocchi commented Oct 8, 2024

Forgot to update the documentation, updating it

Luca Stocchi added 2 commits October 8, 2024 11:44
…lled

    this adds a ignore-if-missing option that allows vfkit to not fail if the rosetta installation do not succeed for some reason (e.g. user cancelled installation).
    So far, if the rosetta installation was cancelled or failed vfkit exited with an error. This behavior still exists if ignore-if-missing option is not set or it is false.
    This will be used by podman bc there could be a fallback and rosetta could also be not mandatory containers/podman#23153
it fixes crc-org#160
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Add option to ignore rosetta's failure to install
2 participants