Skip to content

fix migrate failed#5873

Merged
changluyi merged 2 commits intomasterfrom
fix_first_migration_error
Nov 7, 2025
Merged

fix migrate failed#5873
changluyi merged 2 commits intomasterfrom
fix_first_migration_error

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:S This PR changes 10-29 lines, ignoring generated files. label Nov 6, 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 addresses and fixes issues related to Kubevirt virtual machine migrations by enhancing the controller's ability to manage network configurations. It introduces more specific handling for logical switch ports, both when a migration is initiated and when it concludes, ensuring that network settings are correctly adjusted for successful and failed migration scenarios.

Highlights

  • Improved VM Migration Handling: The logic for handling Kubevirt VM migrations has been refined to differentiate between successful and failed migration attempts, allowing for more precise post-migration cleanup.
  • Granular OVN Port Reset: A new function, ResetLogicalSwitchPortMigrateOptions, was introduced to replace the generic cleanup, enabling distinct handling of OVN logical switch port options based on whether a migration succeeded or failed.
  • Migration State Detection for Pods: New logic was added to detect when a VM pod is actively undergoing migration, allowing the system to set appropriate OVN logical switch port options during the migration process.
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 bug Something isn't working label Nov 6, 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 addresses an issue with VM migration failures by correctly handling the reset of OVN logical switch port options. It introduces separate logic for successful and failed migrations and adds logic to set migration options when a VM pod migration is detected. My review includes suggestions to refactor the code for better readability and maintainability by reducing code duplication and flattening nested conditional statements, and also to correct a stale error message.

Comment thread pkg/controller/pod.go
Comment on lines +667 to +678
if isVMPod {
if _, ok := pod.Labels["kubevirt.io/migrationJobUID"]; ok {
if sourceNode, ok := pod.Labels["kubevirt.io/nodeName"]; ok && sourceNode != pod.Spec.NodeName {
klog.Infof("VM pod %s/%s is migrating from %s to %s",
pod.Namespace, pod.Name, sourceNode, pod.Spec.NodeName)
if err := c.OVNNbClient.SetLogicalSwitchPortMigrateOptions(portName, sourceNode, pod.Spec.NodeName); err != nil {
klog.Errorf("failed to set migrate options for VM pod lsp %s: %v", portName, err)
return nil, 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.

medium

The nested if statements can be flattened to improve readability.

Suggested change
if isVMPod {
if _, ok := pod.Labels["kubevirt.io/migrationJobUID"]; ok {
if sourceNode, ok := pod.Labels["kubevirt.io/nodeName"]; ok && sourceNode != pod.Spec.NodeName {
klog.Infof("VM pod %s/%s is migrating from %s to %s",
pod.Namespace, pod.Name, sourceNode, pod.Spec.NodeName)
if err := c.OVNNbClient.SetLogicalSwitchPortMigrateOptions(portName, sourceNode, pod.Spec.NodeName); err != nil {
klog.Errorf("failed to set migrate options for VM pod lsp %s: %v", portName, err)
return nil, err
}
}
}
}
if isVMPod {
_, isMigrating := pod.Labels["kubevirt.io/migrationJobUID"]
sourceNode, hasSourceNode := pod.Labels["kubevirt.io/nodeName"]
if isMigrating && hasSourceNode && sourceNode != pod.Spec.NodeName {
klog.Infof("VM pod %s/%s is migrating from %s to %s",
pod.Namespace, pod.Name, sourceNode, pod.Spec.NodeName)
if err := c.OVNNbClient.SetLogicalSwitchPortMigrateOptions(portName, sourceNode, pod.Spec.NodeName); err != nil {
klog.Errorf("failed to set migrate options for VM pod lsp %s: %v", portName, err)
return nil, err
}
}
}

@coveralls
Copy link
Copy Markdown

coveralls commented Nov 6, 2025

Pull Request Test Coverage Report for Build 19155271956

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 16 (0.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.004%) to 21.532%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/controller/kubevirt.go 0 7 0.0%
pkg/controller/pod.go 0 9 0.0%
Totals Coverage Status
Change from base Build 19131241215: -0.004%
Covered Lines: 10938
Relevant Lines: 50798

💛 - Coveralls

Signed-off-by: clyi <clyi@alauda.io>
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 7, 2025
@changluyi changluyi merged commit 6781af1 into master Nov 7, 2025
74 checks passed
@changluyi changluyi deleted the fix_first_migration_error branch November 7, 2025 08:31
changluyi added a commit that referenced this pull request Nov 7, 2025
* fix migrate failed

Signed-off-by: clyi <clyi@alauda.io>

---------

Signed-off-by: clyi <clyi@alauda.io>
zbb88888 added a commit to zbb88888/kube-ovn that referenced this pull request Feb 1, 2026
This commit fixes KubeVirt VM migration failures (Issue kubeovn#6220) by:

1. Remove early return on MigrationState.Completed check that could
   skip cleanup logic for MigrationSucceeded/MigrationFailed phases

2. Add MigrationUID check to ensure we use state from current migration,
   not stale state from previous migration (from PR kubeovn#6239)

3. Change from ResetLogicalSwitchPortMigrateOptions to
   CleanLogicalSwitchPortMigrateOptions for migration cleanup:
   - Reset: keeps requested-chassis with new value, causing stale state
   - Clean: fully removes requested-chassis and activation-strategy

The root cause was PR kubeovn#5873 changing from Clean to Reset, which left
stale requested-chassis options that caused subsequent migrations to
fail with 'ovs interface not ready after 30s' errors.

Fixes: kubeovn#6220
Signed-off-by: Kube-OVN Developer <developer@kubeovn.io>
Signed-off-by: zbb88888 <jmdxjsjgcxy@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants