Skip to content

Commit 77181ad

Browse files
authored
Merge pull request #2138 from davis-haba/npi-attach-limits
Add attach limits for C3 Baremetal and A4X + A4X-Max machine types
2 parents 0c47cf9 + 0a5a8bd commit 77181ad

File tree

4 files changed

+111
-6
lines changed

4 files changed

+111
-6
lines changed

pkg/common/constants.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,9 @@ var C4AMachineHyperdiskAttachLimitMap = []MachineHyperdiskLimit{
104104
{max: 48, value: 31},
105105
{max: 72, value: 63},
106106
}
107+
108+
// A4X Machine Types - Hyperdisk Balanced Limits. The max here is actually the GPU count (not CPU, like the others).
109+
var A4XMachineHyperdiskAttachLimitMap = []MachineHyperdiskLimit{
110+
{max: 1, value: 63},
111+
{max: 2, value: 127},
112+
}

pkg/common/utils.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,8 @@ func GetHyperdiskAttachLimit(machineTypePrefix string, vCPUs int64) int64 {
775775
limitMap = N4MachineHyperdiskAttachLimitMap
776776
case "c4a":
777777
limitMap = C4AMachineHyperdiskAttachLimitMap
778+
case "a4x":
779+
limitMap = A4XMachineHyperdiskAttachLimitMap
778780
default:
779781
// Fallback to the most conservative Gen4 map for unknown types
780782
return MapNumber(vCPUs, C4DMachineHyperdiskAttachLimitMap)

pkg/gce-pd-csi-driver/node.go

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,13 @@ const (
113113
// doc https://cloud.google.com/compute/docs/memory-optimized-machines#x4_disks
114114
x4HyperdiskLimit int64 = 39
115115
// doc https://cloud.google.com/compute/docs/accelerator-optimized-machines#a4-disks
116-
a4HyperdiskLimit int64 = 127
117-
defaultLinuxFsType = "ext4"
118-
defaultWindowsFsType = "ntfs"
119-
fsTypeExt3 = "ext3"
120-
fsTypeBtrfs = "btrfs"
116+
a4HyperdiskLimit int64 = 127
117+
a4xMetalHyperdiskLimit int64 = 31
118+
c3MetalHyperdiskLimit int64 = 15
119+
defaultLinuxFsType = "ext4"
120+
defaultWindowsFsType = "ntfs"
121+
fsTypeExt3 = "ext3"
122+
fsTypeBtrfs = "btrfs"
121123

122124
readAheadKBMountFlagRegexPattern = "^read_ahead_kb=(.+)$"
123125
btrfsReclaimDataRegexPattern = "^btrfs-allocation-data-bg_reclaim_threshold=(\\d{1,2})$" // 0-99 are valid, incl. 00
@@ -847,7 +849,7 @@ func (ns *GCENodeServer) GetVolumeLimits(ctx context.Context) (int64, error) {
847849
}
848850
}
849851

850-
// Process gen4 machine attach limits
852+
// Process gen4 machine attach limits which include vCPUs in the machine type
851853
gen4MachineTypesPrefix := []string{"c4a-", "c4-", "n4-", "c4d-"}
852854
for _, gen4Prefix := range gen4MachineTypesPrefix {
853855
if strings.HasPrefix(machineType, gen4Prefix) {
@@ -866,12 +868,32 @@ func (ns *GCENodeServer) GetVolumeLimits(ctx context.Context) (int64, error) {
866868
}
867869
}
868870
}
871+
// Process gen4 A4X machine attach limits, which have a -1g/-2g/-4g/metal suffix
872+
if strings.HasPrefix(machineType, "a4x-") {
873+
machineTypeSlice := strings.Split(machineType, "-")
874+
if len(machineTypeSlice) < 3 {
875+
return volumeLimitBig, fmt.Errorf("unconventional machine type: %v", machineType)
876+
}
877+
gpuString := machineTypeSlice[2]
878+
if gpuString == "metal" {
879+
return a4xMetalHyperdiskLimit, nil
880+
}
881+
gpuString = gpuString[0 : len(gpuString)-1] // Remove the 'g' suffix
882+
gpus, err := strconv.ParseInt(gpuString, 10, 64)
883+
if err != nil {
884+
return volumeLimitBig, fmt.Errorf("invalid gpuString %s for machine type: %v", gpuString, machineType)
885+
}
886+
return common.GetHyperdiskAttachLimit("a4x", gpus), nil
887+
}
869888
if strings.HasPrefix(machineType, "x4-") {
870889
return x4HyperdiskLimit, nil
871890
}
872891
if strings.HasPrefix(machineType, "a4-") {
873892
return a4HyperdiskLimit, nil
874893
}
894+
if strings.HasPrefix(machineType, "c3-") && strings.HasSuffix(machineType, "-metal") {
895+
return c3MetalHyperdiskLimit, nil
896+
}
875897

876898
return volumeLimitBig, nil
877899
}

