crc-org / crc

CRC is a tool to help you run containers. It manages a local OpenShift 4.x cluster, Microshift or a Podman VM optimized for testing and development purposes
https://crc.dev
Apache License 2.0
1.26k stars 242 forks source link

fix: Download bundle without specifying tag #4474

Open A-725-K opened 22 hours ago

A-725-K commented 22 hours ago

The "latest" tag is not supported, therefore it is necessary to stop with an error in case it is not provided when using the -b flag command line flag.

Add unit tests to reproduce the bug and verify the fix.

Closes issue #4470

Fixes: Issue #4470

Solution/Idea

Before, in the GetBundleNameFromURI function, the imageAndTag array was trying to access its second element without ensuring that the length is at least 2 causing a crash in case the -b command line option was used to specify a bundle from a container image repository (using the docker:// scheme) without a tag. I have added a check to prevent the program from crashing, returning an error to the user since the "latest" tag is not an option.

Proposed changes

In GetBundleNameFromURI function:

  1. Check the lenght of imageAndTag array
    1. if it is greater or equal to 2, then obtain image name and tag as imageAndTag[0] and imageAndTag[1] respectively
    2. otherwise, bail out with an error
  2. Change all the use in the codebase, since now the function returns also an error in case of failure

Testing

Added unit tests to reproduce the bug and validate the fix proposed. Check the TestGetBundleNameFromURI function in the pkg/crc/machine/bundle/metadata_test.go file. Running crc setup -b docker://quay.io/crcont/openshift-bundle should now return an error message instead of crashing.

openshift-ci[bot] commented 22 hours ago

Hi @A-725-K. 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.

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.
openshift-ci[bot] commented 21 hours ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cfergeau

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: - ~~[OWNERS](https://github.com/crc-org/crc/blob/main/OWNERS)~~ [cfergeau] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment
openshift-ci[bot] commented 19 hours ago

New changes are detected. LGTM label has been removed.

openshift-ci[bot] commented 18 hours ago

@A-725-K: The following tests 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/integration-crc 2262b80bf81336c2c8745db08e77a55f0494a7ef link true /test integration-crc
ci/prow/e2e-crc 2262b80bf81336c2c8745db08e77a55f0494a7ef link true /test e2e-crc

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).