Skip to content

Commit 938ba73

Browse files
authored
Merge pull request kubernetes-sigs#2096 from sunnylovestiramisu/attachLimit
Fix Gen4 Custom VM Cases
2 parents 69effd6 + 10bb90a commit 938ba73

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

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

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

657657
volumeLimits, err := ns.GetVolumeLimits(ctx)
658658
if err != nil {
659-
klog.Errorf("GetVolumeLimits failed: %v", err.Error())
659+
klog.Errorf("GetVolumeLimits failed: %v. The error is ignored so that the driver can register", err.Error())
660+
// No error should be returned from NodeGetInfo, otherwise the driver will not register
661+
err = nil
660662
}
661663

662664
resp := &csi.NodeGetInfoResponse{
@@ -843,13 +845,17 @@ func (ns *GCENodeServer) GetVolumeLimits(ctx context.Context) (int64, error) {
843845
gen4MachineTypesPrefix := []string{"c4a-", "c4-", "n4-"}
844846
for _, gen4Prefix := range gen4MachineTypesPrefix {
845847
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)
848+
machineTypeSlice := strings.Split(machineType, "-")
849+
if len(machineTypeSlice) > 2 {
850+
cpuString := machineTypeSlice[2]
851+
cpus, err := strconv.ParseInt(cpuString, 10, 64)
852+
if err != nil {
853+
return volumeLimitBig, fmt.Errorf("invalid cpuString %s for machine type: %v", cpuString, machineType)
854+
}
855+
return common.MapNumber(cpus), nil
856+
} else {
857+
return volumeLimitBig, fmt.Errorf("unconventional machine type: %v", machineType)
850858
}
851-
return common.MapNumber(cpus), nil
852-
853859
}
854860
if strings.HasPrefix(machineType, "x4-") {
855861
return x4HyperdiskLimit, nil

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,15 +288,31 @@ 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+
expectError: true,
296+
},
291297
{
292298
name: "n4-highcpu-4",
293299
machineType: "n4-highcpu-4",
294300
expVolumeLimit: 15,
295301
},
302+
{
303+
name: "n4-custom-8-12345-ext",
304+
machineType: "n4-custom-8-12345-ext",
305+
expVolumeLimit: 23,
306+
},
307+
{
308+
name: "n4-custom-16-12345",
309+
machineType: "n4-custom-16-12345",
310+
expVolumeLimit: 31,
311+
},
296312
{
297313
name: "invalid gen4 machine type",
298314
machineType: "n4-highcpu-4xyz",
299-
expVolumeLimit: volumeLimitSmall,
315+
expVolumeLimit: volumeLimitBig,
300316
expectError: true,
301317
},
302318
{

0 commit comments

Comments
 (0)