Skip to content

Fix Gen4 Custom VM Cases #2096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions pkg/gce-pd-csi-driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,9 @@ func (ns *GCENodeServer) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRe

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

resp := &csi.NodeGetInfoResponse{
Expand Down Expand Up @@ -843,13 +845,17 @@ func (ns *GCENodeServer) GetVolumeLimits(ctx context.Context) (int64, error) {
gen4MachineTypesPrefix := []string{"c4a-", "c4-", "n4-"}
for _, gen4Prefix := range gen4MachineTypesPrefix {
if strings.HasPrefix(machineType, gen4Prefix) {
cpuString := machineType[strings.LastIndex(machineType, "-")+1:]
cpus, err := strconv.ParseInt(cpuString, 10, 64)
if err != nil {
return volumeLimitSmall, fmt.Errorf("invalid cpuString %s for machine type: %v", cpuString, machineType)
machineTypeSlice := strings.Split(machineType, "-")
if len(machineTypeSlice) > 2 {
cpuString := machineTypeSlice[2]
cpus, err := strconv.ParseInt(cpuString, 10, 64)
if err != nil {
return volumeLimitBig, fmt.Errorf("invalid cpuString %s for machine type: %v", cpuString, machineType)
}
return common.MapNumber(cpus), nil
} else {
return volumeLimitBig, fmt.Errorf("unconventional machine type: %v", machineType)
}
return common.MapNumber(cpus), nil

}
if strings.HasPrefix(machineType, "x4-") {
return x4HyperdiskLimit, nil
Expand Down
18 changes: 17 additions & 1 deletion pkg/gce-pd-csi-driver/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,31 @@ func TestNodeGetVolumeLimits(t *testing.T) {
machineType: "n4-standard-16",
expVolumeLimit: 31,
},
{
name: "n4-micro", // This type does not exist, but testing edge cases
machineType: "n4-micro",
expVolumeLimit: volumeLimitBig,
expectError: true,
},
{
name: "n4-highcpu-4",
machineType: "n4-highcpu-4",
expVolumeLimit: 15,
},
{
name: "n4-custom-8-12345-ext",
machineType: "n4-custom-8-12345-ext",
expVolumeLimit: 23,
},
{
name: "n4-custom-16-12345",
machineType: "n4-custom-16-12345",
expVolumeLimit: 31,
},
{
name: "invalid gen4 machine type",
machineType: "n4-highcpu-4xyz",
expVolumeLimit: volumeLimitSmall,
expVolumeLimit: volumeLimitBig,
expectError: true,
},
{
Expand Down