Skip to content

Commit 317c8e4

Browse files
authored
Merge pull request kubernetes-sigs#2092 from sunnylovestiramisu/attachLimit
Using Default PD Attach Limit for Gen3 Machines
2 parents 8e820cd + a9acfff commit 317c8e4

File tree

4 files changed

+4
-128
lines changed

4 files changed

+4
-128
lines changed

pkg/common/utils.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"net/http"
2525
"regexp"
2626
"slices"
27-
"strconv"
2827
"strings"
2928
"time"
3029

@@ -773,25 +772,6 @@ func MapNumber(num int64) int64 {
773772
return 0
774773
}
775774

776-
func ExtractCPUFromMachineType(input string) (int64, error) {
777-
// Regex to find the number at the end of the string,
778-
// it allows optional -lssd suffix.
779-
re := regexp.MustCompile(`(\d+)(?:-lssd|-metal)?$`)
780-
781-
match := re.FindStringSubmatch(input)
782-
if len(match) < 2 {
783-
return 0, fmt.Errorf("no number found at the end of the input string: %s", input)
784-
}
785-
786-
numberStr := match[1]
787-
number, err := strconv.ParseInt(numberStr, 10, 64)
788-
if err != nil {
789-
return 0, fmt.Errorf("failed to convert string '%s' to integer: %w", numberStr, err)
790-
}
791-
792-
return number, nil
793-
}
794-
795775
func DiskTypeLabelKey(diskType string) string {
796776
return fmt.Sprintf("%s/%s", DiskTypeKeyPrefix, diskType)
797777
}

pkg/common/utils_test.go

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,47 +2149,3 @@ func TestGetMinIopsThroughput(t *testing.T) {
21492149
})
21502150
}
21512151
}
2152-
2153-
func TestExtractCPUFromMachineType(t *testing.T) {
2154-
testcases := []struct {
2155-
name string
2156-
input string
2157-
expectOutput int64
2158-
expectErr bool
2159-
}{
2160-
{
2161-
name: "c3-highmem-176",
2162-
input: "c3-highmem-176",
2163-
expectOutput: 176,
2164-
},
2165-
{
2166-
name: "c3-standard-8-lssd",
2167-
input: "c3-standard-8-lssd",
2168-
expectOutput: 8,
2169-
},
2170-
{
2171-
name: "c3-standard-192-metal",
2172-
input: "c3-standard-192-metal",
2173-
expectOutput: 192,
2174-
},
2175-
{
2176-
name: "invalid input",
2177-
input: "something-not-valid",
2178-
expectOutput: 0,
2179-
expectErr: true,
2180-
},
2181-
}
2182-
2183-
for _, tc := range testcases {
2184-
t.Run(tc.name, func(t *testing.T) {
2185-
output, err := ExtractCPUFromMachineType(tc.input)
2186-
if output != tc.expectOutput {
2187-
t.Errorf("ExtractCPUFromMachineType: got %v, want %v", output, tc.expectOutput)
2188-
}
2189-
2190-
if gotErr := err != nil; gotErr != tc.expectErr {
2191-
t.Fatalf("ExtractCPUFromMachineType(%+v) = %v; expectedErr: %v", tc.input, err, tc.expectErr)
2192-
}
2193-
})
2194-
}
2195-
}

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

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,7 @@ const (
108108
// doc https://cloud.google.com/compute/docs/memory-optimized-machines#x4_disks
109109
x4HyperdiskLimit int64 = 39
110110
// doc https://cloud.google.com/compute/docs/accelerator-optimized-machines#a4-disks
111-
a4HyperdiskLimit int64 = 127
112-
// doc https://cloud.google.com/compute/docs/storage-optimized-machines#z3_disks
113-
// doc https://cloud.google.com/compute/docs/accelerator-optimized-machines#a3-disks
114-
gen3HyperdiskLimit int64 = 31
115-
// doc https://cloud.google.com/compute/docs/compute-optimized-machines#h3_disks
116-
h3HyperdiskLimit int64 = 7 // Use limit for Hyperdisk Balanced
111+
a4HyperdiskLimit int64 = 127
117112
defaultLinuxFsType = "ext4"
118113
defaultWindowsFsType = "ntfs"
119114
fsTypeExt3 = "ext3"
@@ -864,36 +859,6 @@ func (ns *GCENodeServer) GetVolumeLimits(ctx context.Context) (int64, error) {
864859
}
865860
}
866861

867-
// Process gen3 machine attach limits
868-
gen3MachineTypesPrefix := []string{"c3-", "c3d-"}
869-
for _, gen3Prefix := range gen3MachineTypesPrefix {
870-
if strings.HasPrefix(machineType, gen3Prefix) {
871-
cpus, err := common.ExtractCPUFromMachineType(machineType)
872-
if err != nil {
873-
return volumeLimitSmall, err
874-
}
875-
if cpus <= 8 || strings.Contains(machineType, "metal") {
876-
return volumeLimitSmall, nil
877-
}
878-
return gen3HyperdiskLimit, nil
879-
880-
}
881-
if strings.HasPrefix(machineType, "z3-") {
882-
return gen3HyperdiskLimit, nil
883-
}
884-
if strings.HasPrefix(machineType, "h3-") {
885-
return h3HyperdiskLimit, nil
886-
}
887-
if strings.HasPrefix(machineType, "a3-") {
888-
if machineType == "a3-ultragpu-8g" {
889-
return volumeLimitBig, nil
890-
} else {
891-
return gen3HyperdiskLimit, nil
892-
}
893-
}
894-
895-
}
896-
897862
return volumeLimitBig, nil
898863
}
899864

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

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -310,39 +310,14 @@ func TestNodeGetVolumeLimits(t *testing.T) {
310310
expVolumeLimit: a4HyperdiskLimit,
311311
},
312312
{
313-
name: "z3-highmem-176",
314-
machineType: "z3-highmem-176",
315-
expVolumeLimit: gen3HyperdiskLimit,
316-
},
317-
{
318-
name: "h3-standard-88",
319-
machineType: "h3-standard-88",
320-
expVolumeLimit: h3HyperdiskLimit,
321-
},
322-
{
323-
name: "a3-ultragpu-8g",
324-
machineType: "a3-ultragpu-8g",
313+
name: "c3-standard-4",
314+
machineType: "c3-standard-4",
325315
expVolumeLimit: volumeLimitBig,
326316
},
327-
{
328-
name: "a3-megagpu-8g",
329-
machineType: "a3-megagpu-8g",
330-
expVolumeLimit: gen3HyperdiskLimit, // 31
331-
},
332317
{
333318
name: "c3d-highmem-8-lssd",
334319
machineType: "c3d-highmem-8-lssd",
335-
expVolumeLimit: volumeLimitSmall, // 15
336-
},
337-
{
338-
name: "c3-standard-192-metal",
339-
machineType: "c3-standard-192-metal",
340-
expVolumeLimit: volumeLimitSmall, // 15
341-
},
342-
{
343-
name: "c3-standard-176",
344-
machineType: "c3-standard-176",
345-
expVolumeLimit: gen3HyperdiskLimit, // 31
320+
expVolumeLimit: volumeLimitBig,
346321
},
347322
}
348323

0 commit comments

Comments
 (0)