Skip to content

Conversation

@pcbailey
Copy link
Member

@pcbailey pcbailey commented Oct 2, 2025

📝 Description

This PR adds support for storage migration for multiple VMs across multiple namespaces. The alert in the modal has been adjusted to list the namespaces that conflict when more than one exists.

Jira: https://issues.redhat.com/browse/CNV-62749

🎥 Screenshot

After

storage-migration--AFTER--2025-10-02_09-38

Summary by CodeRabbit

  • New Features

    • Extended virtual machine migration to support multiple namespaces simultaneously
    • Added alerts to notify users of namespace conflicts during migration planning
    • Introduced new message indicating cross-cluster storage migration is not supported
  • Localization

    • Updated translations across English, Spanish, French, Japanese, Korean, and Chinese with improved migration-related messaging

@openshift-ci-robot
Copy link
Collaborator

openshift-ci-robot commented Oct 2, 2025

@pcbailey: This pull request references CNV-62749 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the bug to target the "4.21.0" version, but no target version was set.

In response to this:

📝 Description

This PR adds support for storage migration for multiple VMs across multiple namespaces. The alert in the modal has been adjusted to list the namespaces that conflict when more than one exists.

Jira: https://issues.redhat.com/browse/CNV-62749

🎥 Screenshot

After

storage-migration--AFTER--2025-10-02_09-38

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 openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci openshift-ci bot requested review from gouyang and rszwajko October 2, 2025 14:13
@openshift-ci openshift-ci bot added the approved This issue is something we want to fix label Oct 2, 2025
@pcbailey pcbailey force-pushed the bug--multi-namespace-storage-migration branch from 4db6f0b to ff403cf Compare October 2, 2025 22:49
Copy link
Member

@rszwajko rszwajko left a comment

Choose a reason for hiding this comment

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

We need to clarify the behavior for the remote clusters.

const { t } = useKubevirtTranslation();
const vmNamespaces = removeDuplicates(vms?.map((vm) => getNamespace(vm)));

const migrationNamespace = getNamespace(vms?.[0]);
Copy link
Member

Choose a reason for hiding this comment

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

accessReview for the bulk action is still based on the namespace from the first VM only - we should make sure that all VMs are from the same namespace OR check all of them

Copy link
Member Author

Choose a reason for hiding this comment

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

I looked, but don't see a way to do multiple access review checks. I want to make sure I'm not missing something before creating our own hook to do it.

Copy link
Member

Choose a reason for hiding this comment

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

I don't know a bulk access check hook - maybe @upalatucci can help. However I can share how this problem is solved for LazyMenuActions. The PR #3077 needs another iteration to fix tests but the concept is not new - the original code in the Console is working the same way:

  1. lazy pre-load access checks as soon as possible - the action is triggered by onHover event. The calls are memoized (lodash).
  2. the check is repeated when creating the menu items

In both cases the utility methods ignores failures - the assumption is that the backend will re-check anyway.
The performance impact due to lazy loading is small - it's less then 10 calls usually. In case of namespaces most of them should be memoized already.

}

