Skip to content

Commit b2995ba

Browse files
Fix Gen4 Custom VM Cases
1 parent e0cc9d9 commit b2995ba

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

pkg/gce-pd-csi-driver/node.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -654,10 +654,8 @@ func (ns *GCENodeServer) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRe
654654

655655
nodeID := common.CreateNodeID(ns.MetadataService.GetProject(), ns.MetadataService.GetZone(), ns.MetadataService.GetName())
656656

657+
// err is always nil
657658
volumeLimits, err := ns.GetVolumeLimits(ctx)
658-
if err != nil {
659-
klog.Errorf("GetVolumeLimits failed: %v", err.Error())
660-
}
661659

662660
resp := &csi.NodeGetInfoResponse{
663661
NodeId: nodeID,
@@ -843,13 +841,19 @@ func (ns *GCENodeServer) GetVolumeLimits(ctx context.Context) (int64, error) {
843841
gen4MachineTypesPrefix := []string{"c4a-", "c4-", "n4-"}
844842
for _, gen4Prefix := range gen4MachineTypesPrefix {
845843
if strings.HasPrefix(machineType, gen4Prefix) {
846-
cpuString := machineType[strings.LastIndex(machineType, "-")+1:]
847-
cpus, err := strconv.ParseInt(cpuString, 10, 64)
848-
if err != nil {
849-
return volumeLimitSmall, fmt.Errorf("invalid cpuString %s for machine type: %v", cpuString, machineType)
844+
machineTypeSlice := strings.Split(machineType, "-")
845+
if len(machineTypeSlice) > 2 {
846+
cpuString := machineTypeSlice[2]
847+
cpus, err := strconv.ParseInt(cpuString, 10, 64)
848+
if err != nil {
849+
klog.Warningf("invalid cpuString %s for machine type: %v", cpuString, machineType)
850+
return volumeLimitBig, nil
851+
}
852+
return common.MapNumber(cpus), nil
853+
} else {
854+
klog.Warningf("unconventional machine type: %v", machineType)
855+
return volumeLimitBig, nil
850856
}
851-
return common.MapNumber(cpus), nil
852-
853857
}
854858
if strings.HasPrefix(machineType, "x4-") {
855859
return x4HyperdiskLimit, nil

pkg/gce-pd-csi-driver/node_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,26 @@ func TestNodeGetVolumeLimits(t *testing.T) {
288288
machineType: "n4-standard-16",
289289
expVolumeLimit: 31,
290290
},
291+
{
292+
name: "n4-micro", // This type does not exist, but testing edge cases
293+
machineType: "n4-micro",
294+
expVolumeLimit: volumeLimitBig,
295+
},
291296
{
292297
name: "n4-highcpu-4",
293298
machineType: "n4-highcpu-4",
294299
expVolumeLimit: 15,
295300
},
301+
{
302+
name: "n4-custom-8-12345-ext",
303+
machineType: "n4-custom-8-12345-ext",
304+
expVolumeLimit: 23,
305+
},
306+
{
307+
name: "n4-custom-16-12345",
308+
machineType: "n4-custom-16-12345",
309+
expVolumeLimit: 31,
310+
},
296311
{
297312
name: "invalid gen4 machine type",
298313
machineType: "n4-highcpu-4xyz",

0 commit comments

Comments
 (0)