Skip to content

Print the progress for container Image Pull during cluster-up #1425

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

harshitgupta1337
Copy link

What this PR does / why we need it:
Currently, when the cluster-provision scripts download a container image (such as the quay.io/kubevirtci/k8s-1.31 image), the exact progress of the download is not displayed. This PR addresses this limitation by printing the image pull progress in a manner finds a middle-ground between high verbosity (passing the entirety of the docker image pull output to a non-terminal stdout) and not tracking image download/extraction progress (only showing state changes, e.g., Downloading --> Verifying Checksum).
In the proposed approach, we report the pull progress for each image layer independently. Image pull status for a given layer is printed only when either one of the following 2 conditions is met.

  1. Image pull process has transitioned from one state to the next. For example, it has moved from Downloading state to Verifying Checksum state.
  2. Image pull process has made more than 10% progress in the current state. For example, if a layer is currently in Downloading state and it has downloaded more than 10% of the layer since the last time its progress was printed, then the progress of that layer will be printed.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes kubevirt/kubevirt#14242

Special notes for your reviewer:

Checklist

This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR.
Approvers are expected to review this list.

Release note:

NONE

@kubevirt-bot
Copy link
Contributor

[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 stu-gott 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

@kubevirt-bot kubevirt-bot added the dco-signoff: no Indicates the PR's author has not DCO signed all their commits. label Apr 14, 2025
@kubevirt-bot kubevirt-bot requested a review from ormergi April 14, 2025 16:06
Copy link

sourcery-ai bot commented Apr 14, 2025

Reviewer's Guide by Sourcery

This PR enhances the cluster-provision scripts by providing detailed progress information during container image pulls. It tracks the progress of each image layer and reports updates based on state changes or significant progress milestones, offering a more informative user experience.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Implemented detailed progress reporting for container image pulls, providing insights into each layer's download and extraction.
  • Introduced a PullStatus struct to parse and represent the progress of each image layer.
  • Implemented logic to print the status of each layer only when its state changes or when it has made significant progress (10%) since the last update.
  • Maintained a map (lastReportedState) to track the last reported state of each layer, preventing redundant updates.
  • Added parseAndCheckForError function to parse the progress json message into PullStatus struct and check for errors.
  • Report the pull progress for each image layer independently.
  • Image pull status for a given layer is printed only when either the image pull process has transitioned from one state to the next, or the image pull process has made more than 10% progress in the current state.
cluster-provision/gocli/docker/docker.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!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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

@kubevirt-bot
Copy link
Contributor

Thanks for your pull request. Before we can look at it, you'll need to add a 'DCO signoff' to your commits.

📝 Please follow instructions in the contributing guide to update your commits with the DCO

Full details of the Developer Certificate of Origin can be found at developercertificate.org.

The list of commits missing DCO signoff:

  • 985cdb7 Print progress after every 10% increment
  • 69fc803 Use the same parseAndCheckForError fn for checking error in pull msg

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.

@kubevirt-bot
Copy link
Contributor

Hi @harshitgupta1337. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

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.

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 @harshitgupta1337 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider extracting the logic for parsing and reporting progress into a separate function for better readability.
  • It might be helpful to add some comments explaining the logic behind the 10% progress update condition.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

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.

return err
}
fmt.Print(".")

lastStatus, ok := lastReportedState[pullStatus.Id]
Copy link

Choose a reason for hiding this comment

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

issue (complexity): Consider extracting the pull status reporting logic into a helper function to reduce nesting and improve clarity of the code.

Consider extracting the pull‑status reporting logic into a helper function to reduce nesting and improve clarity. For example, you could create a function like this:

```go
func shouldReport(current, last PullStatus) bool {
	if current.Status != last.Status {
		return true
	}
	lastProgress := float64(last.ProgressDetail.Current) / float64(last.ProgressDetail.Total)
	currProgress := float64(current.ProgressDetail.Current) / float64(current.ProgressDetail.Total)
	return currProgress-lastProgress >= 0.1
}

Then your scanner loop in the non‑terminal branch can become:

scanner := bufio.NewScanner(progressReader)
// Map to store the last state printed for each container layer.
lastReportedState := make(map[string]PullStatus)
for scanner.Scan() {
	line := scanner.Text()
	if line == "" {
		continue
	}

	pullStatus := &PullStatus{}
	if err := parseAndCheckForError(line, pullStatus); err != nil {
		return err
	}

	toReport := false
	if last, ok := lastReportedState[pullStatus.Id]; ok {
		toReport = shouldReport(*pullStatus, last)
	} else {
		toReport = true
	}

	if toReport {
		fmt.Fprintf(writer, "%s\t%s\t%s\n", pullStatus.Id, pullStatus.Status, pullStatus.Progress)
		lastReportedState[pullStatus.Id] = *pullStatus
	}
}

This refactoring isolates the decision logic, reduces nested conditionals, and improves overall readability without changing the functionality.

@brianmcarey
Copy link
Member

/cc @iholder101

@kubevirt-bot kubevirt-bot requested a review from iholder101 April 16, 2025 14:22
@iholder101
Copy link
Contributor

Thank you very much @harshitgupta1337 for trying to address this annoying issue!

Image pull process has made more than 10% progress in the current state. For example, if a layer is currently in Downloading state and it has downloaded more than 10% of the layer since the last time its progress was printed, then the progress of that layer will be printed.

It's unfortunate that we can't just redirect the output to the terminal for it to print in a nicely fashion. However, I'm not sure if or how to do so.

@dhiller what are your thoughts on this? is this better than the dots being printed? is there a way to better redirect to terminal?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dco-signoff: no Indicates the PR's author has not DCO signed all their commits. kind/enhancement size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

download progress for image quay.io/kubevirtci/k8s-1.31 while building
4 participants