if (namespaces.size === 1 && mtcInstalled) {
if (mtcInstalled) {
Copy link
Member

Choose a reason for hiding this comment

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

the check is for the local cluster - how about the remote?

Copy link
Member

@upalatucci upalatucci Oct 3, 2025

Choose a reason for hiding this comment

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

yes we should test this in the destination cluster, and that vms come all from the same cluster

Copy link
Member Author

Choose a reason for hiding this comment

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

@upalatucci How do I check for flags on a different cluster?

useEffect(() => {
Promise.all(
memoizedNamespaces?.map((ns) =>
fleetK8sList<IoK8sApiCoreV1PersistentVolumeClaim>({
Copy link
Member

Choose a reason for hiding this comment

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

in src/multicluster/k8sRequests.ts we have all the methods for GET POST and so on. It would be awesome to have kubevirtK8sList

Copy link
Member Author

Choose a reason for hiding this comment

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

I looked at the types for FleetK8sListOptions. It doesn't have a cluster property.

@pcbailey pcbailey force-pushed the bug--multi-namespace-storage-migration branch from ff403cf to 9079d77 Compare November 18, 2025 02:47
@coderabbitai
Copy link

coderabbitai bot commented Nov 18, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This pull request refactors virtual machine migration from single-namespace to multi-namespace support. It updates locale translations to reflect plural and parameterized MigPlan messages, extends MigPlan type with a namespaces array field, introduces new hooks for multi-namespace PVC fetching and conflict detection, renames components, and adds cluster-aware logic to migration action conditions.

Changes

Cohort / File(s) Summary
Locale translations
locales/en/plugin__kubevirt-plugin.json, locales/es/plugin__kubevirt-plugin.json, locales/fr/plugin__kubevirt-plugin.json, locales/ja/plugin__kubevirt-plugin.json, locales/ko/plugin__kubevirt-plugin.json, locales/zh/plugin__kubevirt-plugin.json
Replaced singular namespace MigPlan message with plural and namespace-scoped variants; added cross-cluster storage migration unsupported message.
Core type updates
src/utils/resources/migrations/constants.ts
Added optional namespaces: string[] property to MigPlan.spec type.
Utility functions
src/utils/utils/utils.ts, src/views/virtualmachines/actions/components/VirtualMachineMigration/utils/utils.ts
Added removeDuplicates() helper; added getExistingMigPlanNamespaces() to extract namespaces from MigPlan objects.
SDK imports
src/multicluster/k8sRequests.ts
Added imports for k8sList, fleetK8sList, and FleetK8sListOptions.
Migration modal refactoring
src/views/virtualmachines/actions/components/VirtualMachineMigration/VirtualMachineMigrationModal.tsx
Migrated from single-namespace to multi-namespace handling; replaced hooks for PVC and conflict detection; introduced VMMigrationNamespaceConflictsAlert component.
New migration components
src/views/virtualmachines/actions/components/VirtualMachineMigration/components/VMMigrationNamespaceConflictsAlert.tsx
New component rendering namespace conflicts alert with dynamic title and conflicting namespace list.
Component renames & import fixes
src/views/virtualmachines/actions/components/VirtualMachineMigration/components/VirtualMachineMigrationStatus.tsx, src/views/virtualmachines/actions/components/VirtualMachineMigration/components/tabs/VirtualMachineMigrationDetailsTab.tsx, src/views/virtualmachines/actions/components/VirtualMachineMigration/components/tabs/VirtualMachineMigrationReviewTab.tsx, src/views/virtualmachines/actions/components/VirtualMachineMigration/components/tabs/components/ReviewVolumesColumn.tsx, src/views/virtualmachines/actions/components/VirtualMachineMigration/components/tabs/components/utils.ts
Renamed VirtualMachineMigrationDetailsVirtualMachineMigrationDetailsTab; updated import paths to reflect directory structure changes.
Migration hooks (namespace/PVC handling)
src/views/virtualmachines/actions/components/VirtualMachineMigration/hooks/useCreateEmptyMigPlan.ts, src/views/virtualmachines/actions/components/VirtualMachineMigration/hooks/useMigrationNamespacesPVCs.ts
Updated useCreateEmptyMigPlan to accept namespace array with memoization; added new useMigrationNamespacesPVCs hook for fetching PVCs across multiple namespaces.
Migration hooks (conflict & namespace detection)
src/views/virtualmachines/actions/components/VirtualMachineMigration/hooks/useExistingMigPlanConflicts.ts
Added new hook to detect namespace conflicts between VMs and existing MigPlans; replaces useExistingMigrationPlan (removed).
Migration utilities
src/views/virtualmachines/actions/components/VirtualMachineMigration/utils/migrateVMs.ts
Updated getEmptyMigPlan() to accept namespace array instead of single string.
Action factory & cluster awareness
src/views/virtualmachines/actions/BulkVirtualMachineActionFactory.tsx, src/views/virtualmachines/actions/hooks/useMultipleVirtualMachineActions.tsx, src/views/virtualmachines/actions/utils.ts
Added isDisabled parameter to migrateStorage action; introduced cluster-aware logic with isSameCluster() utility; refactored action conditions to check cluster/namespace uniformity and target cluster status.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant Modal as VirtualMachineMigrationModal
    participant Hooks as Migration Hooks
    participant K8s as Kubernetes API
    participant Alert as VMMigrationNamespaceConflictsAlert
    
    User->>Modal: Initiate multi-VM migration
    
    Note over Modal: Collect VM namespaces & clusters
    
    Modal->>Hooks: useExistingMigPlanConflicts(vmNamespaces)
    Hooks->>K8s: Fetch MigPlans
    K8s-->>Hooks: MigPlan list
    Hooks->>Hooks: Compute namespace conflicts
    Hooks-->>Modal: {migPlansLoaded, namespaceConflicts}
    
    Modal->>Hooks: useMigrationNamespacesPVCs(vmNamespaces)
    Hooks->>K8s: Fetch PVCs per namespace (parallel)
    K8s-->>Hooks: PVCs
    Hooks-->>Modal: pvcsInNamespaces
    
    alt Conflicts detected
        Modal->>Alert: Render with namespaceConflicts
        Alert-->>User: Show conflict alert
    else No conflicts
        Modal->>Alert: Render details tab with PVCs
        Alert-->>User: Show migration review form
    end
    
    User->>Modal: Submit migration
    Modal->>Hooks: useCreateEmptyMigPlan(vmNamespaces)
    Hooks-->>Modal: MigPlan with namespaces array
    Modal->>K8s: Create MigPlan
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Locale files: Repetitive changes across 6 files with consistent pattern (low effort per file)
  • VirtualMachineMigrationModal.tsx: Significant logic refactoring with hook replacements and new data flows requires careful review of multi-namespace logic and state management
  • New hooks (useExistingMigPlanConflicts, useMigrationNamespacesPVCs): Moderate complexity; clear responsibility but requires validation of Kubernetes API usage and memoization patterns
  • Action cluster-awareness (useMultipleVirtualMachineActions.tsx): Logic changes around cluster/namespace checks need verification of conditional flow
  • Multiple import path adjustments: Low effort, mostly mechanical

Areas requiring extra attention:

  • Namespace conflict detection logic and intersection computation in useExistingMigPlanConflicts
  • Multi-namespace PVC fetching parallelization in useMigrationNamespacesPVCs
  • VirtualMachineMigrationModal state flow changes and hook dependency ordering
  • Cluster-aware migration action enablement conditions in useMultipleVirtualMachineActions
  • Impact of removeExistingMigrationPlan.ts removal on downstream consumers

Possibly related PRs

  • PR #3185: Introduces multicluster-aware data-fetching patterns and cluster-scoped list/watch helpers; shares similar refactoring of k8s data hooks with this PR.

Suggested labels

lgtm

Suggested reviewers

  • gouyang
  • aviavissar
  • adamviktora

Poem

🐰 Multi-namespaces now, no more single-space blues,
PVCs hop between clusters, migration's good news!
Conflicts we detect, with memoized delight,
Storage migrations bloom—in each namespace's light! 🌸

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding support for storage migration across multiple namespaces, which aligns with the core objective reflected throughout the changeset.
Description check ✅ Passed The description provides a clear purpose, includes a Jira reference, and demonstrates the change with a screenshot. However, it lacks a demo section as suggested by the template.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci-robot
Copy link
Collaborator

openshift-ci-robot commented Nov 18, 2025

@pcbailey: This pull request references CNV-62749 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the bug to target the "4.21.0" version, but no target version was set.

In response to this:

📝 Description

This PR adds support for storage migration for multiple VMs across multiple namespaces. The alert in the modal has been adjusted to list the namespaces that conflict when more than one exists.

Jira: https://issues.redhat.com/browse/CNV-62749

🎥 Screenshot

After

storage-migration--AFTER--2025-10-02_09-38

Summary by CodeRabbit

  • New Features

  • Extended virtual machine migration to support multiple namespaces simultaneously

  • Added alerts to notify users of namespace conflicts during migration planning

  • Introduced new message indicating cross-cluster storage migration is not supported

  • Localization

  • Updated translations across English, Spanish, French, Japanese, Korean, and Chinese with improved migration-related messaging

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 openshift-eng/jira-lifecycle-plugin repository.

@pcbailey pcbailey force-pushed the bug--multi-namespace-storage-migration branch from 9079d77 to f46df28 Compare November 18, 2025 02:52
@pcbailey pcbailey marked this pull request as draft November 18, 2025 02:53
@pcbailey
Copy link
Member Author

/retest

@upalatucci
Copy link
Member

/lgtm

@openshift-ci openshift-ci bot added the lgtm Passed code review, ready for merge label Nov 18, 2025
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Nov 18, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: pcbailey, upalatucci

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

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [pcbailey,upalatucci]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@upalatucci
Copy link
Member

/remove-lgtm

@openshift-ci openshift-ci bot removed the lgtm Passed code review, ready for merge label Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants