Repository: kubernetes-sigs/gcp-compute-persistent-disk-csi-driver

Issue:
N4 instances have wrong attach limit
N4 instances can use only hyperdisk-balanced disks and they have a different attach limit than regular "persistent disks": https://cloud.google.com/compute/docs/general-purpose-machines#disk_and_capacity_limits_2

The CSI driver should report 20 disks per n4-standard-2, now it reports 127.

Discussion:
@k8s-triage-robot: The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:
- After 90d of inactivity, `lifecycle/stale` is applied
- After 30d of inactivity since `lifecycle/stale` was applied, `lifecycle/rotten` is applied
- After 30d of inactivity since `lifecycle/rotten` was applied, the issue is closed

You can:
- Mark this issue as fresh with `/remove-lifecycle stale`
- Close this issue with `/close`
- Offer to help out with [Issue Triage][1]

Please send feedback to sig-contributor-experience at [kubernetes/community](https://github.com/kubernetes/community).

/lifecycle stale

[1]: https://www.kubernetes.dev/docs/guide/issue-triage/@k8s-triage-robot: The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:
- After 90d of inactivity, `lifecycle/stale` is applied
- After 30d of inactivity since `lifecycle/stale` was applied, `lifecycle/rotten` is applied
- After 30d of inactivity since `lifecycle/rotten` was applied, the issue is closed

You can:
- Mark this issue as fresh with `/remove-lifecycle rotten`
- Close this issue with `/close`
- Offer to help out with [Issue Triage][1]

Please send feedback to sig-contributor-experience at [kubernetes/community](https://github.com/kubernetes/community).

/lifecycle rotten

[1]: https://www.kubernetes.dev/docs/guide/issue-triage/@jsafrane: /remove-lifecycle rotten@sunnylovestiramisu: This is fixed in master

/close@k8s-ci-robot: @sunnylovestiramisu: Closing this issue.

<details>

In response to [this](https://github.com/kubernetes-sigs/gcp-compute-persistent-disk-csi-driver/issues/1819#issuecomment-2776317759):

>This is fixed in master
>
>/close


Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.
</details>@jsafrane: /reopen

It's much better, just off-by-one :-).
The driver reports 16 attachments on n4-standard-4, but it forgets the root disk. Only 15 Pods with one volume each can run on the machine, the 16th one shows:

`AttachVolume.Attach failed for volume "pvc-c1673c2a-7749-4b9b-b270-3544d9b04cef" : rpc error: code = InvalidArgument desc = Failed to Attach: failed when waiting for zonal op: rpc error: code = InvalidArgument desc = operation operation-1744802898292-632e394f4ad33-7301bb9b-ce176f79 failed (UNSUPPORTED_OPERATION): Maximum hyperdisk-balanced disks count should be less than or equal to [16], Requested : [17]`

The driver reports 127 attachments for pd-disks, so it should report 15 for hyperdisks.@k8s-ci-robot: @jsafrane: Reopened this issue.

<details>

In response to [this](https://github.com/kubernetes-sigs/gcp-compute-persistent-disk-csi-driver/issues/1819#issuecomment-2809295748):

>/reopen
>
>It's much better, just off-by-one :-).
>The driver reports 16 attachments on n4-standard-4, but it forgets the root disk. Only 15 Pods with one volume each can run on the machine, 16th shows:
>
>```
>AttachVolume.Attach failed for volume "pvc-c1673c2a-7749-4b9b-b270-3544d9b04cef" : rpc error: code = InvalidArgument desc = Failed to Attach: failed when waiting for zonal op: rpc error: code = InvalidArgument desc = operation operation-1744802898292-632e394f4ad33-7301bb9b-ce176f79 failed (UNSUPPORTED_OPERATION): Maximum hyperdisk-balanced disks count should be less than or equal to [16], Requested : [17]
>```
>
>The driver reports 127 attachments for pd-disks, so it should report 15 for hyperdisks.


Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.
</details>@jsafrane: Proposing a fix in https://github.com/kubernetes-sigs/gcp-compute-persistent-disk-csi-driver/pull/2057

Solution patch:
diff --git a/pkg/common/constants.go b/pkg/common/constants.go
index 2ab74b77..94c7f5a6 100644
--- a/pkg/common/constants.go
+++ b/pkg/common/constants.go
@@ -67,10 +67,10 @@ var Gen4MachineHyperdiskAttachLimitMap = []struct {
 	max   int64
 	value int64
 }{
-	{max: 4, value: 16},
-	{max: 8, value: 24},
-	{max: 16, value: 32},
-	{max: 32, value: 48},
-	{max: 64, value: 64},
-	{max: 1024, value: 128},
+	{max: 4, value: 15},
+	{max: 8, value: 23},
+	{max: 16, value: 31},
+	{max: 32, value: 49},
+	{max: 64, value: 63},
+	{max: 1024, value: 127},
 }
diff --git a/pkg/gce-pd-csi-driver/node.go b/pkg/gce-pd-csi-driver/node.go
index c1fd96e3..3194c478 100644
--- a/pkg/gce-pd-csi-driver/node.go
+++ b/pkg/gce-pd-csi-driver/node.go
@@ -99,9 +99,9 @@ const (
 	volumeLimitSmall int64 = 15
 	volumeLimitBig   int64 = 127
 	// doc https://cloud.google.com/compute/docs/memory-optimized-machines#x4_disks
-	x4HyperdiskLimit int64 = 40
+	x4HyperdiskLimit int64 = 39
 	// doc https://cloud.google.com/compute/docs/accelerator-optimized-machines#a4-disks
-	a4HyperdiskLimit     int64 = 128
+	a4HyperdiskLimit     int64 = 127
 	defaultLinuxFsType         = "ext4"
 	defaultWindowsFsType       = "ntfs"
 	fsTypeExt3                 = "ext3"



Test patch:
diff --git a/pkg/gce-pd-csi-driver/node_test.go b/pkg/gce-pd-csi-driver/node_test.go
index 2de92447..63add2b0 100644
--- a/pkg/gce-pd-csi-driver/node_test.go
+++ b/pkg/gce-pd-csi-driver/node_test.go
@@ -271,27 +271,27 @@ func TestNodeGetVolumeLimits(t *testing.T) {
 		{
 			name:           "c4-standard-192",
 			machineType:    "c4-standard-192",
-			expVolumeLimit: 128,
+			expVolumeLimit: 127,
 		},
 		{
 			name:           "c4-standard-48",
 			machineType:    "c4-standard-48",
-			expVolumeLimit: 64,
+			expVolumeLimit: 63,
 		},
 		{
 			name:           "c4a-standard-4",
 			machineType:    "c4a-standard-4",
-			expVolumeLimit: 16,
+			expVolumeLimit: 15,
 		},
 		{
 			name:           "n4-standard-16",
 			machineType:    "n4-standard-16",
-			expVolumeLimit: 32,
+			expVolumeLimit: 31,
 		},
 		{
 			name:           "n4-highcpu-4",
 			machineType:    "n4-highcpu-4",
-			expVolumeLimit: 16,
+			expVolumeLimit: 15,
 		},
 		{
 			name:           "invalid gen4 machine type",