Skip to content

Commit d3748bc

Browse files
iamanmolmHarness
authored andcommitted
fix: [CCM-33334]: Fix cloud-info zones and gpu issue for gcp (#56)
* bff6fa [feat]: [CCM-33334]: Fix spot prices zones * 363f96 fix: [CCM-33334]: Fix cloud-info zones and gpu issue for gcp
1 parent 41f19cd commit d3748bc

2 files changed

Lines changed: 60 additions & 37 deletions

File tree

internal/cloudinfo/cloudinfo.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,14 @@ func (cpi *cloudInfo) GetProductDetails(provider, service, region string) ([]typ
142142
cpi.log.Debug("price info not yet cached", map[string]interface{}{"instanceType": vm.Type})
143143
}
144144

145+
validZones := make(map[string]struct{}, len(vm.Zones))
146+
for _, z := range vm.Zones {
147+
validZones[z] = struct{}{}
148+
}
145149
for zone, price := range cachedVal.SpotPrice {
146-
pd.SpotPrice = append(pd.SpotPrice, *types.NewZonePrice(zone, price))
150+
if _, ok := validZones[zone]; len(vm.Zones) == 0 || ok {
151+
pd.SpotPrice = append(pd.SpotPrice, *types.NewZonePrice(zone, price))
152+
}
147153
}
148154

149155
details = append(details, *pd)
@@ -170,8 +176,14 @@ func (cpi *cloudInfo) GetProductDetail(provider, service, region string, product
170176
cpi.log.Debug("price info not yet cached", map[string]interface{}{"instanceType": vm.Type})
171177
}
172178

179+
validZones := make(map[string]struct{}, len(vm.Zones))
180+
for _, z := range vm.Zones {
181+
validZones[z] = struct{}{}
182+
}
173183
for zone, price := range cachedVal.SpotPrice {
174-
pd.SpotPrice = append(pd.SpotPrice, *types.NewZonePrice(zone, price))
184+
if _, ok := validZones[zone]; len(vm.Zones) == 0 || ok {
185+
pd.SpotPrice = append(pd.SpotPrice, *types.NewZonePrice(zone, price))
186+
}
175187
}
176188
return *pd, nil
177189
}

internal/cloudinfo/providers/google/cloudinfo.go

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -446,52 +446,61 @@ func (g *GceInfoer) GetVirtualMachines(region string) ([]types.VMInfo, error) {
446446
logger := log.WithFields(g.log, map[string]interface{}{"region": region})
447447
logger.Debug("retrieving product information")
448448
var vmsMap = make(map[string]types.VMInfo)
449+
vmZones := make(map[string][]string)
449450
var ntwPerf uint
450451

451452
zones, err := g.GetZones(region)
452453
if err != nil {
453454
return nil, err
454455
}
455-
err = g.computeSvc.MachineTypes.List(g.projectId, zones[0]).Pages(context.TODO(), func(allMts *compute.MachineTypeList) error {
456-
for _, mt := range allMts.Items {
457-
if _, ok := vmsMap[mt.Name]; !ok {
458-
switch {
459-
case mt.GuestCpus < 1:
460-
// minimum 1 Gbps network performance for each virtual machine
461-
ntwPerf = 1
462-
case mt.GuestCpus > 8:
463-
// theoretical maximum of 16 Gbps for each virtual machine
464-
ntwPerf = 16
465-
default:
466-
// each vCPU has a 2 Gbps egress cap for peak performance
467-
ntwPerf = uint(mt.GuestCpus * 2)
468-
}
469-
ntwMapper := newGceNetworkMapper()
470-
ntwPerfCat, err := ntwMapper.MapNetworkPerf(fmt.Sprint(ntwPerf, " Gbit/s"))
471-
if err != nil {
472-
logger.Debug(emperror.Wrap(err, "failed to get network performance category").Error(),
473-
map[string]interface{}{"instanceType": mt.Name})
474-
}
475-
vmsMap[mt.Name] = types.VMInfo{
476-
Category: g.getCategory(mt.Name),
477-
Series: g.mapSeries(mt.Name),
478-
Type: mt.Name,
479-
Cpus: float64(mt.GuestCpus),
480-
Mem: float64(mt.MemoryMb) / 1024,
481-
NtwPerf: fmt.Sprintf("%d Gbit/s", ntwPerf),
482-
NtwPerfCat: ntwPerfCat,
483-
Zones: zones,
484-
Attributes: cloudinfo.Attributes(fmt.Sprint(mt.GuestCpus), fmt.Sprint(float64(mt.MemoryMb)/1024), ntwPerfCat, g.getCategory(mt.Name)),
456+
for _, zone := range zones {
457+
err = g.computeSvc.MachineTypes.List(g.projectId, zone).Pages(context.TODO(), func(allMts *compute.MachineTypeList) error {
458+
for _, mt := range allMts.Items {
459+
vmZones[mt.Name] = append(vmZones[mt.Name], zone)
460+
if _, ok := vmsMap[mt.Name]; !ok {
461+
switch {
462+
case mt.GuestCpus < 1:
463+
// minimum 1 Gbps network performance for each virtual machine
464+
ntwPerf = 1
465+
case mt.GuestCpus > 8:
466+
// theoretical maximum of 16 Gbps for each virtual machine
467+
ntwPerf = 16
468+
default:
469+
// each vCPU has a 2 Gbps egress cap for peak performance
470+
ntwPerf = uint(mt.GuestCpus * 2)
471+
}
472+
ntwMapper := newGceNetworkMapper()
473+
ntwPerfCat, err := ntwMapper.MapNetworkPerf(fmt.Sprint(ntwPerf, " Gbit/s"))
474+
if err != nil {
475+
logger.Debug(emperror.Wrap(err, "failed to get network performance category").Error(),
476+
map[string]interface{}{"instanceType": mt.Name})
477+
}
478+
var gpus float64
479+
for _, acc := range mt.Accelerators {
480+
gpus += float64(acc.GuestAcceleratorCount)
481+
}
482+
vmsMap[mt.Name] = types.VMInfo{
483+
Category: g.getCategory(mt.Name),
484+
Series: g.mapSeries(mt.Name),
485+
Type: mt.Name,
486+
Cpus: float64(mt.GuestCpus),
487+
Mem: float64(mt.MemoryMb) / 1024,
488+
Gpus: gpus,
489+
NtwPerf: fmt.Sprintf("%d Gbit/s", ntwPerf),
490+
NtwPerfCat: ntwPerfCat,
491+
Attributes: cloudinfo.Attributes(fmt.Sprint(mt.GuestCpus), fmt.Sprint(float64(mt.MemoryMb)/1024), ntwPerfCat, g.getCategory(mt.Name)),
492+
}
485493
}
486494
}
495+
return nil
496+
})
497+
if err != nil {
498+
return nil, err
487499
}
488-
return nil
489-
})
490-
if err != nil {
491-
return nil, err
492500
}
493501
var vms []types.VMInfo
494-
for _, vm := range vmsMap {
502+
for name, vm := range vmsMap {
503+
vm.Zones = vmZones[name]
495504
vms = append(vms, vm)
496505
}
497506
logger.Debug("found virtual machines", map[string]interface{}{"vms": len(vms)})
@@ -504,6 +513,8 @@ func (g *GceInfoer) getCategory(name string) string {
504513
return types.CategoryMemory
505514
case strings.Contains(name, "highcpu"):
506515
return types.CategoryCompute
516+
case strings.Contains(name, "highgpu"):
517+
return types.CategoryGpu
507518
default:
508519
return types.CategoryGeneral
509520
}

0 commit comments

Comments
 (0)