Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CPU & memory to ContainerInstance #400

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions fbpcp/entity/container_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ class ContainerInstance:
instance_id: str
ip_address: Optional[str] = None
status: ContainerInstanceStatus = ContainerInstanceStatus.UNKNOWN
cpu: Optional[int] = None # Number of vCPU
memory: Optional[int] = None # Memory in GB
16 changes: 14 additions & 2 deletions fbpcp/mapper/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,20 @@ def map_ecstask_to_containerinstance(task: Dict[str, Any]) -> ContainerInstance:
status = ContainerInstanceStatus.FAILED
else:
status = ContainerInstanceStatus.UNKNOWN

return ContainerInstance(task["taskArn"], ip_v4, status)
task_overrides = None
if (
"overrides" in task
and "cpu" in task["overrides"]
and "memory" in task["overrides"]
):
task_overrides = task["overrides"]
elif "cpu" in task and "memory" in task:
task_overrides = task
vcpu = map_unit_to_vcpu(int(task_overrides["cpu"])) if task_overrides else None
memory_in_gb = (
map_mb_to_gb(int(task_overrides["memory"])) if task_overrides else None
)
return ContainerInstance(task["taskArn"], ip_v4, status, vcpu, memory_in_gb)


def map_esccluster_to_clusterinstance(cluster: Dict[str, Any]) -> Cluster:
Expand Down
2 changes: 2 additions & 0 deletions tests/gateway/test_ecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def test_run_task(self) -> None:
self.TEST_TASK_ARN,
self.TEST_IP_ADDRESS,
ContainerInstanceStatus.STARTED,
self.TEST_CPU,
self.TEST_MEMORY,
)
# Act
task = self.gw.run_task(
Expand Down
4 changes: 4 additions & 0 deletions tests/mapper/test_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,15 @@ def test_map_ecstask_to_containerinstance(self):
self.TEST_TASK_ARN,
None,
ContainerInstanceStatus.COMPLETED,
self.TEST_CPU,
self.TEST_MEMORY,
),
ContainerInstance(
self.TEST_TASK_ARN,
None,
ContainerInstanceStatus.FAILED,
self.TEST_CPU,
self.TEST_MEMORY,
),
ContainerInstance(
self.TEST_TASK_ARN,
Expand Down