Skip to content

Commit 4f71e5e

Browse files
authored
Merge pull request #2099 from k8s-infra-cherrypick-robot/cherry-pick-2096-to-release-1.17
[release-1.17] Fix Gen4 Custom VM Cases
2 parents bdcc9ef + fa81e60 commit 4f71e5e

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

574574
volumeLimits, err := ns.GetVolumeLimits()
575575
if err != nil {
576-
klog.Errorf("GetVolumeLimits failed: %v", err.Error())
576+
klog.Errorf("GetVolumeLimits failed: %v. The error is ignored so that the driver can register", err.Error())
577+
// No error should be returned from NodeGetInfo, otherwise the driver will not register
578+
err = nil
577579
}
578580

579581
resp := &csi.NodeGetInfoResponse{
@@ -744,13 +746,17 @@ func (ns *GCENodeServer) GetVolumeLimits() (int64, error) {
744746
gen4MachineTypesPrefix := []string{"c4a-", "c4-", "n4-"}
745747
for _, gen4Prefix := range gen4MachineTypesPrefix {
746748
if strings.HasPrefix(machineType, gen4Prefix) {
747-
cpuString := machineType[strings.LastIndex(machineType, "-")+1:]
748-
cpus, err := strconv.ParseInt(cpuString, 10, 64)
749-
if err != nil {
750-
return volumeLimitSmall, fmt.Errorf("invalid cpuString %s for machine type: %v", cpuString, machineType)
749+
machineTypeSlice := strings.Split(machineType, "-")
750+
if len(machineTypeSlice) > 2 {
751+
cpuString := machineTypeSlice[2]
752+
cpus, err := strconv.ParseInt(cpuString, 10, 64)
753+
if err != nil {
754+
return volumeLimitBig, fmt.Errorf("invalid cpuString %s for machine type: %v", cpuString, machineType)
755+
}
756+
return common.MapNumber(cpus), nil
757+
} else {
758+
return volumeLimitBig, fmt.Errorf("unconventional machine type: %v", machineType)
751759
}
752-
return common.MapNumber(cpus), nil
753-
754760
}
755761
if strings.HasPrefix(machineType, "x4-") {
756762
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
@@ -276,15 +276,31 @@ func TestNodeGetVolumeLimits(t *testing.T) {
276276
machineType: "n4-standard-16",
277277
expVolumeLimit: 31,
278278
},
279+
{
280+
name: "n4-micro", // This type does not exist, but testing edge cases
281+
machineType: "n4-micro",
282+
expVolumeLimit: volumeLimitBig,
283+
expectError: true,
284+
},
279285
{
280286
name: "n4-highcpu-4",
281287
machineType: "n4-highcpu-4",
282288
expVolumeLimit: 15,
283289
},
290+
{
291+
name: "n4-custom-8-12345-ext",
292+
machineType: "n4-custom-8-12345-ext",
293+
expVolumeLimit: 23,
294+
},
295+
{
296+
name: "n4-custom-16-12345",
297+
machineType: "n4-custom-16-12345",
298+
expVolumeLimit: 31,
299+
},
284300
{
285301
name: "invalid gen4 machine type",
286302
machineType: "n4-highcpu-4xyz",
287-
expVolumeLimit: volumeLimitSmall,
303+
expVolumeLimit: volumeLimitBig,
288304
expectError: true,
289305
},
290306
{

0 commit comments

Comments
 (0)