pkg/gce-pd-csi-driver/node_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,81 @@ func TestNodeGetVolumeLimits(t *testing.T) {
350350
machineType: "c4d-standard-32",
351351
expVolumeLimit: 31,
352352
},
353+
{
354+
name: "c3-highcpu-192-metal",
355+
machineType: "c3-highcpu-192-metal",
356+
expVolumeLimit: c3MetalHyperdiskLimit,
357+
},
358+
{
359+
name: "c3-standard-192-metal",
360+
machineType: "c3-standard-192-metal",
361+
expVolumeLimit: c3MetalHyperdiskLimit,
362+
},
363+
{
364+
name: "c3-highmem-192-metal",
365+
machineType: "c3-highmem-192-metal",
366+
expVolumeLimit: c3MetalHyperdiskLimit,
367+
},
368+
{
369+
name: "a4x-highgpu-1g",
370+
machineType: "a4x-highgpu-1g",
371+
expVolumeLimit: 63,
372+
},
373+
{
374+
name: "a4x-highgpu-2g",
375+
machineType: "a4x-highgpu-2g",
376+
expVolumeLimit: 127,
377+
},
378+
{
379+
name: "a4x-highgpu-2g-nolssd",
380+
machineType: "a4x-highgpu-2g-nolssd",
381+
expVolumeLimit: 127,
382+
},
383+
{
384+
name: "a4x-highgpu-4g",
385+
machineType: "a4x-highgpu-4g",
386+
expVolumeLimit: 127,
387+
},
388+
{
389+
name: "a4x-highgpu-8g",
390+
machineType: "a4x-highgpu-8g",
391+
expVolumeLimit: 127,
392+
},
393+
{
394+
name: "a4x-highgpu-metal",
395+
machineType: "a4x-highgpu-metal",
396+
expVolumeLimit: a4xMetalHyperdiskLimit,
397+
},
398+
{
399+
name: "a4x-max-metal",
400+
machineType: "a4x-max-metal",
401+
expVolumeLimit: a4xMetalHyperdiskLimit,
402+
},
403+
{
404+
name: "a4x-max-1g",
405+
machineType: "a4x-max-1g",
406+
expVolumeLimit: 63,
407+
},
408+
{
409+
name: "a4x-max-highgpu-2g",
410+
machineType: "a4x-max-2g",
411+
expVolumeLimit: 127,
412+
},
413+
{
414+
name: "a4x-max-4g",
415+
machineType: "a4x-max-4g",
416+
expVolumeLimit: 127,
417+
},
418+
{
419+
name: "a4x-max-8g", // -8g does not exist, testing edge case
420+
machineType: "a4x-max-8g",
421+
expVolumeLimit: 127,
422+
},
423+
{
424+
name: "a4x-medgpu-nolssd", // does not exist, testing edge case
425+
machineType: "a4x-medgpu-nolssd",
426+
expVolumeLimit: volumeLimitBig,
427+
},
353428
}
354429

355430
for _, tc := range testCases {

0 commit comments

Comments
 (0)