Skip to content

Commit 9110541

Browse files
authored
Merge pull request #2067 from k8s-infra-cherrypick-robot/cherry-pick-2064-to-release-1.14
[release-1.14] Add Attach Limit for Hyperdisk + Gen4 VMs
2 parents 24dbdc3 + a5f1354 commit 9110541

File tree

4 files changed

+99
-3
lines changed

4 files changed

+99
-3
lines changed

pkg/common/constants.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,16 @@ const (
3333
// Label that is set on a disk when it is used by a 'multi-zone' VolumeHandle
3434
MultiZoneLabel = "goog-gke-multi-zone"
3535
)
36+
37+
// doc https://cloud.google.com/compute/docs/disks/hyperdisks#max-total-disks-per-vm
38+
var Gen4MachineHyperdiskAttachLimitMap = []struct {
39+
max int64
40+
value int64
41+
}{
42+
{max: 4, value: 15},
43+
{max: 8, value: 23},
44+
{max: 16, value: 31},
45+
{max: 32, value: 49},
46+
{max: 64, value: 63},
47+
{max: 1024, value: 127},
48+
}

pkg/common/utils.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,3 +696,17 @@ func NewLimiter(limit, burst int, emptyBucket bool) *rate.Limiter {
696696

697697
return limiter
698698
}
699+
700+
func IsHyperdisk(diskType string) bool {
701+
return strings.HasPrefix(diskType, "hyperdisk-")
702+
}
703+
704+
// MapNumber is a function to map input cpu number to the Hyperdisk attach limit
705+
func MapNumber(num int64) int64 {
706+
for _, r := range Gen4MachineHyperdiskAttachLimitMap {
707+
if num <= r.max {
708+
return r.value
709+
}
710+
}
711+
return 0
712+
}

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"regexp"
2424
"runtime"
2525
"strconv"
26+
"strings"
2627
"time"
2728

2829
"google.golang.org/grpc/codes"
@@ -70,8 +71,12 @@ var _ csi.NodeServer = &GCENodeServer{}
7071
// node boot disk is considered an attachable disk so effective attach limit is
7172
// one less.
7273
const (
73-
volumeLimitSmall int64 = 15
74-
volumeLimitBig int64 = 127
74+
volumeLimitSmall int64 = 15
75+
volumeLimitBig int64 = 127
76+
// doc https://cloud.google.com/compute/docs/memory-optimized-machines#x4_disks
77+
x4HyperdiskLimit int64 = 39
78+
// doc https://cloud.google.com/compute/docs/accelerator-optimized-machines#a4-disks
79+
a4HyperdiskLimit int64 = 127
7580
defaultLinuxFsType = "ext4"
7681
defaultWindowsFsType = "ntfs"
7782
fsTypeExt3 = "ext3"
@@ -501,6 +506,9 @@ func (ns *GCENodeServer) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRe
501506
nodeID := common.CreateNodeID(ns.MetadataService.GetProject(), ns.MetadataService.GetZone(), ns.MetadataService.GetName())
502507

503508
volumeLimits, err := ns.GetVolumeLimits()
509+
if err != nil {
510+
klog.Errorf("GetVolumeLimits failed: %v", err.Error())
511+
}
504512

505513
resp := &csi.NodeGetInfoResponse{
506514
NodeId: nodeID,
@@ -667,5 +675,24 @@ func (ns *GCENodeServer) GetVolumeLimits() (int64, error) {
667675
return volumeLimitSmall, nil
668676
}
669677
}
678+
gen4MachineTypesPrefix := []string{"c4a-", "c4-", "n4-"}
679+
for _, gen4Prefix := range gen4MachineTypesPrefix {
680+
if strings.HasPrefix(machineType, gen4Prefix) {
681+
cpuString := machineType[strings.LastIndex(machineType, "-")+1:]
682+
cpus, err := strconv.ParseInt(cpuString, 10, 64)
683+
if err != nil {
684+
return volumeLimitSmall, fmt.Errorf("invalid cpuString %s for machine type: %v", cpuString, machineType)
685+
}
686+
return common.MapNumber(cpus), nil
687+
688+
}
689+
if strings.HasPrefix(machineType, "x4-") {
690+
return x4HyperdiskLimit, nil
691+
}
692+
if strings.HasPrefix(machineType, "a4-") {
693+
return a4HyperdiskLimit, nil
694+
}
695+
}
696+
670697
return volumeLimitBig, nil
671698
}

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

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ func TestNodeGetVolumeLimits(t *testing.T) {
204204
name string
205205
machineType string
206206
expVolumeLimit int64
207+
expectError bool
207208
}{
208209
{
209210
name: "Predifined standard machine",
@@ -235,13 +236,54 @@ func TestNodeGetVolumeLimits(t *testing.T) {
235236
machineType: "e2-micro",
236237
expVolumeLimit: volumeLimitSmall,
237238
},
239+
{
240+
name: "c4-standard-192",
241+
machineType: "c4-standard-192",
242+
expVolumeLimit: 127,
243+
},
244+
{
245+
name: "c4-standard-48",
246+
machineType: "c4-standard-48",
247+
expVolumeLimit: 63,
248+
},
249+
{
250+
name: "c4a-standard-4",
251+
machineType: "c4a-standard-4",
252+
expVolumeLimit: 15,
253+
},
254+
{
255+
name: "n4-standard-16",
256+
machineType: "n4-standard-16",
257+
expVolumeLimit: 31,
258+
},
259+
{
260+
name: "n4-highcpu-4",
261+
machineType: "n4-highcpu-4",
262+
expVolumeLimit: 15,
263+
},
264+
{
265+
name: "invalid gen4 machine type",
266+
machineType: "n4-highcpu-4xyz",
267+
expVolumeLimit: volumeLimitSmall,
268+
expectError: true,
269+
},
270+
{
271+
name: "x4-megamem-960-metal",
272+
machineType: "x4-megamem-960-metal",
273+
expVolumeLimit: x4HyperdiskLimit,
274+
},
275+
{
276+
name: "a4-highgpu-8g",
277+
machineType: "a4-highgpu-8g",
278+
expVolumeLimit: a4HyperdiskLimit,
279+
},
238280
}
239281

240282
for _, tc := range testCases {
241283
t.Logf("Test case: %s", tc.name)
242284
metadataservice.SetMachineType(tc.machineType)
243285
res, err := ns.NodeGetInfo(context.Background(), req)
244-
if err != nil {
286+
if err != nil && !tc.expectError {
245287
t.Fatalf("Failed to get node info: %v", err)
246288
} else {
247289
volumeLimit := res.GetMaxVolumesPerNode()

0 commit comments

Comments
 (0)