Repository navigation
feat(ec2): an instance reports its own block devices (#669) - #679
Merged
Merged
Conversation
DescribeInstances, RunInstances and DescribeInstanceAttribute now render a blockDeviceMapping set. The set is derived from the volume records rather than from the mappings a launch recorded, so it tracks reality rather than intent: a volume attached after launch appears, a detached one stops appearing, and an instance store device never appears because it never became a volume. Hoisting ec2InstanceItem to package level also fixes a live #444-class drift: RunInstances omitted the iamInstanceProfile DescribeInstances reported for the same instance.
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
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
DescribeInstances,RunInstancesandDescribeInstanceAttributenow render ablockDeviceMappingset for an instance.#666 made a launch materialize its EBS volumes, but the only way to learn which volume sat
on which device was
DescribeVolumesfiltered onattachment.instance-id— a question realEC2 answers from the instance.
DescribeInstanceAttributerefusedblockDeviceMappingoutright, which was right when there was nothing to render.
The set is derived from the volumes, not from the request
That is the design decision the whole change rests on, and it is what satisfies the
detached-later-stops-appearing criterion for free:
AttachVolumeafter launch appears,ec2CreatesEBSVolumeexcluded it inEC2: RunInstances' inline BlockDeviceMapping.N.Ebs.* is parsed nowhere and never reaches DescribeVolumes #666 and it therefore never became an
EC2Volume.EC2Instancecarries no block-device field, so the volumes are also the only availablesource. The mapping from state to AWS's shape is one-to-one and total —
deviceName←att.Device,volumeId←vol.VolumeID,status←att.State,attachTime←att.AttachTime,deleteOnTermination←att.DeleteOnTermination— so nothing isfabricated.
The volume list is read once per request and bucketed by instance ID.
describeInstancesalready does oneListplus aGetper security group per instance, soa per-instance
Listwould compound into an instances × volumes scan.Shape
InstanceBlockDeviceMappingis exactlydeviceName+ebs.EbsInstanceBlockDevicehaseight members and no size; the four AWS's own sample shows are rendered, in its order.
The other four (
associatedResource,ebsCardIndex,operator,volumeOwnerId) areomitted rather than defaulted — substrate records nothing behind them, and a fabricated
volumeOwnerIdis indistinguishable to a caller from a real one.Because there is no size member, this does not close #666's gap:
docs/services.mdstill says
DescribeVolumesis the only surface a launch-specified size is observable on,and that sentence is deliberately kept true.
EbsInstanceBlockDevice.statususes the four-valueAttachmentStatusenum, whileDescribeVolumes' volume-side status is a five-value enum that addsbusy— so the two aredeliberately not rendered through one shared helper, and the type comment says why.
On
DescribeInstanceAttributethe response needs both halves of the existinggroupSetpattern: a
*ec2BlockDeviceMappingSetXMLpointer field, so the element is absent from auserDataresponse (encoding/xmlemits the parent of afoo>itempath even when theslice is empty), and an unconditional non-nil assignment in its own
case, so an instancewith no EBS volumes renders present-but-empty. No
<value>wrapper — it is one of theInstanceAttributemembers that is not anAttributeValue.Two divergences from the issue's premises, corrected rather than implemented
The issue says
RunInstances' response should render the set "since the reference shows itthere too". It does not. The reference's only
RunInstancessample response emits<blockDeviceMapping />, empty, on apendinginstance whose request declared no mappingsat all. Rendering it populated is a deliberate divergence, argued on substrate's own
grounds — the same ones
ec2_plugin.goalready records fornetworkInterfaceSet: substrate'sinstances are running and their volumes exist by the time
RunInstancesanswers. The codecomment and the release's
## Provenancesay so rather than claiming AWS settles it.The issue calls the two
ec2InstanceItemstructs duplicates; they had already driftedagain.
describeInstances' copy carriediamInstanceProfileandrunInstancesResponse'did not, they used different Go types for the state element, and their
placement/instanceStateorder was swapped. SoRunInstancessilently omitted theinstance profile
DescribeInstancesreported for the same instance — a live #444-classdefect, fixed as a side effect of the hoist and given its own
### FixedCHANGELOG linerather than landing quietly.
ec2InstanceItemand its four sub-items are now package-levelwith one builder, following the
ec2GroupItem/ec2NetworkInterfaceItemprecedents whosecomments record the original #444 bug.
Ordering
Sorted by device name, volume ID breaking a tie.
DescribeInstancesstates outright thatits own order may vary, so no fidelity claim rests on this — but state-listing order is
not a promise substrate makes, and a deterministic emulator answering one request two ways
would break the guarantee the project exists for. No test asserts element order within an
item.
Fail-before proof
All eight new tests fail on the pre-fix tree.
DescribeInstancesandRunInstancesreturnzero mappings, and the attribute surface refuses:
Tests
Eight HTTP-tier tests in
emulator/ec2_instance_blockdevices_test.go, reusing #666'sbdmRunInstances/bdmDescribeVolumeshelpers: the three surfaces; thatRunInstancesandDescribeInstancesagree byte-for-byte on the set (the drift above); that the volume IDsagree with what
DescribeVolumesreports for the same instance; instance-store andNoDevice; attach-then-detach tracking; per-instance bucketing on a two-count launch;present-but-empty on the attribute surface after termination; and stable order across four
identical requests.
ec2AttributeSupportedis an allow-list with a catch-alldefault: return false, so thechange is "the allow-list grew" and the
"blockDeviceMapping"row inTestEC2_InstanceAttribute_UnknownAttributeis deleted. Its doc comment now records thatthe row left deliberately and that the remaining five still cover all four refusal classes —
listed-and-rejected-by-AWS, not-an-attribute, listed-and-unmodelled, and right-name-wrong-case.
Verification
gofmt -lclean,go build ./...,go vet ./...,golangci-lint run ./...(0 issues),make test(race, all packages),go vet -C test/e2e ./...+go test -C test/e2e ./...,gen-service-reference -check,scripts/check-doc-versions.sh,npm --prefix docs run build.Docs
Two sites, not the one the issue names: the launch-time-storage "not modeled" paragraph
loses both
blockDeviceMappingclauses and gains a new "An instance reports its own blockdevices" subsection, and the instance-attributes section's unmodelled-attributes list
drops the name while its table grows a fifth row. The two operation-table rows and the
DescribeInstanceAttributerow are updated too.Closes #669