Skip to content

Update volume limits for new machine types: https://cloud.google.com/compute/docs/machine-types #455

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
merged 1 commit into from
Jan 24, 2020
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
14 changes: 7 additions & 7 deletions pkg/gce-pd-csi-driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,16 +505,16 @@ func (ns *GCENodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpa
}

func (ns *GCENodeServer) GetVolumeLimits() (int64, error) {
var volumeLimits int64

// Machine-type format: n1-type-CPUS or custom-CPUS-RAM or f1/g1-type
machineType := ns.MetadataService.GetMachineType()
if strings.HasPrefix(machineType, "n1-") || strings.HasPrefix(machineType, "custom-") {
volumeLimits = volumeLimitBig
} else {
volumeLimits = volumeLimitSmall

smallMachineTypes := []string{"f1-micro", "g1-small", "e2-micro", "e2-small", "e2-medium"}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using a map of machine types to volume size?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are only two volume size limits and only a very small subset are "small" so that is probably not necessary, see here for an interesting comparison of lookup times between slices and maps: https://www.darkcoding.net/software/go-slice-search-vs-map-lookup/ (breakeven point around 5 items).

The thing I want to avoid is a map for small things with all the value being smallValue and then "everything not in the map is big". Or else I would have to be exhaustive with the map which is error prone and repetitive

for _, st := range smallMachineTypes {
if machineType == st {
return volumeLimitSmall, nil
}
}
return volumeLimits, nil
return volumeLimitBig, nil
}

func (ns *GCENodeServer) getDevicePath(volumeID string, partition string) (string, error) {
Expand Down
5 changes: 5 additions & 0 deletions pkg/gce-pd-csi-driver/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ func TestNodeGetVolumeLimits(t *testing.T) {
machineType: "custom-2-4096",
expVolumeLimit: volumeLimitBig,
},
{
name: "Predifined e2 machine",
machineType: "e2-micro",
expVolumeLimit: volumeLimitSmall,
},
}

for _, tc := range testCases {
Expand Down