-
Notifications
You must be signed in to change notification settings - Fork 28
fix: improved fetching details of VM from vmware in less API calls #828
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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".
k8s/migration/pkg/utils/credutils.go
Outdated
| clusterName = val.(clusterDetails).ClusterName | ||
| esxiName = val.(clusterDetails).ESXIName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type assertion doesn't check if the assertion is successful before using the result. If the value in the map is not of type clusterDetails, this will cause a panic. Consider using the two-value form of type assertion to handle this safely:
| clusterName = val.(clusterDetails).ClusterName | |
| esxiName = val.(clusterDetails).ESXIName | |
| if details, ok := val.(clusterDetails); ok { | |
| clusterName = details.ClusterName | |
| esxiName = details.ESXIName | |
| } else { | |
| log.Error(nil, "Invalid type in hostSystemMap", "VM", moVM.Config.Name) | |
| continue | |
| } |
k8s/migration/pkg/utils/credutils.go
Outdated
| } | ||
| } | ||
|
|
||
| var hostSystemMap sync.Map |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hostSystemMap is declared as a global variable which could lead to race conditions if multiple goroutines access it concurrently. Consider making this map local to the getVMDetails function or passing it as a parameter to maintain proper encapsulation and thread safety.
k8s/migration/pkg/utils/credutils.go
Outdated
| if !ok { | ||
| // Get the host name and parent (cluster) information | ||
| host := mo.HostSystem{} | ||
| hostSystemMap.Store(host.Reference().Value, host) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code stores a host reference value in the hostSystemMap before retrieving its properties. If the subsequent property retrieval fails, an empty host object will remain in the map. Consider moving the hostSystemMap.Store() call after successfully retrieving the host properties.
Changelist by BitoThis pull request implements the following key changes.
|
There was a problem hiding this 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
- Premature storage of host reference in map · Line 1661-1662
Additional Suggestions - 2
-
k8s/migration/pkg/utils/credutils.go - 2
-
Redundant VM configuration and name prefix check · Line 1597-1599Duplicate 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-1678Duplicate `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
k8s/migration/pkg/utils/credutils.go
Outdated
| hostSystemMap.Store(host.Reference().Value, host) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The host reference value is stored in the hostSystemMap before retrieving the host data, causing potential race conditions. Store the host details only after successfully retrieving the data.
Code suggestion
Check the AI-generated fix before applying
- hostSystemMap.Store(host.Reference().Value, host)
-
err = property.DefaultCollector(client).RetrieveOne(ctx, *moVM.Runtime.Host, []string{"name", "parent"}, &host)
if err != nil {
log.Error(err, "failed to get host name", "VM NAME", moVM.Config.Name)
@@ -1677,6 +1675,7 @@
ESXIName: esxiName,
ClusterName: clusterName,
}
+ hostSystemMap.Store(moVM.Runtime.Host.Value, clusterDetails)
hostSystemMap.Store(moVM.Runtime.Host.Value, clusterDetails)
Code Review Run #23be1e
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
|
Bito Review Skipped - No Changes Detected |
There was a problem hiding this 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
- RDM disk info updates overwritten in loop · Line 1398-1408
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
k8s/migration/pkg/utils/credutils.go
Outdated
| UUID: b.LunUuid, | ||
| DisplayName: "", | ||
| }) | ||
| rdmDisks, err = populateRDMDiskInfoFromAttributes(ctx, rdmDisks, attributeMap[moVM.Reference().Value]) | ||
| if err != nil { | ||
| log.Error(err, "failed to populate RDM disk info from attributes", "VM", moVM.Config.Name) | ||
| continue | ||
| } | ||
| case *types.VirtualDiskFlatVer2BackingInfo, *types.VirtualDiskSparseVer2BackingInfo: | ||
| diskLabels = append(diskLabels, disk.DeviceInfo.GetDescription().Label) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The RDM disk info is populated from attributes for each disk individually inside the loop, but the function returns the entire updated array. This causes only the last disk's updates to be preserved, overwriting previous updates.
Code suggestion
Check the AI-generated fix before applying
| UUID: b.LunUuid, | |
| DisplayName: "", | |
| }) | |
| rdmDisks, err = populateRDMDiskInfoFromAttributes(ctx, rdmDisks, attributeMap[moVM.Reference().Value]) | |
| if err != nil { | |
| log.Error(err, "failed to populate RDM disk info from attributes", "VM", moVM.Config.Name) | |
| continue | |
| } | |
| case *types.VirtualDiskFlatVer2BackingInfo, *types.VirtualDiskSparseVer2BackingInfo: | |
| diskLabels = append(diskLabels, disk.DeviceInfo.GetDescription().Label) | |
| } | |
| UUID: b.LunUuid, | |
| DisplayName: "", | |
| }) | |
| case *types.VirtualDiskFlatVer2BackingInfo, *types.VirtualDiskSparseVer2BackingInfo: | |
| diskLabels = append(diskLabels, disk.DeviceInfo.GetDescription().Label) | |
| } |
Code Review Run #401feb
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
|
@sarika-p9 @OmkarDeshpande7 : Please take commits from this PR : RDMDisk attributes - not populating. Considering my time constraints please take it over for this change from here. |
|
Bito Review Skipped - No Changes Detected |
… details retrieval
…al parameters for improved functionality
There was a problem hiding this 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
- Cleanup operations in wrong location · Line 131-139
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
| err = utils.DeleteStaleVMwareMachines(ctx, r.Client, scope.VMwareCreds, vminfo) | ||
| if err != nil { | ||
| return ctrl.Result{}, errors.Wrap(err, fmt.Sprintf("Error finding deleted VMs for VMwareCreds '%s'", scope.Name())) | ||
| } | ||
| err = utils.DeleteStaleVMwareClustersAndHosts(ctx, scope) | ||
| if err != nil { | ||
| return ctrl.Result{}, errors.Wrap(err, fmt.Sprintf("Error finding deleted clusters and hosts for VMwareCreds '%s'", scope.Name())) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cleanup operations DeleteStaleVMwareMachines and DeleteStaleVMwareClustersAndHosts have been incorrectly moved inside the VM processing loop. These operations should run once per reconciliation, not once per VM. The current placement would execute these cleanup functions N times (once for each VM) instead of once per reconciliation cycle, leading to severe performance degradation and potential race conditions. Move these operations outside the for _, vm := range vminfo loop to restore the correct behavior.
Code suggestion
Check the AI-generated fix before applying
| err = utils.DeleteStaleVMwareMachines(ctx, r.Client, scope.VMwareCreds, vminfo) | |
| if err != nil { | |
| return ctrl.Result{}, errors.Wrap(err, fmt.Sprintf("Error finding deleted VMs for VMwareCreds '%s'", scope.Name())) | |
| } | |
| err = utils.DeleteStaleVMwareClustersAndHosts(ctx, scope) | |
| if err != nil { | |
| return ctrl.Result{}, errors.Wrap(err, fmt.Sprintf("Error finding deleted clusters and hosts for VMwareCreds '%s'", scope.Name())) | |
| } | |
| } | |
| } | |
| err = utils.DeleteStaleVMwareMachines(ctx, r.Client, scope.VMwareCreds, vminfo) | |
| if err != nil { | |
| return ctrl.Result{}, errors.Wrap(err, fmt.Sprintf("Error finding deleted VMs for VMwareCreds '%s'", scope.Name())) | |
| } | |
| err = utils.DeleteStaleVMwareClustersAndHosts(ctx, scope) | |
| if err != nil { | |
| return ctrl.Result{}, errors.Wrap(err, fmt.Sprintf("Error finding deleted clusters and hosts for VMwareCreds '%s'", scope.Name())) | |
| } |
Code Review Run #27d427
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
…ent and batch processing for VMs
There was a problem hiding this 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
- Division by zero risk · Line 131-135
- Division by zero risk · Line 131-135
- Resource leak in error handling · Line 92-94
-
k8s/migration/pkg/utils/credutils.go - 1
- Nil pointer dereference · Line 1593-1595
-
k8s/migration/pkg/utils/rollingmigrationutils.go - 1
- Defer placement causes nil panic · Line 221-225
-
k8s/migration/pkg/utils/maintenance_mode.go - 2
- Nil pointer dereference · Line 179-179
- Nil pointer dereference · Line 178-180
Additional Suggestions - 2
-
k8s/migration/pkg/utils/credutils.go - 1
-
Redundant nil check · Line 1568-1568Redundant 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-106Remove 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
k8s/migration/pkg/utils/credutils.go
Outdated
| if moVM.Config == nil { | ||
| log.Error(fmt.Errorf("vm config is nil"), "skipping VM", "VM NAME", moVM.Config.Name) | ||
| continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical nil pointer dereference detected. When moVM.Config is nil, the code attempts to access moVM.Config.Name in the log.Error call, which will cause a runtime panic. This breaks the VM processing flow and could crash the entire migration operation. Use moVM.Summary.Config.Name as a safe fallback when Config is nil.
Code suggestion
Check the AI-generated fix before applying
| if moVM.Config == nil { | |
| log.Error(fmt.Errorf("vm config is nil"), "skipping VM", "VM NAME", moVM.Config.Name) | |
| continue | |
| if moVM.Config == nil { | |
| vmName := "unknown" | |
| if moVM.Summary != nil && moVM.Summary.Config != nil { | |
| vmName = moVM.Summary.Config.Name | |
| } | |
| log.Error(fmt.Errorf("vm config is nil"), "skipping VM", "VM NAME", vmName) | |
| continue |
Code Review Run #e02605
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
| c, err := ValidateVMwareCreds(ctx, k8sClient, vmwarecreds) | ||
| defer LogoutVMwareClient(ctx, k8sClient, vmwarecreds, c) // Logout the client | ||
|
|
||
| if err != nil { | ||
| return nil, nil, errors.Wrap(err, "failed to validate vCenter connection") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The defer LogoutVMwareClient statement is placed before the error check on line 224, which means it will execute even when ValidateVMwareCreds returns an error and nil client. This will cause LogoutVMwareClient to be called with a nil client pointer, leading to a nil pointer dereference panic in production. Move the defer statement to after the error check to ensure it only executes when a valid client is available. This affects the GetESXiHostSystem function and its downstream callers including any migration workflows that use this function.
Code suggestion
Check the AI-generated fix before applying
| c, err := ValidateVMwareCreds(ctx, k8sClient, vmwarecreds) | |
| defer LogoutVMwareClient(ctx, k8sClient, vmwarecreds, c) // Logout the client | |
| if err != nil { | |
| return nil, nil, errors.Wrap(err, "failed to validate vCenter connection") | |
| c, err := ValidateVMwareCreds(ctx, k8sClient, vmwarecreds) | |
| if err != nil { | |
| return nil, nil, errors.Wrap(err, "failed to validate vCenter connection") | |
| } | |
| defer LogoutVMwareClient(ctx, k8sClient, vmwarecreds, c) // Logout the client |
Code Review Run #e02605
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
| // Connect and log in to ESX or vCenter | ||
| connection, err := utils.ValidateVMwareCreds(ctx, r.Client, scope.VMwareCreds) | ||
| if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The defer statement for LogoutVMwareClient is placed after the error handling, which means it will only execute when validation succeeds. This creates a resource leak: if ValidateVMwareCreds returns an error, the connection might be partially established but LogoutVMwareClient will never be called to clean up resources. Additionally, the LogoutVMwareClient function has implementation issues - it creates a new session and attempts logout using potentially different credentials than what was used for login. Move the defer statement to immediately after connection establishment and wrap it in a nil check to ensure proper cleanup regardless of validation success or failure.
Code suggestion
Check the AI-generated fix before applying
| // Connect and log in to ESX or vCenter | |
| connection, err := utils.ValidateVMwareCreds(ctx, r.Client, scope.VMwareCreds) | |
| if err != nil { | |
| // Connect and log in to ESX or vCenter | |
| connection, err := utils.ValidateVMwareCreds(ctx, r.Client, scope.VMwareCreds) | |
| // Ensure logout happens regardless of validation result | |
| defer func() { | |
| if connection != nil { | |
| utils.LogoutVMwareClient(ctx, r.Client, scope.VMwareCreds, connection) | |
| } | |
| }() | |
| if err != nil { |
Code Review Run #e02605
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
| func GetMaintenanceModeOptions(ctx context.Context, k8sClient client.Client, vmwcreds *vjailbreakv1alpha1.VMwareCreds, hostName string) (*types.HostMaintenanceSpec, error) { | ||
| // Connect to vCenter | ||
| c, err := ValidateVMwareCreds(ctx, k8sClient, vmwcreds) | ||
| defer LogoutVMwareClient(ctx, k8sClient, vmwcreds, c) // Logout the client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The defer statement will execute LogoutVMwareClient even when ValidateVMwareCreds returns an error and nil client, causing a nil pointer dereference in LogoutVMwareClient when it tries to use the nil vcentreClient parameter. This will crash the application when vCenter connection fails. Wrap the defer call in an anonymous function with a nil check to prevent this issue.
Code suggestion
Check the AI-generated fix before applying
| defer LogoutVMwareClient(ctx, k8sClient, vmwcreds, c) // Logout the client | |
| defer func() { | |
| if c != nil { | |
| LogoutVMwareClient(ctx, k8sClient, vmwcreds, c) // Logout the client | |
| } | |
| }() |
Code Review Run #e02605
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
| c, err := ValidateVMwareCreds(ctx, k8sClient, vmwcreds) | ||
| defer LogoutVMwareClient(ctx, k8sClient, vmwcreds, c) // Logout the client | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The defer statement will execute LogoutVMwareClient even when ValidateVMwareCreds returns an error and nil client, causing a nil pointer dereference in LogoutVMwareClient when it tries to use the nil vcentreClient parameter. This will crash the application when vCenter connection fails. Apply the same fix as in line 31 to maintain consistency.
Code suggestion
Check the AI-generated fix before applying
| c, err := ValidateVMwareCreds(ctx, k8sClient, vmwcreds) | |
| defer LogoutVMwareClient(ctx, k8sClient, vmwcreds, c) // Logout the client | |
| c, err := ValidateVMwareCreds(ctx, k8sClient, vmwcreds) | |
| defer func() { | |
| if c != nil { | |
| LogoutVMwareClient(ctx, k8sClient, vmwcreds, c) | |
| } | |
| }() |
Code Review Run #e02605
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
…-in-one-call to seperate changes
…ed properly in maintenance mode
…ed properly in maintenance mode
There was a problem hiding this 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
- Resource cleanup order issue · Line 228-228
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
- Registry migration risk · Line 141-141
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
| } | ||
|
|
||
| if c != nil { | ||
| defer c.CloseIdleConnections() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The defer statement restructuring introduces a critical resource management issue. The change separates CloseIdleConnections and LogoutVMwareClient into two independent defer statements, which breaks the intended cleanup order. Additionally, there's a duplicate defer at line 222 that will cause LogoutVMwareClient to be called twice - once from the top-level defer (line 222) and once from the conditional defer (lines 229-231). This will lead to double logout attempts and potential connection leaks. The fix restores the nested structure and removes the redundant top-level defer.
Code suggestion
Check the AI-generated fix before applying
- defer LogoutVMwareClient(ctx, k8sClient, vmwarecreds, c) // Logout the client
if err != nil {
return nil, nil, errors.Wrap(err, "failed to validate vCenter connection")
@@ -228,8 +227,8 @@
if c != nil {
- defer c.CloseIdleConnections()
defer func() {
+ defer c.CloseIdleConnections()
LogoutVMwareClient(ctx, k8sClient, vmwarecreds, c)
}()
}
Code Review Run #17f560
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
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>
Code Review Agent Run #238473Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
… and streamline client creation
… and streamline client creation
There was a problem hiding this 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
- Missing client caching · Line 514-515
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
k8s/migration/pkg/utils/credutils.go
Outdated
| c := new(vim25.Client) | ||
| settings, err := k8sutils.GetVjailbreakSettings(ctx, k3sclient) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR removes the entire client caching mechanism by eliminating the providerClientCache usage. This breaks the VMware client reuse functionality that was designed to cache vim25.Client instances per secret name. Without caching, every call to ValidateVMwareCreds will create a new client connection instead of reusing existing ones, causing significant performance degradation and potential connection exhaustion with vCenter. The global providerClientCache variable is now unused and the cache initialization logic has been removed. Restore the caching mechanism to maintain client reuse across credential validations.
Code suggestion
Check the AI-generated fix before applying
| c := new(vim25.Client) | |
| settings, err := k8sutils.GetVjailbreakSettings(ctx, k3sclient) | |
| // Initialize or reuse cached VMware client | |
| var c *vim25.Client | |
| if providerClientCache == nil { | |
| providerClientCache = &sync.Map{} | |
| } | |
| if cachedClient, ok := providerClientCache.Load(vmwcreds.Spec.SecretRef.Name); ok { | |
| c = cachedClient.(*vim25.Client) | |
| } else { | |
| c = new(vim25.Client) | |
| providerClientCache.Store(vmwcreds.Spec.SecretRef.Name, c) | |
| } | |
| settings, err := k8sutils.GetVjailbreakSettings(ctx, k3sclient) |
Code Review Run #a7a045
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
…ary deferred functions
…ary deferred functions
…ary deferred functions
There was a problem hiding this 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
- Double logout race condition · Line 36-39
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
| if c != nil { | ||
| defer c.CloseIdleConnections() | ||
| defer LogoutVMwareClient(ctx, k8sClient, vmwcreds, c) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change introduces a critical double logout issue. There's already a defer LogoutVMwareClient at line 31 that handles cleanup for all cases, but the new code adds a second defer LogoutVMwareClient inside the if c != nil block at line 38. This will cause LogoutVMwareClient to be called twice - once from the outer defer and once from the inner defer - leading to potential race conditions, errors when attempting to logout an already logged-out client, or resource leaks. The original anonymous function defer was actually correct as it ensured logout only happened when c != nil. Remove the duplicate defer call and keep only the single cleanup defer at line 31, or restore the conditional logout logic.
Code suggestion
Check the AI-generated fix before applying
| if c != nil { | |
| defer c.CloseIdleConnections() | |
| defer LogoutVMwareClient(ctx, k8sClient, vmwcreds, c) | |
| } | |
| if c != nil { | |
| defer c.CloseIdleConnections() | |
| } |
Code Review Run #e94e1c
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
…hing and session management
…ary deferred functions
…hing and session management
There was a problem hiding this 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
-
k8s/migration/pkg/utils/credutils.go - 2
- Premature cache storage · Line 1547-1548
- Uninitialized variable · Line 1728-1730
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
- Nil pointer dereference · Line 1634-1634
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
| host := mo.HostSystem{} | ||
| hostSystemMap.Store(host.Reference().Value, host) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hostSystemMap.Store call is storing an empty host struct before it's populated with actual data from vCenter. This will cache invalid host information and cause subsequent lookups to return incorrect data, leading to wrong cluster assignments for VMs. The storage should happen after the host data is retrieved from vCenter.
Code suggestion
Check the AI-generated fix before applying
| host := mo.HostSystem{} | |
| hostSystemMap.Store(host.Reference().Value, host) | |
| host := mo.HostSystem{} |
Code Review Run #e89271
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
| collector := property.DefaultCollector(client) | ||
|
|
||
| // Build property filter for VM retrieval |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rdmDiskMap variable is returned from getVMDetails but is never initialized within the function. This will cause a nil pointer dereference when the returned value is used by the caller. Initialize it as a new sync.Map before it's used by processRDMDisks.
Code suggestion
Check the AI-generated fix before applying
| collector := property.DefaultCollector(client) | |
| // Build property filter for VM retrieval | |
| collector := property.DefaultCollector(client) | |
| // Initialize rdmDiskMap for tracking Raw Device Mappings | |
| rdmDiskMap := new(sync.Map) | |
| // Build property filter for VM retrieval |
Code Review Run #e89271
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
|
Bito Review Skipped - No Changes Detected |
|
@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. |
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
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)
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.