Skip to content

return error when no tag or latest tag is specified #4814

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

Merged
merged 1 commit into from
Jul 23, 2025
Merged

Conversation

redbeam
Copy link
Contributor

@redbeam redbeam commented Jul 3, 2025

Fixes: #4520

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change
  • Chore (non-breaking change which doesn't affect codebase;
    test, version modification, documentation, etc.)

Testing

$ crc setup -b docker://quay.io/crcont/openshift-bundle
ERRO No tag found in bundle URI

$ crc setup -b docker://quay.io/crcont/openshift-bundle:
ERRO No tag found in bundle URI

$ crc setup -b docker://quay.io/crcont/openshift-bundle:latest
ERRO 'latest' tag is not supported; use a specific version

Contribution Checklist

  • I Keep It Small and Simple: The smaller the PR is, the easier it is to review and have it merged
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Which platform have you tested the code changes on?
    • Linux
    • Windows
    • MacOS

Summary by Sourcery

Require explicit version tags in bundle URIs by rejecting empty or 'latest' tags and updating tests accordingly.

Bug Fixes:

  • Return an error when bundle URIs lack a version tag or explicitly use the 'latest' tag.

Tests:

  • Add unit tests to verify error handling for URIs with no tag and with the 'latest' tag.

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced validation for Docker bundle URIs to reject empty tags and the "latest" tag, requiring explicit version tags.
  • Tests

    • Added test cases to confirm specific error responses for Docker URIs missing tags or using the "latest" tag.

Copy link

sourcery-ai bot commented Jul 3, 2025

Reviewer's Guide

This PR enhances bundle URI validation by rejecting empty or ‘latest’ tags with specific errors and adds corresponding unit tests to cover these scenarios.

Class diagram for updated GetBundleNameFromURI function

classDiagram
    class BundleMetadata {
        +GetBundleNameFromURI(bundleURI string) (string, error)
    }
    class Error {
        <<interface>>
    }
    BundleMetadata ..> Error
    note for BundleMetadata "Now returns specific errors for missing or 'latest' tag in docker bundle URIs"
Loading

File-Level Changes

Change Details Files
Enforce stricter tag validation in GetBundleNameFromURI
  • Treat missing tag (empty string) as an error
  • Return a specific error when tag equals 'latest'
  • Preserve existing behavior for valid version tags
pkg/crc/machine/bundle/metadata.go
Expand unit tests for bundle URI parsing
  • Add test for URI ending with a colon and no tag
  • Add test for URI containing the 'latest' tag
pkg/crc/machine/bundle/metadata_test.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@openshift-ci openshift-ci bot requested review from cfergeau and praveenkumar July 3, 2025 15:28
Copy link

openshift-ci bot commented Jul 3, 2025

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

coderabbitai bot commented Jul 3, 2025

Walkthrough

The GetBundleNameFromURI function in the bundle metadata code was updated to enhance Docker URI validation, now disallowing empty tags and the "latest" tag by returning specific errors (NoTagError and UnsupportedTagError). Corresponding tests were added to ensure these cases are handled as errors. No changes were made to public interfaces.

Changes

File(s) Change Summary
pkg/crc/machine/bundle/metadata.go Added NoTagError and UnsupportedTagError types; improved Docker URI validation in GetBundleNameFromURI to reject empty and "latest" tags.
pkg/crc/machine/bundle/metadata_test.go Enhanced TestGetBundleNameFromURI to assert specific error types for empty and "latest" Docker tags.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant BundleMetadata

    User->>CLI: Provide Docker bundle URI
    CLI->>BundleMetadata: Call GetBundleNameFromURI(uri)
    alt URI has empty tag or tag is "latest"
        BundleMetadata-->>CLI: Return error
        CLI-->>User: Show error message
    else URI is valid
        BundleMetadata-->>CLI: Return bundle name
        CLI-->>User: Proceed with bundle setup
    end
Loading

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Disallow or warn on use of "latest" tag (#4520)

Poem

A Docker tag, so sly and fleet—
"Latest" no more, we shan't repeat!
With careful checks, the code now knows
To halt where empty or "latest" goes.
The tests all cheer, the bugs retreat—
This bundle’s hop is now complete! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between af1939a and a79c837.

📒 Files selected for processing (2)
  • pkg/crc/machine/bundle/metadata.go (2 hunks)
  • pkg/crc/machine/bundle/metadata_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • pkg/crc/machine/bundle/metadata.go
  • pkg/crc/machine/bundle/metadata_test.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: build-installer (windows-2022, 1.23)
  • GitHub Check: build (ubuntu-latest, 1.23)
  • GitHub Check: build (macOS-13, 1.23)
  • GitHub Check: build (windows-2022, 1.23)
  • GitHub Check: build (ubuntu-latest, 1.23)
  • GitHub Check: build (ubuntu-22.04, 1.23)
  • GitHub Check: build (macOS-13, 1.23)
  • GitHub Check: build (windows-2022, 1.23)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @redbeam - I've reviewed your changes - here's some feedback:

  • Consider defining and returning distinct error variables (e.g. ErrNoTag, ErrUnsupportedLatest) instead of fmt.Errorf so callers and tests can match on error values rather than error text.
  • To make the tag extraction more robust, use strings.LastIndex to split on the final colon instead of strings.Split, which can misbehave if there are extra colons in the string.
  • Standardize the error message formatting (capitalization and punctuation) between the "no tag" and "latest" cases to keep messaging consistent.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider defining and returning distinct error variables (e.g. ErrNoTag, ErrUnsupportedLatest) instead of fmt.Errorf so callers and tests can match on error values rather than error text.
- To make the tag extraction more robust, use strings.LastIndex to split on the final colon instead of strings.Split, which can misbehave if there are extra colons in the string.
- Standardize the error message formatting (capitalization and punctuation) between the "no tag" and "latest" cases to keep messaging consistent.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@redbeam redbeam self-assigned this Jul 3, 2025
@redbeam redbeam moved this to Ready for review in Project planning: crc Jul 3, 2025
// URI with colon but no tag
bundleName, err = GetBundleNameFromURI("docker://quay.io/crcont/openshift-bundle:")
assert.Equal(t, "", bundleName)
assert.Error(t, err)
Copy link
Member

Choose a reason for hiding this comment

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

better to match the error string which we are expecting instead just asserting it as error.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or follow the recommendation from CodeRabbit even if this is not what we do in the rest of the codebase:

Consider defining and returning distinct error variables (e.g. ErrNoTag, ErrUnsupportedLatest) instead of fmt.Errorf so callers and tests can match on error values rather than error text.

Copy link
Contributor Author

@redbeam redbeam Jul 9, 2025

Choose a reason for hiding this comment

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

I added two error types (NoTagError and UnsupportedTagError) that are returned. Alternatively, they could be merged into a generic TagError type.

Issue #4520

We don't use 'latest' tag in container image repositories,
so a check was added to return an error if the user tries to use it.

Additionally, added a check for empty tag as a result of leaving a ':' at the end of the URI.
@praveenkumar
Copy link
Member

@coderabbitai review

Copy link

coderabbitai bot commented Jul 9, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

openshift-ci bot commented Jul 9, 2025

@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 a79c837 link true /test integration-crc
ci/prow/e2e-crc a79c837 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 d22146b into main Jul 23, 2025
27 of 36 checks passed
@github-project-automation github-project-automation bot moved this from Ready for review to Done in Project planning: crc Jul 23, 2025
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.

Show a warning when using latest tag
3 participants