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

bundle validation: check for bundle preset mismatch during setup #4343

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

redbeam
Copy link
Contributor

@redbeam redbeam commented Sep 3, 2024

Fixes: Issue #3615

Added a check for bundle type mismatch with preset in function ValidateBundle.

func ValidateBundle(bundlePath string, preset crcpreset.Preset) error {
bundleName := bundle.GetBundleNameFromURI(bundlePath)
bundleMetadata, err := bundle.Get(bundleName)
if err != nil {
if bundlePath == constants.GetDefaultBundlePath(preset) {
return nil
}
return ValidateBundlePath(bundlePath, preset)
}
if err = BundleMismatchWithPreset(preset, bundleMetadata); err != nil {
logging.Fatal(err.Error())
return err
}
bundleMismatchWarning(bundleMetadata.GetBundleName(), preset)
/* 'bundle' is already unpacked in ~/.crc/cache */
return nil
}

The check is performed before checking for custom bundle (and potentially displaying a warning).

Function BundleMismatchWithPreset was moved from machine/start.go to validation/validation.go and is used during start as well.

Testing

  1. Download bundle for a preset (i.e. microshift).
  2. Change preset to some other value crc config set preset openshift
  3. crc setup --bundle <path_to_bundle>
    Output:
    FATA Preset openshift is used but bundle is provided for microshift preset

Copy link

openshift-ci bot commented Sep 3, 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 cfergeau 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

@redbeam redbeam self-assigned this Sep 3, 2024
@redbeam
Copy link
Contributor Author

redbeam commented Sep 3, 2024

Also, I think bundleMismatchWarning function name is kind of ambiguous. It is checking for and displaying a warning if there is a custom bundle being used, so what about renaming it to something like customBundleUsedWarning or userProvidedBundleWarning?

@redbeam redbeam force-pushed the preset_validation_setup branch 3 times, most recently from 7c9961b to 1921db4 Compare September 26, 2024 20:31
Copy link

openshift-ci bot commented Sep 27, 2024

@redbeam: 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 497e0d9 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-sigs/prow repository. I understand the commands that are listed here.

filenameInfo.Driver = filenameParts[2]
filenameInfo.Version = filenameParts[3]
filenameInfo.Arch = filenameParts[4]
default:
Copy link
Member

@anjannath anjannath Sep 30, 2024

Choose a reason for hiding this comment

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

hey, apologies i should've mentioned this earlier, but forgot, there's a scenario where the filenameParts can be 6, we have a custom bundle generation command crc bundle generate that creates new bundle out of existing one and it names them as crc_microshift_vfkit_4.16.7_arm64_2345.crcbundle for a microshift bundle and crc_vfkit_4.16.7_arm64_2345.crcbundle for an openshift bundle which are valid names; see: https://github.com/crc-org/crc/blob/main/pkg/crc/machine/bundle/metadata.go#L227

so if i use a custom bundle currently this fails, for an openshift bundle as:

% crc config set bundle ./crc_vfkit_4.16.7_arm64_2345.crcbundle
WARN Using custom bundle crc_vfkit_4.16.7_arm64_2345.crcbundle 
Successfully configured bundle to ./crc_vfkit_4.16.7_arm64_2345.crcbundle

% crc setup --log-level debug
DEBU CRC version: 2.41.0+1921db
DEBU OpenShift version: 4.16.7
DEBU MicroShift version: 4.16.7
DEBU Running 'crc setup'
DEBU Got bundle path: ./crc_vfkit_4.16.7_arm64_2345.crcbundle
DEBU Failed to parse url: parse "./crc_vfkit_4.16.7_arm64_2345.crcbundle": invalid URI for request
WARN Using custom bundle crc_vfkit_4.16.7_arm64_2345.crcbundle
Cannot parse preset 'vfkit'

for a microshift bundle, as:

% crc config set bundle ./crc_microshift_vfkit_4.16.7_arm64_232.crcbundle
WARN Using custom bundle crc_microshift_vfkit_4.16.7_arm64_232.crcbundle
Successfully configured bundle to ./crc_microshift_vfkit_4.16.7_arm64_232.crcbundle

% crc setup --log-level debug
DEBU CRC version: 2.41.0+1921db
DEBU OpenShift version: 4.16.7
DEBU MicroShift version: 4.16.7
DEBU Running 'crc setup'
DEBU Got bundle path: ./crc_microshift_vfkit_4.16.7_arm64_232.crcbundle
DEBU Failed to parse url: parse "./crc_microshift_vfkit_4.16.7_arm64_232.crcbundle": invalid URI for request
WARN Using custom bundle crc_microshift_vfkit_4.16.7_arm64_232.crcbundle
bundle filename is in unrecognized format

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

Successfully merging this pull request may close these issues.

3 participants