Skip to content

add time to clean migration option#5853

Closed
changluyi wants to merge 1 commit intomasterfrom
add_time_to_clean_migration_option
Closed

add time to clean migration option#5853
changluyi wants to merge 1 commit intomasterfrom
add_time_to_clean_migration_option

Conversation

@changluyi
Copy link
Copy Markdown
Collaborator

Pull Request

What type of this PR

Examples of user facing changes:

  • Features
  • Bug fixes
  • Docs
  • Tests

Which issue(s) this PR fixes

Fixes #(issue-number)

Signed-off-by: clyi <clyi@alauda.io>
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Nov 4, 2025
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @changluyi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the Virtual Machine Instance (VMI) migration process by introducing a waiting period for the VMI to reach a ready state after a migration completes. This ensures that network configurations related to the migration are only finalized once the VMI is stable and operational, preventing potential race conditions or premature cleanup of network options on the logical switch port.

Highlights

  • VMI Readiness Check: Introduced a new waitForVMIReady function to ensure the Virtual Machine Instance is fully ready after migration before proceeding with cleanup of network options.
  • Migration Option Handling: Modified the migration cleanup logic to explicitly set migration options and then wait for VMI readiness before cleaning them, ensuring a more robust post-migration state.
  • New Helper Functions: Added waitForVMIReady and isVMIReady to facilitate reliable VMI status checking, polling the VMI's conditions or phase for readiness.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@dosubot dosubot bot added the feature New network feature label Nov 4, 2025
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a delay before cleaning up OVN migration options for a KubeVirt VMI after migration is complete. This is achieved by waiting for the VMI to become 'Ready'. While the intention to prevent traffic disruption is good, the current implementation uses a blocking wait within the controller worker, which can negatively impact controller performance by delaying the processing of other migration events. My review includes a suggestion to adopt a non-blocking approach that is more idiomatic for Kubernetes controllers.

Comment on lines +178 to +182
if err := c.waitForVMIReady(vmi); err != nil {
err = fmt.Errorf("failed to wait for VMI %s to be ready: %w", vmi.Name, err)
klog.Error(err)
return err
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The waitForVMIReady function introduces a blocking poll loop that can hold a controller worker for up to a minute. As the VMI migration handler runs as a single worker, this will serialize the completion of all migrations and can cause significant processing delays.

A more idiomatic controller pattern is to use the workqueue's requeueing mechanism for polling. Instead of blocking, check for VMI readiness once. If it's not ready, return an error to trigger a requeue. This allows the worker to process other items.

I recommend replacing the blocking wait with a non-blocking readiness check. This also makes the waitForVMIReady function unnecessary, and it can be removed.

            currentVMI, err := c.config.KubevirtClient.VirtualMachineInstance(vmi.Namespace).Get(context.TODO(), vmi.Name, metav1.GetOptions{})
            if err != nil {
                if k8serrors.IsNotFound(err) {
                    klog.Warningf("VMI %s not found, proceeding to clean migrate options", vmi.Name)
                } else {
                    err = fmt.Errorf("failed to get VMI %s to check readiness: %w", vmi.Name, err)
                    klog.Error(err)
                    return err
                }
            } else if !c.isVMIReady(currentVMI) {
                klog.Infof("VMI %s is not ready yet after migration, requeueing", vmi.Name)
                return fmt.Errorf("VMI %s is not ready yet", vmi.Name)
            }

@coveralls
Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 19057062882

Details

  • 0 of 49 (0.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.02%) to 21.521%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/controller/kubevirt.go 0 49 0.0%
Totals Coverage Status
Change from base Build 19054987369: -0.02%
Covered Lines: 10940
Relevant Lines: 50835

💛 - Coveralls

@changluyi changluyi closed this Nov 4, 2025
@oilbeater oilbeater deleted the add_time_to_clean_migration_option branch February 24, 2026 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New network feature size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants