Skip to content

Conversation

@rishabh625
Copy link
Contributor

@rishabh625 rishabh625 commented Aug 19, 2025

What this PR does / why we need it

This PR aims to improve fetching of vmware virtual machines details efficiently

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 #790

Special notes for your reviewer

Testing done

  1. Deployed changes and verified the vmware custom resource created by version 0.3.0 and by this PR change is identical
  2. Tested total time taken to create VMware machine custom resource.

please add testing details (logs, screenshots, etc.)

Time taken to create 1700 VMs - 50 seconds

Age of Pod - 8m
Age of CR created - 7m

Time taken to create CR - 50 secs ( age of pod - age of cr created)

Screenshot from 2025-09-18 15-33-47

Summary by Bito

This pull request refactors the VMware VM fetching mechanism to improve efficiency through batched processing, improved concurrency management, and reduced API calls. The changes include adding a Reauth flag to session setup, optimizing annotation and network name retrieval, enhancing RDM disk processing, and implementing improved host cluster information extraction and connection cleanup logic.

Copy link
Contributor

@windsurf-bot windsurf-bot bot left a comment

Choose a reason for hiding this comment

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

Other comments (3)
  • k8s/migration/internal/controller/vmwarecreds_controller.go (127-130) The error message when creating/updating VMwareMachine doesn't include which VM failed, making it difficult to troubleshoot issues with specific VMs.
    		err = utils.CreateOrUpdateVMwareMachine(ctx, scope.Client, scope.VMwareCreds, &vm)
    		if err != nil {
    			return ctrl.Result{}, errors.Wrap(err, fmt.Sprintf("Error creating or updating VMwareMachine '%s' for VMwareCreds", vm.Name))
    		}
    
  • k8s/migration/internal/controller/vmwarecreds_controller.go (123-126) The current logging when skipping VMs with empty fields could be more informative. Consider logging which specific fields are empty for each VM to make debugging easier.
    		if vm.Name == "" || vm.ESXiName == "" || vm.ClusterName == "" {
    			ctxlog.Info("Skipping VM with empty required fields", 
    				"VM", vm.Name, 
    				"ESXi", vm.ESXiName, 
    				"Cluster", vm.ClusterName, 
    				"nameEmpty", vm.Name == "", 
    				"esxiEmpty", vm.ESXiName == "", 
    				"clusterEmpty", vm.ClusterName == "")
    			continue
    		}
    
  • k8s/migration/config/crd/bases/vjailbreak.k8s.pf9.io_rdmdisks.yaml (53-53) The description for `openstackVolumeRef` has been changed from 'OpenstackVolumeRefInfo' to 'OpenstackVolumeRef ...'. For clarity in documentation, the description should use the exact type name without ellipsis. If the field type is indeed `OpenstackVolumeRef`, then the description should be updated accordingly without the '...'.

💡 To request another review, post a new comment with "/windsurf-review".

@bito-code-review
Copy link
Contributor

bito-code-review bot commented Aug 19, 2025

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
Other Improvements - Minor CRD Config Update

vjailbreak.k8s.pf9.io_migrations.yaml - Refined the CRD status configuration for clarity and consistency.

Feature Improvement - Enhanced VMware VM Fetching & Resource Management

vmwarecreds_controller.go - Optimized the VMwareCreds controller by introducing batched VM processing with improved concurrency, error handling, and cleanup of idle connections.

credutils.go - Refactored VMware VM details fetching with streamlined datastore and network extraction, improved session handling and reduced redundant API calls.

maintenance_mode.go - Enhanced maintenance mode handling by adding proper idle connection cleanup and a robust VMware client logout mechanism.

rollingmigrationutils.go - Improved VMware client session cleanup and error handling in resource management functions to ensure efficient processing and recovery.

Testing - Refined Test Mocks for Consistent API Interfaces

migrate_test.go - Updated mock VM operations to match revised API signatures, ensuring accurate simulation of VM disk and snapshot operations.

openstackops_mock.go - Modified the CreatePort method signature to include a fallbackToDHCP flag, enhancing test robustness and simulation accuracy.

vmops_mock.go - Adjusted the GetVMInfo mock to incorporate an additional parameter for RDM disks, thereby aligning test interfaces with production changes.

Copy link
Contributor

@bito-code-review bito-code-review 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 Agent Run #23be1e

Actionable Suggestions - 1
  • k8s/migration/pkg/utils/credutils.go - 1
Additional Suggestions - 2
  • k8s/migration/pkg/utils/credutils.go - 2
    • Redundant VM configuration and name prefix check · Line 1597-1599
      Duplicate check for VM config and vCLS prefix. The same condition is checked twice, making the second check redundant. Remove the second check to improve code clarity and performance.
      Code suggestion
       @@ -1647,9 +1647,6 @@
        		// NIC & Guest Network extraction
        		nic, _ := ExtractVirtualNICs(&moVM)
        		guestNetwork, _ := ExtractGuestNetworkInfo(&moVM)
      -
      -		if moVM.Config == nil || strings.HasPrefix(moVM.Config.Name, "vCLS-") {
      -			continue
      -		}
       
        		// Determine cluster name
        		var clusterName string
    • Redundant map store operation causing inefficiency · Line 1678-1678
      Duplicate `hostSystemMap.Store()` call with the same key but different value. The second call overwrites the first one, making the first call redundant.
      Code suggestion
       @@ -1677,8 +1677,7 @@
        					ESXIName:    esxiName,
        					ClusterName: clusterName,
        				}
      -				hostSystemMap.Store(moVM.Runtime.Host.Value, clusterDetails)
        				hostSystemMap.Store(moVM.Runtime.Host.Value, clusterDetails)
Review Details
  • Files reviewed - 4 · Commit Range: ad60b93..ad60b93
    • deploy/00crds.yaml
    • k8s/migration/config/crd/bases/vjailbreak.k8s.pf9.io_rdmdisks.yaml
    • k8s/migration/internal/controller/vmwarecreds_controller.go
    • k8s/migration/pkg/utils/credutils.go
  • Files skipped - 0
  • Tools
    • Golangci-lint (Linter) - ✖︎ Failed
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Default Agent You can customize the agent settings here or contact your Bito workspace admin at mithil@platform9.com.

Documentation & Help

AI Code Review powered by Bito Logo

@bito-code-review
Copy link
Contributor

bito-code-review bot commented Aug 19, 2025

Bito Review Skipped - No Changes Detected

Bito didn't review this pull request because we did not detect any changes in the pull request to review.

Copy link
Contributor

@bito-code-review bito-code-review 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 Agent Run #401feb

Actionable Suggestions - 1
  • k8s/migration/pkg/utils/credutils.go - 1
Review Details
  • Files reviewed - 1 · Commit Range: ad60b93..d6c4704
    • k8s/migration/pkg/utils/credutils.go
  • Files skipped - 0
  • Tools
    • Golangci-lint (Linter) - ✖︎ Failed
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Default Agent You can customize the agent settings here or contact your Bito workspace admin at mithil@platform9.com.

Documentation & Help

AI Code Review powered by Bito Logo

@rishabh625
Copy link
Contributor Author

@sarika-p9 @OmkarDeshpande7 : Please take commits from this PR :
I have tested this PR and found issues

RDMDisk attributes - not populating.

Considering my time constraints please take it over for this change from here.

@bito-code-review
Copy link
Contributor

bito-code-review bot commented Sep 16, 2025

Bito Review Skipped - No Changes Detected

Bito didn't review this pull request because we did not detect any changes in the pull request to review.

Copy link
Contributor

@bito-code-review bito-code-review 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 Agent Run #27d427

Actionable Suggestions - 1
  • k8s/migration/internal/controller/vmwarecreds_controller.go - 1
Review Details
  • Files reviewed - 5 · Commit Range: d6c4704..f8decca
    • k8s/migration/internal/controller/vmwarecreds_controller.go
    • k8s/migration/pkg/utils/credutils.go
    • v2v-helper/migrate/migrate_test.go
    • v2v-helper/openstack/openstackops_mock.go
    • v2v-helper/vm/vmops_mock.go
  • Files skipped - 0
  • Tools
    • Golangci-lint (Linter) - ✖︎ Failed
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Default Agent You can customize the agent settings here or contact your Bito workspace admin at mithil@platform9.com.

Documentation & Help

AI Code Review powered by Bito Logo

Copy link
Contributor

@bito-code-review bito-code-review 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 Agent Run #e02605

Actionable Suggestions - 7
  • k8s/migration/internal/controller/vmwarecreds_controller.go - 3
  • k8s/migration/pkg/utils/credutils.go - 1
  • k8s/migration/pkg/utils/rollingmigrationutils.go - 1
  • k8s/migration/pkg/utils/maintenance_mode.go - 2
Additional Suggestions - 2
  • k8s/migration/pkg/utils/credutils.go - 1
    • Redundant nil check · Line 1568-1568
      Redundant nil check for moVM.Config. The same condition is already checked at line 1555, making this check unreachable and unnecessary. This creates confusion about the control flow and suggests the code structure needs cleanup.
      Code suggestion
       @@ -1567,4 +1567,1 @@
      -		// NIC & Guest Network extraction
      -		nicList, _ := ExtractVirtualNICs(&moVM)
      -		if moVM.Config == nil || strings.HasPrefix(moVM.Config.Name, "vCLS-") {
      -			continue
      +		// NIC & Guest Network extraction
      +		nicList, _ := ExtractVirtualNICs(&moVM)
  • k8s/migration/internal/controller/vmwarecreds_controller.go - 1
    • Redundant cleanup defer · Line 106-106
      Remove the redundant defer statement at line 106 since we've already added a more comprehensive cleanup mechanism earlier in the function. Having two defer statements for the same cleanup operation would attempt to logout twice, which could cause issues.
      Code suggestion
       @@ -105,2 +105,1 @@
      -	// log out from vCenter or ESXI
      -	defer utils.LogoutVMwareClient(ctx, r.Client, scope.VMwareCreds, connection) // Logout the client
      +	// log out from vCenter or ESXI
Review Details
  • Files reviewed - 4 · Commit Range: f8decca..4e1e6cf
    • k8s/migration/internal/controller/vmwarecreds_controller.go
    • k8s/migration/pkg/utils/credutils.go
    • k8s/migration/pkg/utils/maintenance_mode.go
    • k8s/migration/pkg/utils/rollingmigrationutils.go
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Golangci-lint (Linter) - ✖︎ Failed

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Default Agent You can customize the agent settings here or contact your Bito workspace admin at mithil@platform9.com.

Documentation & Help

AI Code Review powered by Bito Logo

Copy link
Contributor

@bito-code-review bito-code-review 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 Agent Run #17f560

Actionable Suggestions - 1
  • k8s/migration/pkg/utils/rollingmigrationutils.go - 1
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • pkg/vpwned/upgrade/version_checker.go - 1
Review Details
  • Files reviewed - 6 · Commit Range: 4e1e6cf..e454688
    • pkg/vpwned/server/version.go
    • pkg/vpwned/upgrade/version_checker.go
    • k8s/migration/internal/controller/vmwarecreds_controller.go
    • k8s/migration/pkg/utils/credutils.go
    • k8s/migration/pkg/utils/maintenance_mode.go
    • k8s/migration/pkg/utils/rollingmigrationutils.go
  • Files skipped - 0
  • Tools
    • Golangci-lint (Linter) - ✖︎ Failed
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Default Agent You can customize the agent settings here or contact your Bito workspace admin at mithil@platform9.com.

Documentation & Help

AI Code Review powered by Bito Logo

rishabh625 and others added 2 commits September 22, 2025 11:00
Co-authored-by: bito-code-review[bot] <188872107+bito-code-review[bot]@users.noreply.github.com>
Signed-off-by: rishabh625 <43094970+rishabh625@users.noreply.github.com>
@bito-code-review
Copy link
Contributor

bito-code-review bot commented Sep 22, 2025

Code Review Agent Run #238473

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: e454688..08a9102
    • k8s/migration/pkg/utils/maintenance_mode.go
    • k8s/migration/internal/controller/vmwarecreds_controller.go
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Golangci-lint (Linter) - ✖︎ Failed

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Default Agent You can customize the agent settings here or contact your Bito workspace admin at mithil@platform9.com.

Documentation & Help

AI Code Review powered by Bito Logo

Copy link
Contributor

@bito-code-review bito-code-review 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 Agent Run #a7a045

Actionable Suggestions - 1
  • k8s/migration/pkg/utils/credutils.go - 1
Review Details
  • Files reviewed - 1 · Commit Range: 08a9102..1c6742a
    • k8s/migration/pkg/utils/credutils.go
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Golangci-lint (Linter) - ✖︎ Failed

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Default Agent You can customize the agent settings here or contact your Bito workspace admin at mithil@platform9.com.

Documentation & Help

AI Code Review powered by Bito Logo

Copy link
Contributor

@bito-code-review bito-code-review 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 Agent Run #e94e1c

Actionable Suggestions - 1
  • k8s/migration/pkg/utils/maintenance_mode.go - 1
Review Details
  • Files reviewed - 4 · Commit Range: 1c6742a..036d121
    • k8s/migration/internal/controller/vmwarecreds_controller.go
    • k8s/migration/pkg/utils/credutils.go
    • k8s/migration/pkg/utils/maintenance_mode.go
    • k8s/migration/pkg/utils/rollingmigrationutils.go
  • Files skipped - 0
  • Tools
    • Golangci-lint (Linter) - ✖︎ Failed
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Default Agent You can customize the agent settings here or contact your Bito workspace admin at mithil@platform9.com.

Documentation & Help

AI Code Review powered by Bito Logo

Copy link
Contributor

@bito-code-review bito-code-review 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 Agent Run #e89271

Actionable Suggestions - 2
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • k8s/migration/pkg/utils/credutils.go - 1
Review Details
  • Files reviewed - 5 · Commit Range: 036d121..60fdffd
    • k8s/migration/pkg/utils/credutils.go
    • k8s/migration/internal/controller/vmwarecreds_controller.go
    • k8s/migration/pkg/utils/maintenance_mode.go
    • k8s/migration/pkg/utils/rollingmigrationutils.go
    • k8s/migration/config/crd/bases/vjailbreak.k8s.pf9.io_migrations.yaml
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Golangci-lint (Linter) - ✖︎ Failed

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Default Agent You can customize the agent settings here or contact your Bito workspace admin at mithil@platform9.com.

Documentation & Help

AI Code Review powered by Bito Logo

@bito-code-review
Copy link
Contributor

bito-code-review bot commented Sep 25, 2025

Bito Review Skipped - No Changes Detected

Bito didn't review this pull request because we did not detect any changes in the pull request to review.

@sharma-tapas
Copy link
Collaborator

@rishabh625 Please rebase the PR to the latest master, I will run the build again, also please share some scale testing numbers of before and after your change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Perf] Research on how we can speed up VMWare Machine details CR fetch

3 participants