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

metadata: Add logic to fallback to quay if mirror is unreachable #3802

Merged
merged 3 commits into from
Oct 6, 2023

Conversation

praveenkumar
Copy link
Member

Since we are going to put bundles on quay and mirror where quay serve as
fallback solution. This PR makes user aware in case mirror fails to
download bundle.

INFO Getting bundle for the CRC executable
INFO Downloading bundle: /home/prkumar/.crc/cache/crc_microshift_libvirt_4.13.9_amd64.crcbundle...
INFO Unable to download bundle from mirror, falling back to quay
Getting image source signatures
Copying blob d37da0367460 done
Copying config f3021495d6 done
Writing manifest to image destination
Storing signatures
INFO Extracting the image bundle layer...
crc_microshift_libvirt_4.13.9_amd64.crcbundle:  1.46 GiB / 1.46 GiB [--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------] 100.00%
INFO Verifying the bundle signature...
INFO Uncompressing /home/prkumar/.crc/cache/crc_microshift_libvirt_4.13.9_amd64.crcbundle
crc.qcow2:  4.28 GiB / 4.28 GiB [--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------] 100.00%
oc:  141.85 MiB / 141.85 MiB [-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------] 100.00%
Your system is correctly setup for using CRC. Use 'crc start' to start the instance

@@ -353,7 +353,12 @@ func Download(preset crcPreset.Preset, bundleURI string) (string, error) {
// bundles, their sha256sums are known and can be checked.
if bundleURI == constants.GetDefaultBundlePath(preset) {
if preset == crcPreset.OpenShift || preset == crcPreset.Microshift {
return DownloadDefault(preset)
downloadedBundlePath, err := DownloadDefault(preset)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to differentiate "not found" from other errors?

Copy link
Member Author

Choose a reason for hiding this comment

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

@cfergeau looks like grab package have StatusCodeError type and can validated with IsStatusCodeError which I now used.

StatusCodeError indicates that the server response had a status code that
// was not in the 200-299 range (after following any redirects).

pkg/crc/machine/bundle/metadata.go Outdated Show resolved Hide resolved
pkg/crc/image/image.go Outdated Show resolved Hide resolved
@cfergeau
Copy link
Contributor

This PR needs a rebase.

This remove some of code duplication.
Copy link
Contributor

@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.

Overall looks good, a few minor comments left.

pkg/crc/image/image.go Outdated Show resolved Hide resolved
pkg/crc/config/settings.go Outdated Show resolved Hide resolved
logging.Infof("Using bundle path %s", bundlePath)
return getPreflightChecks(experimentalFeatures, mode, bundlePath, preset)
return getPreflightChecks(experimentalFeatures, mode, bundlePath, preset, enableBundleQuayFallback)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hrm, 4 arguments was already quite a few, 5 is starting to be too many args :-/

@@ -346,7 +348,12 @@ func Download(preset crcPreset.Preset, bundleURI string) (string, error) {
if bundleURI == constants.GetDefaultBundlePath(preset) {
switch preset {
case crcPreset.OpenShift, crcPreset.Microshift:
return downloadDefault(preset)
downloadedBundlePath, err := downloadDefault(preset)
if grab.IsStatusCodeError(errors.Unwrap(err)) && enableBundleQuayFallback {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this could be errors.Is(err, grab.StatusCodeError)

Copy link
Member Author

Choose a reason for hiding this comment

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

@cfergeau this is not work because as per errors.Is it doesn't call the unwrap on the target and the way we have this error it is wrapped around grabStatusCodeError so it is not able to work.

Copy link
Contributor

Choose a reason for hiding this comment

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

errors.Is was introduced to deal with wrapped errors. Its documentation is clear about this. https://pkg.go.dev/errors

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes but if I take a look to grab error package the implementation around StatusCodeError is type int and if I try to use errors.Is on that it is not working until we know the statuscode. I think that is the reason it have IsStatusCodeError function.

https://go.dev/play/p/jwkn9TG9SmH

Copy link
Contributor

@cfergeau cfergeau Oct 4, 2023

Choose a reason for hiding this comment

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

Ah right, errors.Is checks for equality, not for type :-/ errors.As checks for types, but is not as convenient as errors.Is. If we keep this code, I think we should use errors.As instead of hardcoding a single errors.Unwrap(). Hardcoding this Unwrap() will break if we move/refactor this code, and the level of wrapping is changed (eg if errors.Unwrap(errors.Unwrap()) becomes needed instead of errors.Unwrap()).

However looking at downloadDefault(), there are more situations than "the bundle file is missing/cannot be downloaded" when we want to fallback, for example if the signature is missing/invalid. IsStatusCodeError() seems to be too restrictive? The initial version where the fallback always happened when there was an error may be a better option

Copy link
Member Author

Choose a reason for hiding this comment

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

@cfergeau yeah that is more flexible, I can revert to that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

As part of a9c0b4c we didn't add microshift preset. This PR add
microshift preset to fetch default container image when it is available
to `quay.io`.
@openshift-merge-robot
Copy link
Contributor

@praveenkumar: 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 f1ed74e link true /test integration-crc
ci/prow/e2e-crc f1ed74e link true /test e2e-crc

Full PR test history. Your PR dashboard.

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

Since we are going to put bundles on quay and mirror where quay serve as
fallback solution. This PR add a config flag
`enable-bundle-quay-fallback` which allow user to download bundle from
quay.

```
$ crc config set enable-bundle-quay-fallback true

$ crc setup
INFO Getting bundle for the CRC executable
INFO Downloading bundle: /home/prkumar/.crc/cache/crc_microshift_libvirt_4.13.9_amd64.crcbundle...
INFO Unable to download bundle from mirror, falling back to quay
Getting image source signatures
Copying blob d37da0367460 done
Copying config f3021495d6 done
Writing manifest to image destination
Storing signatures
INFO Extracting the image bundle layer...
crc_microshift_libvirt_4.13.9_amd64.crcbundle:  1.46 GiB / 1.46 GiB [--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------] 100.00%
INFO Verifying the bundle signature...
INFO Uncompressing /home/prkumar/.crc/cache/crc_microshift_libvirt_4.13.9_amd64.crcbundle
crc.qcow2:  4.28 GiB / 4.28 GiB [--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------] 100.00%
oc:  141.85 MiB / 141.85 MiB [-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------] 100.00%
Your system is correctly setup for using CRC. Use 'crc start' to start the instance
```
@openshift-ci
Copy link

openshift-ci bot commented Oct 4, 2023

@praveenkumar: 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 fea84f0 link true /test integration-crc
ci/prow/e2e-crc fea84f0 link true /test e2e-crc

Full PR test history. Your PR dashboard.

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

@openshift-ci
Copy link

openshift-ci bot commented Oct 5, 2023

[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:

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

@openshift-ci openshift-ci bot added the approved label Oct 5, 2023
@praveenkumar praveenkumar merged commit 2875a74 into crc-org:main Oct 6, 2023
11 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants