diff --git a/pkg/executables/govc.go b/pkg/executables/govc.go index 96035be71a38b..6f3c653ae224f 100644 --- a/pkg/executables/govc.go +++ b/pkg/executables/govc.go @@ -1188,7 +1188,7 @@ func (g *Govc) GetResourcePoolInfo(ctx context.Context, datacenter, resourcepool return poolInfo, nil } -// helper function that parses the resource pool response and returns memory requirements. +// getPoolInfo parses resource pool response and returns memory requirements. func getPoolInfo(rp *resourcePool) (map[string]int, error) { memoryUsed, err := getValueFromString(rp.memoryUsage) if err != nil { @@ -1207,6 +1207,7 @@ func getPoolInfo(rp *resourcePool) (map[string]int, error) { return poolInfo, nil } +// getValueFromString cleans the input string and returns the extracted numerical value. func getValueFromString(str string) (int, error) { splitResponse := strings.Split(strings.TrimSpace(str), " ") nonNumericRegex := regexp.MustCompile(`[^0-9- ]+`) diff --git a/pkg/providers/vsphere/vsphere_test.go b/pkg/providers/vsphere/vsphere_test.go index 97d090f3c2e4b..73c6cacd618b7 100644 --- a/pkg/providers/vsphere/vsphere_test.go +++ b/pkg/providers/vsphere/vsphere_test.go @@ -1871,10 +1871,6 @@ func TestSetupAndValidateUpgradeClusterSameMachineConfigforCPandEtcd(t *testing. for _, mc := range clusterSpec.VSphereMachineConfigs { kubectl.EXPECT().GetEksaVSphereMachineConfig(ctx, gomock.Any(), cluster.KubeconfigFile, clusterSpec.Cluster.GetNamespace()).Return(mc, nil).AnyTimes() } - // resourcePoolResponse := map[string]int{ - // "Memory_Available": -1, - // } - // provider.govc.EXPECT().GetResourcePoolInfo(tt.ctx, tt.clusterSpec.VSphereDatacenter.Spec.Datacenter, tt.clusterSpec.VSphereMachineConfigs[controlPlaneMachineConfigName].Spec.ResourcePool).Return(resourcePoolResponse, nil) err := provider.SetupAndValidateUpgradeCluster(ctx, cluster, clusterSpec, clusterSpec) if err != nil { t.Fatalf("unexpected failure %v", err)