This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Support for capacity provider #407
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
213633d
checks for capacity provider
jeanluciano ef36941
Merge branch 'main' into improvement/add-capacity-provider
zzstoatzz a6d37d9
logs warning when removing launch type
jeanluciano bf18abe
Merge branch 'improvement/add-capacity-provider' of https://github.co…
jeanluciano 0bea3e7
passes ecs test
jeanluciano c1042d3
Revert "passes ecs test"
jeanluciano daa9a24
added capacity_provider_strategy to ecs variables
jeanluciano bbdae80
changed field formatting
jeanluciano 9107e27
sets fargate spot capacity provider
jeanluciano cfe0fd5
Merge branch 'main' into improvement/add-capacity-provider
jeanluciano 883a64c
Merge branch 'main' into improvement/add-capacity-provider
jeanluciano 4b912cd
description formatting
jeanluciano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,9 +70,9 @@ | |
from pydantic import VERSION as PYDANTIC_VERSION | ||
|
||
if PYDANTIC_VERSION.startswith("2."): | ||
from pydantic.v1 import Field, root_validator | ||
from pydantic.v1 import BaseModel, Field, root_validator | ||
else: | ||
from pydantic import Field, root_validator | ||
from pydantic import Field, root_validator, BaseModel | ||
|
||
from slugify import slugify | ||
from tenacity import retry, stop_after_attempt, wait_fixed, wait_random | ||
|
@@ -126,6 +126,7 @@ | |
taskRoleArn: "{{ task_role_arn }}" | ||
tags: "{{ labels }}" | ||
taskDefinition: "{{ task_definition_arn }}" | ||
capacityProviderStrategy: "{{ capacity_provider_strategy }}" | ||
""" | ||
|
||
# Create task run retry settings | ||
|
@@ -245,6 +246,16 @@ def mask_api_key(task_run_request): | |
) | ||
|
||
|
||
class CapacityProvider(BaseModel): | ||
""" | ||
The capacity provider strategy to use when running the task. | ||
""" | ||
|
||
capacityProvider: str | ||
weight: int | ||
base: int | ||
|
||
|
||
class ECSJobConfiguration(BaseJobConfiguration): | ||
""" | ||
Job configuration for an ECS worker. | ||
|
@@ -267,6 +278,7 @@ class ECSJobConfiguration(BaseJobConfiguration): | |
auto_deregister_task_definition: bool = Field(default=False) | ||
vpc_id: Optional[str] = Field(default=None) | ||
container_name: Optional[str] = Field(default=None) | ||
|
||
cluster: Optional[str] = Field(default=None) | ||
match_latest_revision_in_family: bool = Field(default=False) | ||
|
||
|
@@ -425,6 +437,13 @@ class ECSVariables(BaseVariables): | |
), | ||
) | ||
) | ||
capacity_provider_strategy: Optional[List[CapacityProvider]] = Field( | ||
default_factory=list, | ||
description=( | ||
"The capacity provider strategy to use when running the task. This is only" | ||
"If a capacityProviderStrategy is specified, we will omit the launchType" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
), | ||
) | ||
image: Optional[str] = Field( | ||
default=None, | ||
description=( | ||
|
@@ -1449,17 +1468,24 @@ def _prepare_task_run_request( | |
|
||
task_run_request.setdefault("taskDefinition", task_definition_arn) | ||
assert task_run_request["taskDefinition"] == task_definition_arn | ||
capacityProviderStrategy = task_run_request.get("capacityProviderStrategy") | ||
|
||
if capacityProviderStrategy: | ||
# Should not be provided at all if capacityProviderStrategy is set, see https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_RunTask.html#ECS-RunTask-request-capacityProviderStrategy # noqa | ||
self._logger.warning( | ||
"Removing launchType from task run request. Due to finding" | ||
" capacityProviderStrategy in the request." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
) | ||
task_run_request.pop("launchType", None) | ||
|
||
if task_run_request.get("launchType") == "FARGATE_SPOT": | ||
elif task_run_request.get("launchType") == "FARGATE_SPOT": | ||
# Should not be provided at all for FARGATE SPOT | ||
task_run_request.pop("launchType", None) | ||
|
||
# A capacity provider strategy is required for FARGATE SPOT | ||
task_run_request.setdefault( | ||
"capacityProviderStrategy", | ||
[{"capacityProvider": "FARGATE_SPOT", "weight": 1}], | ||
) | ||
|
||
task_run_request["capacityProviderStrategy"] = [ | ||
{"capacityProvider": "FARGATE_SPOT", "weight": 1} | ||
] | ||
overrides = task_run_request.get("overrides", {}) | ||
container_overrides = overrides.get("containerOverrides", []) | ||
|
||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this line