Skip to content

Commit c2bf47c

Browse files
authored
Merge pull request #2100 from k8s-infra-cherrypick-robot/cherry-pick-2096-to-release-1.14
[release-1.14] Fix Gen4 Custom VM Cases
2 parents 9110541 + 4f288a8 commit c2bf47c

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

508508
volumeLimits, err := ns.GetVolumeLimits()
509509
if err != nil {
510-
klog.Errorf("GetVolumeLimits failed: %v", err.Error())
510+
klog.Errorf("GetVolumeLimits failed: %v. The error is ignored so that the driver can register", err.Error())
511+
// No error should be returned from NodeGetInfo, otherwise the driver will not register
512+
err = nil
511513
}
512514

513515
resp := &csi.NodeGetInfoResponse{
@@ -678,13 +680,17 @@ func (ns *GCENodeServer) GetVolumeLimits() (int64, error) {
678680
gen4MachineTypesPrefix := []string{"c4a-", "c4-", "n4-"}
679681
for _, gen4Prefix := range gen4MachineTypesPrefix {
680682
if strings.HasPrefix(machineType, gen4Prefix) {
681-
cpuString := machineType[strings.LastIndex(machineType, "-")+1:]
682-
cpus, err := strconv.ParseInt(cpuString, 10, 64)
683-
if err != nil {
684-
return volumeLimitSmall, fmt.Errorf("invalid cpuString %s for machine type: %v", cpuString, machineType)
683+
machineTypeSlice := strings.Split(machineType, "-")
684+
if len(machineTypeSlice) > 2 {
685+
cpuString := machineTypeSlice[2]
686+
cpus, err := strconv.ParseInt(cpuString, 10, 64)
687+
if err != nil {
688+
return volumeLimitBig, fmt.Errorf("invalid cpuString %s for machine type: %v", cpuString, machineType)
689+
}
690+
return common.MapNumber(cpus), nil
691+
} else {
692+
return volumeLimitBig, fmt.Errorf("unconventional machine type: %v", machineType)
685693
}
686-
return common.MapNumber(cpus), nil
687-
688694
}
689695
if strings.HasPrefix(machineType, "x4-") {
690696
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
@@ -256,15 +256,31 @@ func TestNodeGetVolumeLimits(t *testing.T) {
256256
machineType: "n4-standard-16",
257257
expVolumeLimit: 31,
258258
},
259+
{
260+
name: "n4-micro", // This type does not exist, but testing edge cases
261+
machineType: "n4-micro",
262+
expVolumeLimit: volumeLimitBig,
263+
expectError: true,
264+
},
259265
{
260266
name: "n4-highcpu-4",
261267
machineType: "n4-highcpu-4",
262268
expVolumeLimit: 15,
263269
},
270+
{
271+
name: "n4-custom-8-12345-ext",
272+
machineType: "n4-custom-8-12345-ext",
273+
expVolumeLimit: 23,
274+
},
275+
{
276+
name: "n4-custom-16-12345",
277+
machineType: "n4-custom-16-12345",
278+
expVolumeLimit: 31,
279+
},
264280
{
265281
name: "invalid gen4 machine type",
266282
machineType: "n4-highcpu-4xyz",
267-
expVolumeLimit: volumeLimitSmall,
283+
expVolumeLimit: volumeLimitBig,
268284
expectError: true,
269285
},
270286
{

0 commit comments

Comments
 (0)