Skip to content

Conversation

@sebrandon1
Copy link
Contributor

@sebrandon1 sebrandon1 commented Jun 25, 2025

In the codebase, there are 12 references to context.TODO() and 28 references to context.Background().

They both do the same thing functionally so here's a PR to make it more consistent and change all TODO references to Background.

Similar to:

Summary by Sourcery

Enhancements:

  • Replace context.TODO() with context.Background() in production code and tests for consistency

Summary by CodeRabbit

  • Refactor
    • Updated internal context usage for various download, extraction, and file copy operations to use a more appropriate background context. No changes to user-facing functionality or behavior.

@sourcery-ai
Copy link

sourcery-ai bot commented Jun 25, 2025

Reviewer's Guide

Standardize context usage by replacing all context.TODO() calls with context.Background() across tests, cache, preflight, CLI, compression, repository, and file operations for consistency.

File-Level Changes

Change Details Files
Replaced context.TODO() with context.Background() for consistency
  • Updated test functions in extract, compress, and repository packages to use background context
  • Refactored cache download and extraction routines to invoke context.Background()
  • Adjusted preflight bundle download and extraction commands to use background context
  • Unified context usage in CLI embedder and OS copy operations
cmd/crc-embedder/cmd/embed.go
pkg/compress/compress_test.go
pkg/crc/cache/cache.go
pkg/crc/machine/bundle/repository_test.go
pkg/crc/preflight/preflight_checks_common.go
pkg/extract/extract_test.go
pkg/os/copy.go
test/extended/util/util.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
Copy link

openshift-ci bot commented Jun 25, 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 cfergeau for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details 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
Copy link

openshift-ci bot commented Jun 25, 2025

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

Details

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.

@coderabbitai
Copy link

coderabbitai bot commented Jun 25, 2025

Walkthrough

All instances of context.TODO() across various source and test files have been replaced with context.Background(). These changes affect the context argument passed to several download, extraction, and file copy operations, but do not alter any other logic, error handling, or control flow in the affected functions.

Changes

File(s) Change Summary
cmd/crc-embedder/cmd/embed.go Replaced context.TODO() with context.Background() in call to download.Download.
pkg/compress/compress_test.go Replaced context.TODO() with context.Background() in call to extract.Uncompress in tests.
pkg/crc/cache/cache.go Updated two methods to use context.Background() instead of context.TODO() for extraction/download.
pkg/crc/machine/bundle/repository_test.go Swapped context.TODO() for context.Background() in test call to repo.Extract.
pkg/crc/preflight/preflight_checks_common.go Changed context from TODO() to Background() in bundle download and extraction calls.
pkg/extract/extract_test.go Replaced context.TODO() with context.Background() in test calls to extraction functions.
pkg/os/copy.go Used context.Background() instead of context.TODO() in sparse file copy operation.
test/extended/util/util.go Changed context to context.Background() in bundle download utility function.

Poem

A hop and a skip, the contexts align,
From TODOs to Background, the code’s looking fine.
No logic was altered, just clarity won,
The rabbits approve—this cleanup is done!
With every new context, we leap toward the sun.
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (1.64.8)

Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2
Failed executing command with error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2

✨ Finishing Touches
  • 📝 Generate Docstrings

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

sourcery-ai[bot]

This comment was marked as off-topic.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
pkg/os/copy.go (1)

25-27: Pass a caller-supplied context instead of hard-coding context.Background()

Hard-wiring a root context here prevents higher layers from cancelling long-running sparse copies (for example through a context.WithTimeout).
Consider changing the API to accept a ctx parameter and propagating it to CopySparse, falling back to context.Background() only when nil is supplied.

