mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
* fix(ec2): support NAT gateway secondary addresses * fix(ec2): update a NAT gateway's secondary addresses in place A CloudFormation update that changed only a NAT gateway's Secondary* properties replaced the gateway. The replacement was created while the old gateway still held its Elastic IP or fixed private address, so it came back failed with Resource.AlreadyAssociated (or InvalidIPAddress.InUse) and the update failed. The schema does not mark the secondaries create-only, so AWS changes them in place and the gateway keeps its id. Ec2Service.updateNatGatewaySecondaryAddresses sets a gateway's secondaries to the requested ones: kept ones stay, dropped Elastic IPs are handed back, new ones are checked as CreateNatGateway checks them, and every check runs before anything changes. The provisioner calls it instead of replacing, and records the prior secondaries so a rolled-back update puts them back. * fix(ec2): keep a NAT gateway's picked secondary when listed ones change The counted slots of an in-place secondary update kept the first secondary with no Elastic IP and an address the request does not list. With SecondaryPrivateIpAddresses [A] and a count of 1 changed to [B] and 1, that was the dropped listed A, while the address the subnet had picked was given up. Counted addresses always follow the listed ones, so the counted slots now keep the last such secondaries, in order. Tests cover a count changed in place (an unrelated change keeps the same addresses; 1 to 2 keeps the first; 2 to 1 keeps one of them), the picked address surviving a listed change, and secondary Elastic IPs swapped between listed addresses or moved to a new one, with DescribeAddresses showing each held at its new address. * test(ec2): pin which counted NAT gateway secondary an update keeps The counted slots keep the last unlisted secondaries, so a count lowered from 2 to 1 keeps the second address; the test now asserts that, and that raising the count from 1 to 2 adds a new address in the subnet after the kept one. The comment no longer claims counted addresses always follow the listed ones: slot position is the only record of an address's origin, and across updates a once-listed address can move behind a picked one. * fix(ec2): read a NAT gateway under the allocation lock before updating its secondaries The secondary-address update read the gateway before taking the lock that DeleteNatGateway holds. A delete finishing in between left the update holding a stale copy, which it then wrote back, re-associating the Elastic IPs the delete had released and overwriting the association of a gateway that had since taken the primary one. The gateway is now read again under the lock, and one that is gone or deleted is refused with NatGatewayNotFound. * test(cloudformation): read NAT gateway addresses through XmlParser The secondary-address tests picked addresses out of DescribeNatGateways and DescribeAddresses with a regular expression and substring checks that depended on element order. They now select the non-primary items of natGatewayAddressSet through XmlParser. * test(ec2): cover a NAT gateway stored as deleted by a racing tag write CreateTags writes a NAT gateway back under the gateway's tag lock, which DeleteNatGateway does not take. A tag write that read the gateway before a delete therefore stores the very record the delete marked deleted, so the secondary-address update's deleted-state check is reachable. The test pauses the tag write's put, deletes the gateway, lets the put finish, and asserts the update refuses the record with NatGatewayNotFound and holds no Elastic IP for it. * refactor(ec2): fill a NAT gateway's address slots in one place CreateNatGateway and the secondary-address update each walked the gateway's slots the same way: take the listed Elastic IP and address at each position, assign a free address where none is listed, build the address, and give back what was assigned if a later slot fails. Both now call fillNatGatewaySlots. Create passes its primary address as slot 0 and marks it primary afterwards; the update passes the slots its kept secondaries already fill. The order addresses are assigned in, the error codes and the release on failure are unchanged. * test(ec2): cover NAT gateway lease release and reuse the shared test helpers No test covered the lease a NAT gateway gives back when its addresses run out part way, so the shared slot-filling walk could lose its release with every test green. Two tests now run a /28 subnet out of addresses, one through CreateNatGateway and one through a secondary-address update, and verify the lease taken on the VPC network is released and that the update leaves the gateway as it was. The concurrent-delete test now builds its service with mockModeService() and waits for the blocked update with ThreadStates.awaitBlockedOrDone. * test(ec2): build the small NAT subnet with privateSubnet