Skip to content

Commit 62eb0a5

Browse files
authored
Merge pull request #2098 from k8s-infra-cherrypick-robot/cherry-pick-2096-to-release-1.18
[release-1.18] Fix Gen4 Custom VM Cases
2 parents e47731b + b723f4b commit 62eb0a5

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
@@ -575,7 +575,9 @@ func (ns *GCENodeServer) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRe
575575

576576
volumeLimits, err := ns.GetVolumeLimits(ctx)
577577
if err != nil {
578-
klog.Errorf("GetVolumeLimits failed: %v", err.Error())
578+
klog.Errorf("GetVolumeLimits failed: %v. The error is ignored so that the driver can register", err.Error())
579+
// No error should be returned from NodeGetInfo, otherwise the driver will not register
580+
err = nil
579581
}
580582

581583
resp := &csi.NodeGetInfoResponse{
@@ -762,13 +764,17 @@ func (ns *GCENodeServer) GetVolumeLimits(ctx context.Context) (int64, error) {
762764
gen4MachineTypesPrefix := []string{"c4a-", "c4-", "n4-"}
763765
for _, gen4Prefix := range gen4MachineTypesPrefix {
764766
if strings.HasPrefix(machineType, gen4Prefix) {
765-
cpuString := machineType[strings.LastIndex(machineType, "-")+1:]
766-
cpus, err := strconv.ParseInt(cpuString, 10, 64)
767-
if err != nil {
768-
return volumeLimitSmall, fmt.Errorf("invalid cpuString %s for machine type: %v", cpuString, machineType)
767+
machineTypeSlice := strings.Split(machineType, "-")
768+
if len(machineTypeSlice) > 2 {
769+
cpuString := machineTypeSlice[2]
770+
cpus, err := strconv.ParseInt(cpuString, 10, 64)
771+
if err != nil {
772+
return volumeLimitBig, fmt.Errorf("invalid cpuString %s for machine type: %v", cpuString, machineType)
773+
}
774+
return common.MapNumber(cpus), nil
775+
} else {
776+
return volumeLimitBig, fmt.Errorf("unconventional machine type: %v", machineType)
769777
}
770-
return common.MapNumber(cpus), nil
771-
772778
}
773779
if strings.HasPrefix(machineType, "x4-") {
774780
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)