mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(autoscaling): preserve policy and mixed instances parity (#1437)
* fix(autoscaling): preserve launch template capacity metadata * feat(autoscaling): preserve target tracking policies * feat(autoscaling): preserve mixed instances policies
This commit is contained in:
1 parent
630328547e
commit
9236b40073
12 files changed
+907
-26
No files matched your search
+186
-13
@@ -332,10 +332,51 @@ class AutoScalingIntegrationTest {
|
||||
.body(not(containsString("scale-out")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(17)
|
||||
void putTargetTrackingScalingPolicy() {
|
||||
given()
|
||||
.formParam("Action", "PutScalingPolicy")
|
||||
.formParam("AutoScalingGroupName", "my-asg")
|
||||
.formParam("PolicyName", "cpu-target")
|
||||
.formParam("PolicyType", "TargetTrackingScaling")
|
||||
.formParam("EstimatedInstanceWarmup", "180")
|
||||
.formParam("TargetTrackingConfiguration.PredefinedMetricSpecification.PredefinedMetricType",
|
||||
"ASGAverageCPUUtilization")
|
||||
.formParam("TargetTrackingConfiguration.TargetValue", "55.5")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("PolicyARN"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(18)
|
||||
void describeTargetTrackingScalingPolicy() {
|
||||
given()
|
||||
.formParam("Action", "DescribePolicies")
|
||||
.formParam("AutoScalingGroupName", "my-asg")
|
||||
.formParam("PolicyNames.member.1", "cpu-target")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<PolicyName>cpu-target</PolicyName>"))
|
||||
.body(containsString("<PolicyType>TargetTrackingScaling</PolicyType>"))
|
||||
.body(containsString("<EstimatedInstanceWarmup>180</EstimatedInstanceWarmup>"))
|
||||
.body(containsString("<TargetTrackingConfiguration>"))
|
||||
.body(containsString("<PredefinedMetricSpecification>"))
|
||||
.body(containsString("<PredefinedMetricType>ASGAverageCPUUtilization</PredefinedMetricType>"))
|
||||
.body(containsString("<TargetValue>55.5</TargetValue>"));
|
||||
}
|
||||
|
||||
// ── Metadata ──────────────────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(17)
|
||||
@Order(19)
|
||||
void describeTerminationPolicyTypes() {
|
||||
given()
|
||||
.formParam("Action", "DescribeTerminationPolicyTypes")
|
||||
@@ -349,7 +390,7 @@ class AutoScalingIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(18)
|
||||
@Order(20)
|
||||
void describeAccountLimits() {
|
||||
given()
|
||||
.formParam("Action", "DescribeAccountLimits")
|
||||
@@ -362,7 +403,7 @@ class AutoScalingIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(19)
|
||||
@Order(21)
|
||||
void describeLifecycleHookTypes() {
|
||||
given()
|
||||
.formParam("Action", "DescribeLifecycleHookTypes")
|
||||
@@ -376,7 +417,7 @@ class AutoScalingIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(20)
|
||||
@Order(22)
|
||||
void describeScalingActivities() {
|
||||
given()
|
||||
.formParam("Action", "DescribeScalingActivities")
|
||||
@@ -390,7 +431,7 @@ class AutoScalingIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(21)
|
||||
@Order(23)
|
||||
void createAutoScalingGroupWithLaunchTemplateId() {
|
||||
given()
|
||||
.formParam("Action", "CreateAutoScalingGroup")
|
||||
@@ -425,7 +466,7 @@ class AutoScalingIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(22)
|
||||
@Order(24)
|
||||
void describeAutoScalingGroupWithLaunchTemplateId() {
|
||||
given()
|
||||
.formParam("Action", "DescribeAutoScalingGroups")
|
||||
@@ -466,7 +507,7 @@ class AutoScalingIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(23)
|
||||
@Order(25)
|
||||
void startInstanceRefresh() {
|
||||
instanceRefreshId = given()
|
||||
.formParam("Action", "StartInstanceRefresh")
|
||||
@@ -495,7 +536,7 @@ class AutoScalingIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(24)
|
||||
@Order(26)
|
||||
void describeInstanceRefreshes() {
|
||||
String body = given()
|
||||
.formParam("Action", "DescribeInstanceRefreshes")
|
||||
@@ -537,7 +578,7 @@ class AutoScalingIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(25)
|
||||
@Order(27)
|
||||
void describeInstanceRefreshesPaginatesNewestFirst() {
|
||||
pagedInstanceRefreshId = given()
|
||||
.formParam("Action", "StartInstanceRefresh")
|
||||
@@ -581,7 +622,124 @@ class AutoScalingIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(26)
|
||||
@Order(28)
|
||||
void createAutoScalingGroupWithMixedInstancesPolicy() {
|
||||
given()
|
||||
.formParam("Action", "CreateAutoScalingGroup")
|
||||
.formParam("AutoScalingGroupName", "my-mixed-asg")
|
||||
.formParam("MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.LaunchTemplateId",
|
||||
"lt-mixed")
|
||||
.formParam("MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.Version", "3")
|
||||
.formParam("MixedInstancesPolicy.LaunchTemplate.Overrides.member.1.InstanceType", "t4g.medium")
|
||||
.formParam("MixedInstancesPolicy.LaunchTemplate.Overrides.member.2.InstanceType", "m7g.large")
|
||||
.formParam("MixedInstancesPolicy.InstancesDistribution.OnDemandBaseCapacity", "1")
|
||||
.formParam("MixedInstancesPolicy.InstancesDistribution.OnDemandPercentageAboveBaseCapacity", "25")
|
||||
.formParam("MixedInstancesPolicy.InstancesDistribution.SpotAllocationStrategy", "capacity-optimized")
|
||||
.formParam("MinSize", "0")
|
||||
.formParam("MaxSize", "4")
|
||||
.formParam("DesiredCapacity", "1")
|
||||
.formParam("AvailabilityZones.member.1", "us-east-1a")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("CreateAutoScalingGroupResponse"));
|
||||
|
||||
given()
|
||||
.formParam("Action", "DescribeAutoScalingGroups")
|
||||
.formParam("AutoScalingGroupNames.member.1", "my-mixed-asg")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<MixedInstancesPolicy>"))
|
||||
.body(containsString("<LaunchTemplateSpecification>"))
|
||||
.body(containsString("<LaunchTemplateId>lt-mixed</LaunchTemplateId>"))
|
||||
.body(containsString("<Version>3</Version>"))
|
||||
.body(containsString("<InstanceType>t4g.medium</InstanceType>"))
|
||||
.body(containsString("<InstanceType>m7g.large</InstanceType>"))
|
||||
.body(containsString("<OnDemandBaseCapacity>1</OnDemandBaseCapacity>"))
|
||||
.body(containsString("<OnDemandPercentageAboveBaseCapacity>25</OnDemandPercentageAboveBaseCapacity>"))
|
||||
.body(containsString("<SpotAllocationStrategy>capacity-optimized</SpotAllocationStrategy>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(29)
|
||||
void updateAutoScalingGroupFromLaunchTemplateToMixedInstancesPolicy() {
|
||||
given()
|
||||
.formParam("Action", "UpdateAutoScalingGroup")
|
||||
.formParam("AutoScalingGroupName", "my-lt-asg")
|
||||
.formParam("MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.LaunchTemplateId",
|
||||
"lt-replacement")
|
||||
.formParam("MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.Version", "4")
|
||||
.formParam("MixedInstancesPolicy.LaunchTemplate.Overrides.member.1.InstanceType", "c7g.large")
|
||||
.formParam("MixedInstancesPolicy.InstancesDistribution.OnDemandBaseCapacity", "0")
|
||||
.formParam("MixedInstancesPolicy.InstancesDistribution.OnDemandPercentageAboveBaseCapacity", "10")
|
||||
.formParam("MixedInstancesPolicy.InstancesDistribution.SpotAllocationStrategy", "lowest-price")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("UpdateAutoScalingGroupResponse"));
|
||||
|
||||
given()
|
||||
.formParam("Action", "DescribeAutoScalingGroups")
|
||||
.formParam("AutoScalingGroupNames.member.1", "my-lt-asg")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<MixedInstancesPolicy>"))
|
||||
.body(containsString("<LaunchTemplateId>lt-replacement</LaunchTemplateId>"))
|
||||
.body(containsString("<Version>4</Version>"))
|
||||
.body(containsString("<InstanceType>c7g.large</InstanceType>"))
|
||||
.body(containsString("<OnDemandBaseCapacity>0</OnDemandBaseCapacity>"))
|
||||
.body(containsString("<OnDemandPercentageAboveBaseCapacity>10</OnDemandPercentageAboveBaseCapacity>"))
|
||||
.body(containsString("<SpotAllocationStrategy>lowest-price</SpotAllocationStrategy>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(30)
|
||||
void updateMixedInstancesPolicyOverridesAndDistribution() {
|
||||
given()
|
||||
.formParam("Action", "UpdateAutoScalingGroup")
|
||||
.formParam("AutoScalingGroupName", "my-mixed-asg")
|
||||
.formParam("MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.LaunchTemplateId",
|
||||
"lt-mixed")
|
||||
.formParam("MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.Version", "5")
|
||||
.formParam("MixedInstancesPolicy.LaunchTemplate.Overrides.member.1.InstanceType", "r7g.large")
|
||||
.formParam("MixedInstancesPolicy.InstancesDistribution.OnDemandBaseCapacity", "2")
|
||||
.formParam("MixedInstancesPolicy.InstancesDistribution.OnDemandPercentageAboveBaseCapacity", "50")
|
||||
.formParam("MixedInstancesPolicy.InstancesDistribution.SpotAllocationStrategy", "price-capacity-optimized")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("UpdateAutoScalingGroupResponse"));
|
||||
|
||||
given()
|
||||
.formParam("Action", "DescribeAutoScalingGroups")
|
||||
.formParam("AutoScalingGroupNames.member.1", "my-mixed-asg")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<Version>5</Version>"))
|
||||
.body(containsString("<InstanceType>r7g.large</InstanceType>"))
|
||||
.body(not(containsString("<InstanceType>t4g.medium</InstanceType>")))
|
||||
.body(containsString("<OnDemandBaseCapacity>2</OnDemandBaseCapacity>"))
|
||||
.body(containsString("<OnDemandPercentageAboveBaseCapacity>50</OnDemandPercentageAboveBaseCapacity>"))
|
||||
.body(containsString("<SpotAllocationStrategy>price-capacity-optimized</SpotAllocationStrategy>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(31)
|
||||
void deleteLaunchTemplateAutoScalingGroup() {
|
||||
given()
|
||||
.formParam("Action", "DeleteAutoScalingGroup")
|
||||
@@ -598,7 +756,7 @@ class AutoScalingIntegrationTest {
|
||||
// ── Cleanup ───────────────────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(27)
|
||||
@Order(32)
|
||||
void deleteAutoScalingGroup() {
|
||||
given()
|
||||
.formParam("Action", "DeleteAutoScalingGroup")
|
||||
@@ -613,7 +771,22 @@ class AutoScalingIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(28)
|
||||
@Order(33)
|
||||
void deleteMixedInstancesAutoScalingGroup() {
|
||||
given()
|
||||
.formParam("Action", "DeleteAutoScalingGroup")
|
||||
.formParam("AutoScalingGroupName", "my-mixed-asg")
|
||||
.formParam("ForceDelete", "true")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("DeleteAutoScalingGroupResponse"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(34)
|
||||
void deleteLaunchConfiguration() {
|
||||
given()
|
||||
.formParam("Action", "DeleteLaunchConfiguration")
|
||||
@@ -627,7 +800,7 @@ class AutoScalingIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(29)
|
||||
@Order(35)
|
||||
void describeAutoScalingGroupsEmpty() {
|
||||
given()
|
||||
.formParam("Action", "DescribeAutoScalingGroups")
|
||||
|
||||
+102
@@ -25,6 +25,7 @@ class AutoScalingQueryHandlerTest {
|
||||
"lt-original",
|
||||
null,
|
||||
"1",
|
||||
null,
|
||||
0,
|
||||
3,
|
||||
1,
|
||||
@@ -89,6 +90,7 @@ class AutoScalingQueryHandlerTest {
|
||||
"lt-current",
|
||||
null,
|
||||
"$Latest",
|
||||
null,
|
||||
0,
|
||||
3,
|
||||
1,
|
||||
@@ -126,4 +128,104 @@ class AutoScalingQueryHandlerTest {
|
||||
assertTrue(xml.contains("<LaunchTemplateId>lt-current</LaunchTemplateId>"));
|
||||
assertTrue(xml.contains("<Version>7</Version>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void targetTrackingScalingPolicyUsesAwsQueryXmlShape() {
|
||||
AutoScalingService service = new AutoScalingService();
|
||||
service.regionResolver = new RegionResolver(REGION, "000000000000");
|
||||
service.createAutoScalingGroup(REGION,
|
||||
"target-tracking-asg",
|
||||
null,
|
||||
"lt-current",
|
||||
null,
|
||||
"$Latest",
|
||||
null,
|
||||
0,
|
||||
3,
|
||||
1,
|
||||
300,
|
||||
List.of("us-east-1a"),
|
||||
List.of(),
|
||||
List.of(),
|
||||
List.of(),
|
||||
"EC2",
|
||||
0,
|
||||
List.of("Default"),
|
||||
java.util.Map.of());
|
||||
|
||||
AutoScalingQueryHandler handler = new AutoScalingQueryHandler(service);
|
||||
MultivaluedHashMap<String, String> putParams = new MultivaluedHashMap<>();
|
||||
putParams.add("AutoScalingGroupName", "target-tracking-asg");
|
||||
putParams.add("PolicyName", "cpu-target");
|
||||
putParams.add("PolicyType", "TargetTrackingScaling");
|
||||
putParams.add("EstimatedInstanceWarmup", "180");
|
||||
putParams.add("TargetTrackingConfiguration.PredefinedMetricSpecification.PredefinedMetricType",
|
||||
"ASGAverageCPUUtilization");
|
||||
putParams.add("TargetTrackingConfiguration.TargetValue", "55.5");
|
||||
|
||||
Response putResponse = handler.handle("PutScalingPolicy", putParams, REGION);
|
||||
|
||||
assertEquals(200, putResponse.getStatus());
|
||||
assertTrue(((String) putResponse.getEntity()).contains("<PolicyARN>"));
|
||||
|
||||
MultivaluedHashMap<String, String> describeParams = new MultivaluedHashMap<>();
|
||||
describeParams.add("AutoScalingGroupName", "target-tracking-asg");
|
||||
describeParams.add("PolicyNames.member.1", "cpu-target");
|
||||
|
||||
Response describeResponse = handler.handle("DescribePolicies", describeParams, REGION);
|
||||
|
||||
assertEquals(200, describeResponse.getStatus());
|
||||
String xml = (String) describeResponse.getEntity();
|
||||
assertTrue(xml.contains("<PolicyName>cpu-target</PolicyName>"));
|
||||
assertTrue(xml.contains("<PolicyType>TargetTrackingScaling</PolicyType>"));
|
||||
assertTrue(xml.contains("<EstimatedInstanceWarmup>180</EstimatedInstanceWarmup>"));
|
||||
assertTrue(xml.contains("<TargetTrackingConfiguration>"));
|
||||
assertTrue(xml.contains("<PredefinedMetricSpecification>"));
|
||||
assertTrue(xml.contains("<PredefinedMetricType>ASGAverageCPUUtilization</PredefinedMetricType>"));
|
||||
assertTrue(xml.contains("<TargetValue>55.5</TargetValue>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAutoScalingGroupWithMixedInstancesPolicyUsesAwsQueryXmlShape() {
|
||||
AutoScalingService service = new AutoScalingService();
|
||||
service.regionResolver = new RegionResolver(REGION, "000000000000");
|
||||
AutoScalingQueryHandler handler = new AutoScalingQueryHandler(service);
|
||||
|
||||
MultivaluedHashMap<String, String> createParams = new MultivaluedHashMap<>();
|
||||
createParams.add("AutoScalingGroupName", "mixed-asg");
|
||||
createParams.add("MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.LaunchTemplateId",
|
||||
"lt-mixed");
|
||||
createParams.add("MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.Version", "3");
|
||||
createParams.add("MixedInstancesPolicy.LaunchTemplate.Overrides.member.1.InstanceType", "t4g.medium");
|
||||
createParams.add("MixedInstancesPolicy.LaunchTemplate.Overrides.member.2.InstanceType", "m7g.large");
|
||||
createParams.add("MixedInstancesPolicy.InstancesDistribution.OnDemandBaseCapacity", "1");
|
||||
createParams.add("MixedInstancesPolicy.InstancesDistribution.OnDemandPercentageAboveBaseCapacity", "25");
|
||||
createParams.add("MixedInstancesPolicy.InstancesDistribution.SpotAllocationStrategy", "capacity-optimized");
|
||||
createParams.add("MinSize", "0");
|
||||
createParams.add("MaxSize", "4");
|
||||
createParams.add("DesiredCapacity", "1");
|
||||
createParams.add("AvailabilityZones.member.1", "us-east-1a");
|
||||
|
||||
Response createResponse = handler.handle("CreateAutoScalingGroup", createParams, REGION);
|
||||
|
||||
assertEquals(200, createResponse.getStatus());
|
||||
|
||||
MultivaluedHashMap<String, String> describeParams = new MultivaluedHashMap<>();
|
||||
describeParams.add("AutoScalingGroupNames.member.1", "mixed-asg");
|
||||
|
||||
Response describeResponse = handler.handle("DescribeAutoScalingGroups", describeParams, REGION);
|
||||
|
||||
assertEquals(200, describeResponse.getStatus());
|
||||
String xml = (String) describeResponse.getEntity();
|
||||
assertTrue(xml.contains("<MixedInstancesPolicy>"));
|
||||
assertTrue(xml.contains("<LaunchTemplateSpecification>"));
|
||||
assertTrue(xml.contains("<LaunchTemplateId>lt-mixed</LaunchTemplateId>"));
|
||||
assertTrue(xml.contains("<Version>3</Version>"));
|
||||
assertTrue(xml.contains("<Overrides>"));
|
||||
assertTrue(xml.contains("<InstanceType>t4g.medium</InstanceType>"));
|
||||
assertTrue(xml.contains("<InstanceType>m7g.large</InstanceType>"));
|
||||
assertTrue(xml.contains("<OnDemandBaseCapacity>1</OnDemandBaseCapacity>"));
|
||||
assertTrue(xml.contains("<OnDemandPercentageAboveBaseCapacity>25</OnDemandPercentageAboveBaseCapacity>"));
|
||||
assertTrue(xml.contains("<SpotAllocationStrategy>capacity-optimized</SpotAllocationStrategy>"));
|
||||
}
|
||||
}
|
||||
+132
-2
@@ -2,11 +2,13 @@ package io.github.hectorvent.floci.services.autoscaling;
|
||||
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.AsgInstance;
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.AutoScalingGroup;
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.MixedInstancesPolicy;
|
||||
import io.github.hectorvent.floci.services.ec2.Ec2Service;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Instance;
|
||||
import io.github.hectorvent.floci.services.ec2.model.InstanceState;
|
||||
import io.github.hectorvent.floci.services.ec2.model.LaunchTemplate;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Reservation;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Tag;
|
||||
import io.github.hectorvent.floci.services.elbv2.ElbV2Service;
|
||||
import io.github.hectorvent.floci.services.elbv2.model.TargetDescription;
|
||||
import io.github.hectorvent.floci.services.elbv2.model.TargetHealth;
|
||||
@@ -73,6 +75,8 @@ class AutoScalingReconcilerTest {
|
||||
version.setLatestVersionNumber("1");
|
||||
version.setImageId("ami-version-1");
|
||||
version.setInstanceType("t3.micro");
|
||||
List<Tag> instanceTags = List.of(new Tag("app.ClusterId", "development"));
|
||||
version.setInstanceTags(instanceTags);
|
||||
when(ec2Service.describeLaunchTemplates("us-east-1", List.of("lt-123"), List.of(), Map.of()))
|
||||
.thenReturn(List.of(launchTemplate));
|
||||
when(ec2Service.describeLaunchTemplateVersions("us-east-1", "lt-123", null, List.of("1")))
|
||||
@@ -83,7 +87,7 @@ class AutoScalingReconcilerTest {
|
||||
reservation.setInstances(List.of(ec2Instance));
|
||||
when(ec2Service.runInstances(eq("us-east-1"), eq("ami-version-1"), eq("t3.micro"),
|
||||
eq(1), eq(1), eq(null), eq(List.of()), eq(null), eq(null),
|
||||
eq(List.of()), eq(null), eq(null))).thenReturn(reservation);
|
||||
eq(instanceTags), eq(null), eq(null))).thenReturn(reservation);
|
||||
|
||||
reconciler.reconcile(asg);
|
||||
|
||||
@@ -93,7 +97,7 @@ class AutoScalingReconcilerTest {
|
||||
assertEquals("1", asg.getInstances().getFirst().getLaunchTemplateVersion());
|
||||
verify(ec2Service).runInstances(eq("us-east-1"), eq("ami-version-1"), eq("t3.micro"),
|
||||
eq(1), eq(1), eq(null), eq(List.of()), eq(null), eq(null),
|
||||
eq(List.of()), eq(null), eq(null));
|
||||
eq(instanceTags), eq(null), eq(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -133,6 +137,61 @@ class AutoScalingReconcilerTest {
|
||||
assertEquals("7", asg.getInstances().getFirst().getLaunchTemplateVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
void scaleOutUsesMixedInstancesLaunchTemplateSpecification() {
|
||||
AutoScalingService asgService = mock(AutoScalingService.class);
|
||||
Ec2Service ec2Service = mock(Ec2Service.class);
|
||||
ElbV2Service elbV2Service = mock(ElbV2Service.class);
|
||||
AutoScalingReconciler reconciler = new AutoScalingReconciler(asgService, ec2Service, elbV2Service);
|
||||
AutoScalingGroup asg = new AutoScalingGroup();
|
||||
asg.setRegion("us-east-1");
|
||||
asg.setAutoScalingGroupName("app-asg");
|
||||
asg.setDesiredCapacity(1);
|
||||
MixedInstancesPolicy policy = new MixedInstancesPolicy();
|
||||
MixedInstancesPolicy.LaunchTemplate launchTemplatePolicy =
|
||||
new MixedInstancesPolicy.LaunchTemplate();
|
||||
MixedInstancesPolicy.LaunchTemplateSpecification specification =
|
||||
new MixedInstancesPolicy.LaunchTemplateSpecification();
|
||||
specification.setLaunchTemplateId("lt-123");
|
||||
specification.setVersion("3");
|
||||
launchTemplatePolicy.setLaunchTemplateSpecification(specification);
|
||||
MixedInstancesPolicy.LaunchTemplateOverride override =
|
||||
new MixedInstancesPolicy.LaunchTemplateOverride();
|
||||
override.setInstanceType("t3.small");
|
||||
launchTemplatePolicy.setOverrides(List.of(override));
|
||||
policy.setLaunchTemplate(launchTemplatePolicy);
|
||||
asg.setMixedInstancesPolicy(policy);
|
||||
|
||||
LaunchTemplate launchTemplate = new LaunchTemplate();
|
||||
launchTemplate.setLaunchTemplateId("lt-123");
|
||||
LaunchTemplate version = new LaunchTemplate();
|
||||
version.setLatestVersionNumber("3");
|
||||
version.setImageId("ami-version-3");
|
||||
version.setInstanceType("t3.micro");
|
||||
when(ec2Service.describeLaunchTemplates("us-east-1", List.of("lt-123"), List.of(), Map.of()))
|
||||
.thenReturn(List.of(launchTemplate));
|
||||
when(ec2Service.describeLaunchTemplateVersions("us-east-1", "lt-123", null, List.of("3")))
|
||||
.thenReturn(List.of(version));
|
||||
Instance ec2Instance = new Instance();
|
||||
ec2Instance.setInstanceId("i-launched");
|
||||
Reservation reservation = new Reservation();
|
||||
reservation.setInstances(List.of(ec2Instance));
|
||||
when(ec2Service.runInstances(eq("us-east-1"), eq("ami-version-3"), eq("t3.small"),
|
||||
eq(1), eq(1), eq(null), eq(List.of()), eq(null), eq(null),
|
||||
eq(List.of()), eq(null), eq(null))).thenReturn(reservation);
|
||||
|
||||
reconciler.reconcile(asg);
|
||||
|
||||
assertEquals(1, asg.getInstances().size());
|
||||
assertEquals("i-launched", asg.getInstances().getFirst().getInstanceId());
|
||||
assertEquals("lt-123", asg.getInstances().getFirst().getLaunchTemplateId());
|
||||
assertEquals("3", asg.getInstances().getFirst().getLaunchTemplateVersion());
|
||||
assertEquals("t3.small", asg.getInstances().getFirst().getInstanceType());
|
||||
verify(ec2Service).runInstances(eq("us-east-1"), eq("ami-version-3"), eq("t3.small"),
|
||||
eq(1), eq(1), eq(null), eq(List.of()), eq(null), eq(null),
|
||||
eq(List.of()), eq(null), eq(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void reconcileDeregistersTargetsThatAreNotActiveAsgInstances() {
|
||||
AutoScalingService asgService = mock(AutoScalingService.class);
|
||||
@@ -162,6 +221,77 @@ class AutoScalingReconcilerTest {
|
||||
verify(ec2Service, never()).terminateInstances(asg.getRegion(), List.of("i-active"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void reconcileKeepsPendingInstancesWhileContainerLaunchIsStillInFlight() {
|
||||
AutoScalingService asgService = mock(AutoScalingService.class);
|
||||
Ec2Service ec2Service = mock(Ec2Service.class);
|
||||
ElbV2Service elbV2Service = mock(ElbV2Service.class);
|
||||
AutoScalingReconciler reconciler = new AutoScalingReconciler(asgService, ec2Service, elbV2Service);
|
||||
AutoScalingGroup asg = new AutoScalingGroup();
|
||||
asg.setRegion("us-east-1");
|
||||
asg.setAutoScalingGroupName("app-asg");
|
||||
asg.setDesiredCapacity(1);
|
||||
asg.getInstances().add(instance("i-pending", "Pending"));
|
||||
|
||||
Instance ec2Instance = new Instance();
|
||||
ec2Instance.setInstanceId("i-pending");
|
||||
ec2Instance.setState(InstanceState.pending());
|
||||
Reservation reservation = new Reservation();
|
||||
reservation.setInstances(List.of(ec2Instance));
|
||||
when(ec2Service.describeInstances("us-east-1", List.of("i-pending"), null))
|
||||
.thenReturn(List.of(reservation));
|
||||
when(ec2Service.isInstanceContainerRunning("i-pending")).thenReturn(false);
|
||||
|
||||
reconciler.reconcile(asg);
|
||||
|
||||
assertEquals(1, asg.getInstances().size());
|
||||
assertEquals("i-pending", asg.getInstances().getFirst().getInstanceId());
|
||||
verify(ec2Service, never()).runInstances(
|
||||
eq("us-east-1"),
|
||||
org.mockito.ArgumentMatchers.any(),
|
||||
org.mockito.ArgumentMatchers.any(),
|
||||
org.mockito.ArgumentMatchers.anyInt(),
|
||||
org.mockito.ArgumentMatchers.anyInt(),
|
||||
org.mockito.ArgumentMatchers.any(),
|
||||
org.mockito.ArgumentMatchers.any(),
|
||||
org.mockito.ArgumentMatchers.any(),
|
||||
org.mockito.ArgumentMatchers.any(),
|
||||
org.mockito.ArgumentMatchers.any(),
|
||||
org.mockito.ArgumentMatchers.any(),
|
||||
org.mockito.ArgumentMatchers.any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void reconcilePrunesPendingInstancesWhenEc2InstanceIsTerminal() {
|
||||
AutoScalingService asgService = mock(AutoScalingService.class);
|
||||
Ec2Service ec2Service = mock(Ec2Service.class);
|
||||
ElbV2Service elbV2Service = mock(ElbV2Service.class);
|
||||
AutoScalingReconciler reconciler = new AutoScalingReconciler(asgService, ec2Service, elbV2Service);
|
||||
AutoScalingGroup asg = new AutoScalingGroup();
|
||||
asg.setRegion("us-east-1");
|
||||
asg.setAutoScalingGroupName("app-asg");
|
||||
asg.setDesiredCapacity(0);
|
||||
asg.getInstances().add(instance("i-dead", "Pending"));
|
||||
|
||||
Instance ec2Instance = new Instance();
|
||||
ec2Instance.setInstanceId("i-dead");
|
||||
ec2Instance.setState(InstanceState.terminated());
|
||||
Reservation reservation = new Reservation();
|
||||
reservation.setInstances(List.of(ec2Instance));
|
||||
when(ec2Service.describeInstances("us-east-1", List.of("i-dead"), null))
|
||||
.thenReturn(List.of(reservation));
|
||||
|
||||
reconciler.reconcile(asg);
|
||||
|
||||
assertEquals(0, asg.getInstances().size());
|
||||
verify(asgService).recordActivity(
|
||||
eq("us-east-1"),
|
||||
eq("app-asg"),
|
||||
eq("Removing stale EC2 instance reference(s): [i-dead]"),
|
||||
eq("Persisted Auto Scaling state referenced instance containers that are no longer running."),
|
||||
eq("Successful"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void reconcilePromotesPendingAsgInstanceWhenEc2InstanceIsRunning() {
|
||||
AutoScalingService asgService = mock(AutoScalingService.class);
|
||||
|
||||
+1
@@ -30,6 +30,7 @@ class AutoScalingServiceTest {
|
||||
"lt-original",
|
||||
null,
|
||||
"1",
|
||||
null,
|
||||
0,
|
||||
3,
|
||||
1,
|
||||
|
||||
Reference in new issue
Block a user