-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate scheduling strategy for Fargate services
- Loading branch information
Showing
6 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
28 changes: 28 additions & 0 deletions
28
src/cfnlint/rules/resources/ecs/FargateDeploymentSchedulingStrategy.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
""" | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: MIT-0 | ||
""" | ||
from cfnlint.rules import CloudFormationLintRule, RuleMatch | ||
|
||
|
||
class FargateDeploymentSchedulingStrategy(CloudFormationLintRule): | ||
id = "E3044" | ||
shortdesc = "Check Fargate service scheduling strategy" | ||
description = "Check that Fargate service scheduling strategy is REPLICA" | ||
source_url = "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-service.html#cfn-ecs-service-schedulingstrategy" | ||
tags = ["properties", "ecs", "service", "container", "fargate"] | ||
|
||
def match(self, cfn): | ||
matches = [] | ||
ecs_services = cfn.get_resource_properties(["AWS::ECS::Service"]) | ||
|
||
for ecs_service in ecs_services: | ||
path = ecs_service["Path"] | ||
properties = ecs_service["Value"] | ||
if isinstance(properties, dict): | ||
if properties.get("LaunchType", None) != "Fargate": | ||
continue | ||
if properties.get("SchedulingStrategy", None) != "REPLICA": | ||
error_message = f"Fargate service only support REPLICA as scheduling strategy at {'/'.join(map(str, path))}" | ||
matches.append(RuleMatch(path, error_message)) | ||
return matches |
This file contains 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
6 changes: 6 additions & 0 deletions
6
test/fixtures/templates/bad/resources/ecs/test_fargate_scheduling_strategy.yaml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Resources: | ||
Service1: | ||
Type: AWS::ECS::Service | ||
Properties: | ||
LaunchType: Fargate | ||
SchedulingStrategy: DAEMON |
16 changes: 16 additions & 0 deletions
16
test/fixtures/templates/good/resources/ecs/test_fargate_scheduling_strategy.yaml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Resources: | ||
Service1: | ||
Type: AWS::ECS::Service, | ||
Properties: | ||
LaunchType: Fargate, | ||
SchedulingStrategy: REPLICA | ||
Service2: | ||
Type: AWS::ECS::Service | ||
Properties: | ||
LaunchType: EC2 | ||
SchedulingStrategy: DAEMON | ||
Service3: | ||
Type: AWS::ECS::Service | ||
Properties: | ||
LaunchType: EXTERNAL | ||
SchedulingStrategy: DAEMON |
31 changes: 31 additions & 0 deletions
31
test/unit/rules/resources/ecs/test_fargate_service_scheduling_strategy.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: MIT-0 | ||
""" | ||
from test.unit.rules import BaseRuleTestCase | ||
|
||
from cfnlint.rules.resources.ecs.FargateDeploymentSchedulingStrategy import ( | ||
FargateDeploymentSchedulingStrategy, | ||
) | ||
|
||
|
||
class TestFargateServiceSchedulingStrategy(BaseRuleTestCase): | ||
""" | ||
Test that Fargate service has correct scheduling strategy (REPLICA) | ||
""" | ||
|
||
def setUp(self): | ||
super(TestFargateServiceSchedulingStrategy, self).setUp() | ||
self.collection.register(FargateDeploymentSchedulingStrategy()) | ||
self.success_templates = [ | ||
"test/fixtures/templates/good/resources/ecs/test_fargate_scheduling_strategy.yaml" | ||
] | ||
|
||
def test_file_positive(self): | ||
self.helper_file_positive() | ||
|
||
def test_file_negative(self): | ||
self.helper_file_negative( | ||
"test/fixtures/templates/bad/resources/ecs/test_fargate_scheduling_strategy.yaml", | ||
1, | ||
) |