mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(ec2): keep each instance in the reservation of its RunInstances call (#8257)
RunInstances now stores its reservation id on each instance it launches, and DescribeInstances groups instances by it, so the ReservationId RunInstances answers stays the same on every call and instances launched together are listed together. An instance Floci did not launch keeps a stable reservation of its own, and a provider's reservation id is kept. Closes #8255
This commit is contained in:
1 parent
5cf3c780d4
commit
486f0e4604
4 files changed
+96
-5
No files matched your search
@@ -4184,6 +4184,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
Instance inst = new Instance();
|
||||
inst.setInstanceId(instanceId);
|
||||
inst.setOwnerId(callerAccountId());
|
||||
inst.setReservationId(reservationId);
|
||||
inst.setImageId(imageId);
|
||||
inst.setState(InstanceState.pending());
|
||||
inst.setInstanceType(effectiveInstanceType);
|
||||
@@ -4933,15 +4934,19 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
.filter(i -> matchesFilters(i, filters, region))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// Group into reservations (one instance per reservation for simplicity)
|
||||
// An instance without a stored reservation (one Floci did not launch) keeps a stable id of its own
|
||||
Map<String, Reservation> reservationMap = new LinkedHashMap<>();
|
||||
String ownerAccountId = callerAccountId();
|
||||
for (Instance inst : matched) {
|
||||
Reservation res = new Reservation();
|
||||
res.setReservationId("r-" + randomHex(17));
|
||||
res.setOwnerId(ownerAccountId);
|
||||
String reservationId = inst.getReservationId() != null
|
||||
? inst.getReservationId() : "r-" + inst.getInstanceId().substring("i-".length());
|
||||
Reservation res = reservationMap.computeIfAbsent(reservationId, id -> {
|
||||
Reservation created = new Reservation();
|
||||
created.setReservationId(id);
|
||||
created.setOwnerId(ownerAccountId);
|
||||
return created;
|
||||
});
|
||||
res.getInstances().add(inst);
|
||||
reservationMap.put(inst.getInstanceId(), res);
|
||||
}
|
||||
return new ArrayList<>(reservationMap.values());
|
||||
}
|
||||
@@ -6063,6 +6068,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
copy.setLaunchTime(source.getLaunchTime());
|
||||
copy.setAmiLaunchIndex(source.getAmiLaunchIndex());
|
||||
copy.setClientToken(source.getClientToken());
|
||||
copy.setReservationId(source.getReservationId());
|
||||
copy.setMonitoring(source.getMonitoring());
|
||||
copy.setSourceDestCheck(source.isSourceDestCheck());
|
||||
copy.setEbsOptimized(source.isEbsOptimized());
|
||||
|
||||
@@ -57,6 +57,7 @@ public class Instance {
|
||||
private String stateReasonMessage;
|
||||
private String region;
|
||||
private String ownerId;
|
||||
private String reservationId;
|
||||
private List<Tag> tags = new ArrayList<>();
|
||||
|
||||
private String rootVolumeId;
|
||||
@@ -231,6 +232,9 @@ public class Instance {
|
||||
public String getRegion() { return region; }
|
||||
public void setRegion(String region) { this.region = region; }
|
||||
|
||||
public String getReservationId() { return reservationId; }
|
||||
public void setReservationId(String reservationId) { this.reservationId = reservationId; }
|
||||
|
||||
public String getOwnerId() { return ownerId; }
|
||||
public void setOwnerId(String ownerId) { this.ownerId = ownerId; }
|
||||
|
||||
|
||||
Reference in new issue
Block a user