Skip to content

Commit

Permalink
[Improvement] fargate/* - Support spot capacity (widdix#540)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwittig authored Mar 26, 2021
1 parent 89a29a3 commit 6e6b438
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
12 changes: 11 additions & 1 deletion fargate/service-cloudmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Metadata:
- Memory
- SubnetsReach
- AutoScaling
- Spot
- DesiredCount
- MaxCapacity
- MinCapacity
Expand Down Expand Up @@ -279,6 +280,11 @@ Parameters:
Type: String
Default: 'true'
AllowedValues: ['true', 'false']
Spot:
Description: 'Run workload on spot capacity?'
Type: String
Default: false
AllowedValues: [true, false]
Mappings:
CpuMap:
'0.25':
Expand Down Expand Up @@ -378,6 +384,7 @@ Conditions:
HasSidecarEnvironment1Key: !Not [!Equals [!Ref SidecarEnvironment1Key, '']]
HasSidecarEnvironment2Key: !Not [!Equals [!Ref SidecarEnvironment2Key, '']]
HasSidecarEnvironment3Key: !Not [!Equals [!Ref SidecarEnvironment3Key, '']]
HasSpot: !Equals [!Ref Spot, 'true']
Resources:
ServiceDiscovery:
Type: 'AWS::ServiceDiscovery::Service'
Expand Down Expand Up @@ -526,12 +533,15 @@ Resources:
Service:
Type: 'AWS::ECS::Service'
Properties:
CapacityProviderStrategy:
- Base: 0
CapacityProvider: !If [HasSpot, FARGATE_SPOT, FARGATE]
Weight: 1
Cluster: {'Fn::ImportValue': !Sub '${ParentClusterStack}-Cluster'}
DeploymentConfiguration:
MaximumPercent: 200
MinimumHealthyPercent: 100
DesiredCount: !Ref DesiredCount
LaunchType: FARGATE
ServiceRegistries:
- ContainerName: !If [HasProxyImage, proxy, app]
ContainerPort: !If [HasProxyImage, !Ref ProxyPort, !Ref AppPort]
Expand Down
12 changes: 11 additions & 1 deletion fargate/service-cluster-alb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Metadata:
- Memory
- SubnetsReach
- AutoScaling
- Spot
- DesiredCount
- MaxCapacity
- MinCapacity
Expand Down Expand Up @@ -320,6 +321,11 @@ Parameters:
Default: 60
MinValue: 0
MaxValue: 1800
Spot:
Description: 'Run workload on spot capacity?'
Type: String
Default: false
AllowedValues: [true, false]
Mappings:
CpuMap:
'0.25':
Expand Down Expand Up @@ -422,6 +428,7 @@ Conditions:
HasSidecarEnvironment1Key: !Not [!Equals [!Ref SidecarEnvironment1Key, '']]
HasSidecarEnvironment2Key: !Not [!Equals [!Ref SidecarEnvironment2Key, '']]
HasSidecarEnvironment3Key: !Not [!Equals [!Ref SidecarEnvironment3Key, '']]
HasSpot: !Equals [!Ref Spot, 'true']
Resources:
RecordSet:
Condition: HasZone
Expand Down Expand Up @@ -657,13 +664,16 @@ Resources:
DependsOn: LoadBalancerListenerRule
Type: 'AWS::ECS::Service'
Properties:
CapacityProviderStrategy:
- Base: 0
CapacityProvider: !If [HasSpot, FARGATE_SPOT, FARGATE]
Weight: 1
Cluster: {'Fn::ImportValue': !Sub '${ParentClusterStack}-Cluster'}
DeploymentConfiguration:
MaximumPercent: 200
MinimumHealthyPercent: 100
DesiredCount: !Ref DesiredCount
HealthCheckGracePeriodSeconds: !Ref HealthCheckGracePeriod
LaunchType: FARGATE
LoadBalancers:
- ContainerName: !If [HasProxyImage, proxy, app]
ContainerPort: !If [HasProxyImage, !Ref ProxyPort, !Ref AppPort]
Expand Down
12 changes: 11 additions & 1 deletion fargate/service-dedicated-alb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Metadata:
- Memory
- SubnetsReach
- AutoScaling
- Spot
- DesiredCount
- MaxCapacity
- MinCapacity
Expand Down Expand Up @@ -325,6 +326,11 @@ Parameters:
Default: 60
MinValue: 0
MaxValue: 1800
Spot:
Description: 'Run workload on spot capacity?'
Type: String
Default: false
AllowedValues: [true, false]
Mappings:
CpuMap:
'0.25':
Expand Down Expand Up @@ -434,6 +440,7 @@ Conditions:
HasSidecarEnvironment2Key: !Not [!Equals [!Ref SidecarEnvironment2Key, '']]
HasSidecarEnvironment3Key: !Not [!Equals [!Ref SidecarEnvironment3Key, '']]
HasWAF: !Not [!Equals [!Ref ParentWAFStack, '']]
HasSpot: !Equals [!Ref Spot, 'true']
Resources:
RecordSet:
Condition: HasZone
Expand Down Expand Up @@ -793,13 +800,16 @@ Resources:
Type: 'AWS::ECS::Service'
DependsOn: HttpListener
Properties:
CapacityProviderStrategy:
- Base: 0
CapacityProvider: !If [HasSpot, FARGATE_SPOT, FARGATE]
Weight: 1
Cluster: {'Fn::ImportValue': !Sub '${ParentClusterStack}-Cluster'}
DeploymentConfiguration:
MaximumPercent: 200
MinimumHealthyPercent: 100
DesiredCount: !Ref DesiredCount
HealthCheckGracePeriodSeconds: !Ref HealthCheckGracePeriod
LaunchType: FARGATE
LoadBalancers:
- ContainerName: !If [HasProxyImage, proxy, app]
ContainerPort: !If [HasProxyImage, !Ref ProxyPort, !Ref AppPort]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ public void testClusterAlbPathPattern() {
"fargate/service-cluster-alb.yaml",
new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName),
new Parameter().withParameterKey("ParentClusterStack").withParameterValue(clusterStackName),
new Parameter().withParameterKey("AppImage").withParameterValue("nginx:1.11.5")
new Parameter().withParameterKey("AppImage").withParameterValue("nginx:1.11.5"),
new Parameter().withParameterKey("Spot").withParameterValue("true")
);
final Callable<String> callable = () -> {
final HttpResponse response = WS.url(url).timeout(10000).get();
Expand Down Expand Up @@ -212,7 +213,8 @@ public void testWaf() {
new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName),
new Parameter().withParameterKey("ParentClusterStack").withParameterValue(clusterStackName),
new Parameter().withParameterKey("ParentWAFStack").withParameterValue(wafStackName),
new Parameter().withParameterKey("AppImage").withParameterValue("nginx:1.11.5")
new Parameter().withParameterKey("AppImage").withParameterValue("nginx:1.11.5"),
new Parameter().withParameterKey("Spot").withParameterValue("true")
);
final String url = this.getStackOutputValue(stackName, "URL");
final Callable<String> callable = () -> {
Expand Down Expand Up @@ -327,7 +329,6 @@ public void testCloudMap() throws JSchException {
} finally {
this.deleteKey(context, keyName);
}

}

}

0 comments on commit 6e6b438

Please sign in to comment.