Repository: kubernetes-sigs/gcp-compute-persistent-disk-csi-driver
Pull request #2092 (2025-05-15 19:35:26)

Using Default PD Attach Limit for Gen3 Machines
**What type of PR is this?**
/kind bug

**What this PR does / why we need it**:
For backward compatibility we will not change the attach limit for Gen3 machines. For Hyperdisk, the customers can still use the node labels to override.

**Which issue(s) this PR fixes**:
Fixes #

**Special notes for your reviewer**:

**Does this PR introduce a user-facing change?**:

```release-note
Using Default PD Attach Limit for Gen3 Machines
```

/assign @mattcary 


k8s-ci-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubernetes-sigs/gcp-compute-persistent-disk-csi-driver/pull/2092#" title="Author self-approved">sunnylovestiramisu</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubernetes-sigs%2Fgcp-compute-persistent-disk-csi-driver).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/kubernetes-sigs/gcp-compute-persistent-disk-csi-driver/blob/master/OWNERS)~~ [sunnylovestiramisu]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->

Patch:
diff --git a/pkg/common/utils.go b/pkg/common/utils.go
index 81ba65f0..b15181b3 100644
--- a/pkg/common/utils.go
+++ b/pkg/common/utils.go
@@ -24,7 +24,6 @@ import (
 	"net/http"
 	"regexp"
 	"slices"
-	"strconv"
 	"strings"
 	"time"
 
@@ -773,25 +772,6 @@ func MapNumber(num int64) int64 {
 	return 0
 }
 
-func ExtractCPUFromMachineType(input string) (int64, error) {
-	// Regex to find the number at the end of the string,
-	// it allows optional -lssd suffix.
-	re := regexp.MustCompile(`(\d+)(?:-lssd|-metal)?$`)
-
-	match := re.FindStringSubmatch(input)
-	if len(match) < 2 {
-		return 0, fmt.Errorf("no number found at the end of the input string: %s", input)
-	}
-
-	numberStr := match[1]
-	number, err := strconv.ParseInt(numberStr, 10, 64)
-	if err != nil {
-		return 0, fmt.Errorf("failed to convert string '%s' to integer: %w", numberStr, err)
-	}
-
-	return number, nil
-}
-
 func DiskTypeLabelKey(diskType string) string {
 	return fmt.Sprintf("%s/%s", DiskTypeKeyPrefix, diskType)
 }
diff --git a/pkg/gce-pd-csi-driver/node.go b/pkg/gce-pd-csi-driver/node.go
index 54950b48..959eef2a 100644
--- a/pkg/gce-pd-csi-driver/node.go
+++ b/pkg/gce-pd-csi-driver/node.go
@@ -103,12 +103,7 @@ const (
 	// doc https://cloud.google.com/compute/docs/memory-optimized-machines#x4_disks
 	x4HyperdiskLimit int64 = 39
 	// doc https://cloud.google.com/compute/docs/accelerator-optimized-machines#a4-disks
-	a4HyperdiskLimit int64 = 127
-	// doc https://cloud.google.com/compute/docs/storage-optimized-machines#z3_disks
-	// doc https://cloud.google.com/compute/docs/accelerator-optimized-machines#a3-disks
-	gen3HyperdiskLimit int64 = 31
-	// doc https://cloud.google.com/compute/docs/compute-optimized-machines#h3_disks
-	h3HyperdiskLimit     int64 = 7 // Use limit for Hyperdisk Balanced
+	a4HyperdiskLimit     int64 = 127
 	defaultLinuxFsType         = "ext4"
 	defaultWindowsFsType       = "ntfs"
 	fsTypeExt3                 = "ext3"
@@ -783,36 +778,6 @@ func (ns *GCENodeServer) GetVolumeLimits(ctx context.Context) (int64, error) {
 		}
 	}
 
-	// Process gen3 machine attach limits
-	gen3MachineTypesPrefix := []string{"c3-", "c3d-"}
-	for _, gen3Prefix := range gen3MachineTypesPrefix {
-		if strings.HasPrefix(machineType, gen3Prefix) {
-			cpus, err := common.ExtractCPUFromMachineType(machineType)
-			if err != nil {
-				return volumeLimitSmall, err
-			}
-			if cpus <= 8 || strings.Contains(machineType, "metal") {
-				return volumeLimitSmall, nil
-			}
-			return gen3HyperdiskLimit, nil
-
-		}
-		if strings.HasPrefix(machineType, "z3-") {
-			return gen3HyperdiskLimit, nil
-		}
-		if strings.HasPrefix(machineType, "h3-") {
-			return h3HyperdiskLimit, nil
-		}
-		if strings.HasPrefix(machineType, "a3-") {
-			if machineType == "a3-ultragpu-8g" {
-				return volumeLimitBig, nil
-			} else {
-				return gen3HyperdiskLimit, nil
-			}
-		}
-
-	}
-
 	return volumeLimitBig, nil
 }
 