-func copyFile(src, dst string, sparse bool) error {
+func copyFile(ctx context.Context, src, dst string, sparse bool) error {
 ...
-    if sparse {
-        if _, err = CopySparse(context.Background(), out, in); err != nil {
+    if ctx == nil {
+        ctx = context.Background()
+    }
+    if sparse {
+        if _, err = CopySparse(ctx, out, in); err != nil {

Down-stream helpers (CopyFile, CopyFileSparse, callers) would need tiny updates to thread the context through.
This keeps the code cancellable without altering behaviour for existing callers.

cmd/crc-embedder/cmd/embed.go (1)

162-168: Reuse a single context for the entire download loop

context.Background() is cheap, but constructing it inside the loop makes the intention less explicit and makes later replacement with a cancellable context harder.
Define the context once and reuse it:

-    for componentName, dl := range downloads {
+    ctx := context.Background()
+    for componentName, dl := range downloads {
 ...
-        filename, err := download.Download(context.Background(), dl.url, destDir, dl.permissions, nil)
+        filename, err := download.Download(ctx, dl.url, destDir, dl.permissions, nil)

This also opens the door to replacing ctx with a timeout or cancel context from the caller in the future.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e267724 and 55b05bd.

📒 Files selected for processing (8)
  • cmd/crc-embedder/cmd/embed.go (1 hunks)
  • pkg/compress/compress_test.go (1 hunks)
  • pkg/crc/cache/cache.go (2 hunks)
  • pkg/crc/machine/bundle/repository_test.go (1 hunks)
  • pkg/crc/preflight/preflight_checks_common.go (1 hunks)
  • pkg/extract/extract_test.go (2 hunks)
  • pkg/os/copy.go (1 hunks)
  • test/extended/util/util.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
cmd/crc-embedder/cmd/embed.go (1)
pkg/download/download.go (1)
  • Download (64-96)
pkg/compress/compress_test.go (1)
pkg/extract/extract.go (1)
  • Uncompress (31-33)
pkg/extract/extract_test.go (1)
pkg/extract/extract.go (2)
  • Uncompress (31-33)
  • UncompressWithFilter (27-29)
⏰ Context from checks skipped due to timeout of 90000ms (17)
  • GitHub Check: build (windows-2022, 1.23)
  • GitHub Check: build (ubuntu-latest, 1.23)
  • GitHub Check: Run OKD bundle with crc (1.23)
  • GitHub Check: build (macOS-14, 1.23)
  • GitHub Check: build (ubuntu-latest, 1.23)
  • GitHub Check: build-qe (darwin, arm64)
  • GitHub Check: verify-devcontainer
  • GitHub Check: build (ubuntu-22.04, 1.23)
  • GitHub Check: build-qe (linux, arm64)
  • GitHub Check: build (macOS-13, 1.23)
  • GitHub Check: build (windows-2022, 1.23)
  • GitHub Check: build-qe (windows, amd64)
  • GitHub Check: build-qe (darwin, amd64)
  • GitHub Check: build-qe (linux, amd64)
  • GitHub Check: build-installer (windows-2022, 1.23)
  • GitHub Check: build (macOS-13, 1.23)
  • GitHub Check: build (macOS-14, 1.23)
🔇 Additional comments (6)
pkg/crc/machine/bundle/repository_test.go (1)

43-44: Consistency change looks good

The test now uses context.Background() like the rest of the suite. No further issues spotted.

test/extended/util/util.go (1)

145-147: Download now uses context.Background() – OK

The helper mirrors the updated pattern used across the codebase. No further action required.

pkg/compress/compress_test.go (1)

37-39: Test updated for consistency

extract.Uncompress is now invoked with context.Background(). Change is correct and requires no additional adjustments.

pkg/crc/preflight/preflight_checks_common.go (1)

128-128: LGTM! Consistent context usage.

The replacement of context.TODO() with context.Background() in the bundle download and extraction operations aligns with the PR objective of using context.Background() consistently across the codebase. Both contexts are functionally equivalent, and context.Background() is appropriate for these root-level setup operations.

Also applies to: 133-133

pkg/extract/extract_test.go (1)

63-63: LGTM! Appropriate context usage in tests.

The replacement of context.TODO() with context.Background() in the test functions is correct and follows Go testing best practices. Using context.Background() is standard for test contexts as they represent root-level operations.

Also applies to: 151-151, 153-153

pkg/crc/cache/cache.go (1)

125-125: LGTM! Consistent context usage in cache operations.

The replacement of context.TODO() with context.Background() in the cache management operations is appropriate. These are infrastructure-level operations for managing the executable cache, and using context.Background() aligns with the PR objective of consistent context usage throughout the codebase.

Also applies to: 157-157

@gbraad
Copy link
Contributor

gbraad commented Jun 26, 2025

/ok-to-test

@openshift-ci
Copy link

openshift-ci bot commented Jun 26, 2025

@sebrandon1: 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 55b05bd link true /test e2e-crc

Full PR test history. Your PR dashboard.

Details

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
Copy link
Member

praveenkumar commented Jun 26, 2025

They looks same but have different purpose, context.Background() is act as base context and shouldn't be overused. context.Todo() is where we are not sure how the propagate the context so mostly a placeholder for revisit when possible. It looks like in our codebase we are creating ctx to pass to next function and not something coming from caller so in that case background would be good.

@gbraad
Copy link
Contributor

gbraad commented Jun 26, 2025

In short you try to say that these are not actually the same, but for our purpose (and the references given) this is not an issue... so the PR is OK. Right?

@praveenkumar praveenkumar merged commit cbd2710 into crc-org:main Jul 15, 2025
25 of 36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants