Skip to content

[release-1.18] Using Default PD Attach Limit for Gen3 Machines #2094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions pkg/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"net/http"
"regexp"
"slices"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -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)
}
Expand Down
44 changes: 0 additions & 44 deletions pkg/common/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
}
37 changes: 1 addition & 36 deletions pkg/gce-pd-csi-driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
31 changes: 3 additions & 28 deletions pkg/gce-pd-csi-driver/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

Expand Down