Test patch:
diff --git a/pkg/common/utils_test.go b/pkg/common/utils_test.go
index 71bf0a77..1d4cef0e 100644
--- a/pkg/common/utils_test.go
+++ b/pkg/common/utils_test.go
@@ -2149,47 +2149,3 @@ func TestGetMinIopsThroughput(t *testing.T) {
 		})
 	}
 }
-
-func TestExtractCPUFromMachineType(t *testing.T) {
-	testcases := []struct {
-		name         string
-		input        string
-		expectOutput int64
-		expectErr    bool
-	}{
-		{
-			name:         "c3-highmem-176",
-			input:        "c3-highmem-176",
-			expectOutput: 176,
-		},
-		{
-			name:         "c3-standard-8-lssd",
-			input:        "c3-standard-8-lssd",
-			expectOutput: 8,
-		},
-		{
-			name:         "c3-standard-192-metal",
-			input:        "c3-standard-192-metal",
-			expectOutput: 192,
-		},
-		{
-			name:         "invalid input",
-			input:        "something-not-valid",
-			expectOutput: 0,
-			expectErr:    true,
-		},
-	}
-
-	for _, tc := range testcases {
-		t.Run(tc.name, func(t *testing.T) {
-			output, err := ExtractCPUFromMachineType(tc.input)
-			if output != tc.expectOutput {
-				t.Errorf("ExtractCPUFromMachineType: got %v, want %v", output, tc.expectOutput)
-			}
-
-			if gotErr := err != nil; gotErr != tc.expectErr {
-				t.Fatalf("ExtractCPUFromMachineType(%+v) = %v; expectedErr: %v", tc.input, err, tc.expectErr)
-			}
-		})
-	}
-}
diff --git a/pkg/gce-pd-csi-driver/node_test.go b/pkg/gce-pd-csi-driver/node_test.go
index f4ada1d8..4b004f7d 100644
--- a/pkg/gce-pd-csi-driver/node_test.go
+++ b/pkg/gce-pd-csi-driver/node_test.go
@@ -310,39 +310,14 @@ func TestNodeGetVolumeLimits(t *testing.T) {
 			expVolumeLimit: a4HyperdiskLimit,
 		},
 		{
-			name:           "z3-highmem-176",
-			machineType:    "z3-highmem-176",
-			expVolumeLimit: gen3HyperdiskLimit,
-		},
-		{
-			name:           "h3-standard-88",
-			machineType:    "h3-standard-88",
-			expVolumeLimit: h3HyperdiskLimit,
-		},
-		{
-			name:           "a3-ultragpu-8g",
-			machineType:    "a3-ultragpu-8g",
+			name:           "c3-standard-4",
+			machineType:    "c3-standard-4",
 			expVolumeLimit: volumeLimitBig,
 		},
-		{
-			name:           "a3-megagpu-8g",
-			machineType:    "a3-megagpu-8g",
-			expVolumeLimit: gen3HyperdiskLimit, // 31
-		},
 		{
 			name:           "c3d-highmem-8-lssd",
 			machineType:    "c3d-highmem-8-lssd",
-			expVolumeLimit: volumeLimitSmall, // 15
-		},
-		{
-			name:           "c3-standard-192-metal",
-			machineType:    "c3-standard-192-metal",
-			expVolumeLimit: volumeLimitSmall, // 15
-		},
-		{
-			name:           "c3-standard-176",
-			machineType:    "c3-standard-176",
-			expVolumeLimit: gen3HyperdiskLimit, // 31
+			expVolumeLimit: volumeLimitBig,
 		},
 	}