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

Merged
merged 1 commit into from
Oct 18, 2024

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
pkg/crc/machine/bundle/metadata.go Outdated Show resolved Hide resolved
pkg/crc/machine/bundle/metadata.go Outdated Show resolved Hide resolved
pkg/crc/machine/bundle/metadata.go Outdated Show resolved Hide resolved
@anjannath
Copy link
Member

I'm surprised a custom bundle has a _232 suffix as in your example Anjan, I thought they were suffixed with only _custom

i think this got changed, now they don't contain _custom and are in the form of crc_libvirt_4.16.7_amd64_<unix_timestamp>.crcbundle as per: https://github.com/crc-org/crc/blob/main/pkg/crc/machine/bundle/metadata.go#L227

@cfergeau
Copy link
Contributor

cfergeau commented Oct 3, 2024

I'm surprised a custom bundle has a _232 suffix as in your example Anjan, I thought they were suffixed with only _custom

i think this got changed, now they don't contain _custom and are in the form of crc_libvirt_4.16.7_amd64_<unix_timestamp>.crcbundle as per: https://github.com/crc-org/crc/blob/main/pkg/crc/machine/bundle/metadata.go#L227

Ah ok, I was tricked by git grep _custom which still returns multiple results.

@redbeam
Copy link
Contributor Author

redbeam commented Oct 9, 2024

Thanks for the suggestion @cfergeau, I modified your regex a bit and it worked really well.

Copy link

openshift-ci bot commented Oct 16, 2024

@redbeam: 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 353fc52 link true /test integration-crc
ci/prow/e2e-crc 353fc52 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.

@praveenkumar praveenkumar merged commit 9f06891 into main Oct 18, 2024
27 of 32 checks passed
@redbeam redbeam deleted the preset_validation_setup branch October 18, 2024 14:45
praveenkumar added a commit to praveenkumar/snc that referenced this pull request Oct 24, 2024
Recently on crc side[0] we have enabled the regex to capture bundle info
and as part of this regex we are capturing the custom bundle which is
random generated number like
`crc_okd_vfkit_4.16.7_amd64_2342465234654.crcbundle` but for bundles
generated by the pr have suffix `.pr<pr_number>` which means again
adjust the regex. We can still identify the bundle with `_<pr_number>`
and this way we don't need to update the regex.

- crc-org/crc#4343
praveenkumar added a commit to praveenkumar/snc that referenced this pull request Oct 24, 2024
Recently on crc side[0] we have enabled the regex to capture bundle info
and as part of this regex we are capturing the custom bundle which is
random generated number like
`crc_okd_vfkit_4.16.7_amd64_2342465234654.crcbundle` but for bundles
generated by the pr have suffix `.pr<pr_number>` which means again
adjust the regex. We can still identify the bundle with `_<pr_number>`
and this way we don't need to update the regex.

- crc-org/crc#4343
openshift-merge-bot bot pushed a commit to crc-org/snc that referenced this pull request Oct 25, 2024
Recently on crc side[0] we have enabled the regex to capture bundle info
and as part of this regex we are capturing the custom bundle which is
random generated number like
`crc_okd_vfkit_4.16.7_amd64_2342465234654.crcbundle` but for bundles
generated by the pr have suffix `.pr<pr_number>` which means again
adjust the regex. We can still identify the bundle with `_<pr_number>`
and this way we don't need to update the regex.

- crc-org/crc#4343
openshift-cherrypick-robot pushed a commit to openshift-cherrypick-robot/snc that referenced this pull request Oct 25, 2024
Recently on crc side[0] we have enabled the regex to capture bundle info
and as part of this regex we are capturing the custom bundle which is
random generated number like
`crc_okd_vfkit_4.16.7_amd64_2342465234654.crcbundle` but for bundles
generated by the pr have suffix `.pr<pr_number>` which means again
adjust the regex. We can still identify the bundle with `_<pr_number>`
and this way we don't need to update the regex.

- crc-org/crc#4343
openshift-cherrypick-robot pushed a commit to openshift-cherrypick-robot/snc that referenced this pull request Oct 25, 2024
Recently on crc side[0] we have enabled the regex to capture bundle info
and as part of this regex we are capturing the custom bundle which is
random generated number like
`crc_okd_vfkit_4.16.7_amd64_2342465234654.crcbundle` but for bundles
generated by the pr have suffix `.pr<pr_number>` which means again
adjust the regex. We can still identify the bundle with `_<pr_number>`
and this way we don't need to update the regex.

- crc-org/crc#4343
openshift-cherrypick-robot pushed a commit to openshift-cherrypick-robot/snc that referenced this pull request Oct 25, 2024
Recently on crc side[0] we have enabled the regex to capture bundle info
and as part of this regex we are capturing the custom bundle which is
random generated number like
`crc_okd_vfkit_4.16.7_amd64_2342465234654.crcbundle` but for bundles
generated by the pr have suffix `.pr<pr_number>` which means again
adjust the regex. We can still identify the bundle with `_<pr_number>`
and this way we don't need to update the regex.

- crc-org/crc#4343
praveenkumar added a commit to crc-org/snc that referenced this pull request Oct 29, 2024
Recently on crc side[0] we have enabled the regex to capture bundle info
and as part of this regex we are capturing the custom bundle which is
random generated number like
`crc_okd_vfkit_4.16.7_amd64_2342465234654.crcbundle` but for bundles
generated by the pr have suffix `.pr<pr_number>` which means again
adjust the regex. We can still identify the bundle with `_<pr_number>`
and this way we don't need to update the regex.

- crc-org/crc#4343
praveenkumar added a commit to crc-org/snc that referenced this pull request Oct 29, 2024
Recently on crc side[0] we have enabled the regex to capture bundle info
and as part of this regex we are capturing the custom bundle which is
random generated number like
`crc_okd_vfkit_4.16.7_amd64_2342465234654.crcbundle` but for bundles
generated by the pr have suffix `.pr<pr_number>` which means again
adjust the regex. We can still identify the bundle with `_<pr_number>`
and this way we don't need to update the regex.

- crc-org/crc#4343
praveenkumar added a commit to crc-org/snc that referenced this pull request Oct 29, 2024
Recently on crc side[0] we have enabled the regex to capture bundle info
and as part of this regex we are capturing the custom bundle which is
random generated number like
`crc_okd_vfkit_4.16.7_amd64_2342465234654.crcbundle` but for bundles
generated by the pr have suffix `.pr<pr_number>` which means again
adjust the regex. We can still identify the bundle with `_<pr_number>`
and this way we don't need to update the regex.

- crc-org/crc#4343
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants