fix: stop defaulting disk_type to pd-standard - #150
Merged
Conversation
The driver defaulted every disk to `pd-standard`, which newer machine series reject outright: C3, C3D and M3 require `pd-balanced` or better, and C4 and N4 are Hyperdisk-only. Configuring `machine_type: n4-standard-2` passed every check in `validate!` -- the disk type is genuinely valid in the zone, just not for that machine -- and then failed at `insert_instance` with a raw API error. Send no `diskType` at all unless the user configured one. GCE derives an omitted disk type from the instance's machine series: `pd-standard` on first- and second-generation series such as N1, N2 and E2, `pd-balanced` on C3, C3D and M3, and `hyperdisk-balanced` on C4, N4 and newer. That keeps existing N1/N2 users on exactly the disk type they have today while making the newer families work, and it needs no table of machine families in the driver to go stale -- matching how machine types, disk types, networks and images are already validated against the live API rather than against a hardcoded list. Three call sites had to stop treating an absent type as an error: - `valid_disk_type?` used `nil` as a null-guard returning false, which conflated "absent" with "invalid". An unset type is now valid, and costs no `get_disk_type` call to confirm. - `legacy_disk_config` built its hash with explicit keys, so dropping the default produced `disk_type: nil` rather than no key. It now carries the key only when the user set it. - Both disk-creation paths set the type field only when configured. Without this the boot disk would have received the malformed partial URL `zones/<zone>/diskTypes/`. Extra non-boot disks are created as standalone disks before the instance exists, so GCE has no machine series to derive a default from and falls back to `pd-standard` there regardless of `machine_type`. Fixing that would need the family table this change deliberately avoids, so it is documented in the README instead. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Removes
pd-standardas the defaultdisk_typeso that newer GCE machine series work out of the box.Why
DISK_DEFAULT_CONFIGsetdisk_type: "pd-standard"on every disk. Newer machine series reject it:pd-standard,pd-balanced,pd-ssdpd-balanced,pd-ssd, Hyperdisk — nopd-standardSo
machine_type: n4-standard-2with nodisksblock passed all ofvalidate!— the disk type is valid in the zone, just not for that machine; validation is per-resource, not per-combination — and then failed atinsert_instancewith a raw API error.How
Send no
diskTypeunless the user configured one. GCE then substitutes the default for the instance's machine series, per theAttachedDiskInitializeParams.diskTypecontract in the Compute v1 discovery document:pd-standardfor first- and second-generation series,pd-balancedfor C3/C3D/M3,hyperdisk-balancedfor C4/N4 and newer.This keeps the driver's existing design — machine types, disk types, networks and images are all validated against the live API rather than a hardcoded list — instead of adding a machine-family table that would go stale with each new family. The two alternatives considered were defaulting to
pd-balanced(still fails on C4/N4, and silently changes the disk type for every existing N1/N2 user) and a family-prefix table in the driver (predictable, but duplicates a mapping Google already maintains).Three call sites needed to stop treating an absent type as an error:
valid_disk_type?usednil → falseas a null-guard, conflating "absent" with "invalid". Fine while absent was impossible; wrong once it became the default. Now valid, and skips aget_disk_typecall per run.legacy_disk_configbuilt its hash with explicit keys, so dropping the default yieldeddisk_type: nilinstead of no key. Now carries the key only when set.zones/<zone>/diskTypes/.Compatibility
No behaviour change for N1/N2/E2/T2/M1 users: GCE's default there is also
pd-standard, so no silent disk-type or cost change. C3/C3D/M3 now getpd-balancedand C4/N4/A3/Z3 gethyperdisk-balancedwhere they previously got a hard failure.Known limitation
Extra non-boot disks are created as standalone disks before the instance exists, so GCE has no machine series to derive a default from and falls back to
pd-standardregardless ofmachine_type. On C4/N4,disk_typemust be set explicitly on those disks. Solving this properly needs the family table this PR deliberately avoids, so it is documented in the new "Disk types and machine series" README section with an N4 example rather than worked around.Testing
bundle exec rake— 297 examples, 0 failures; chefstyle clean on 18 files.Six specs were written failing first:
disk_typekeyget_disk_typediskTypetypeplus the existing
valid_disk_type?(nil)spec flipped to the new contract.Not verified against a live GCE project — the machine-series mapping comes from the
google-apis-compute_v10.153.0 generated docs (Google's own discovery document), which is authoritative for API behaviour, but a realkitchen createagainst an N4 instance would be the actual proof.🤖 Generated with Claude Code