Skip to content

Commit

Permalink
Add CPU & memory to ContainerInstance
Browse files Browse the repository at this point in the history
Summary:
## Context
We want to enable customized containers in our infra ([design doc](https://docs.google.com/document/d/1UqaK6VXEoIVUHSJnYs_Ydju8)). Therefore we need to add cpu & memory specs to ContainerInstance;
## This commit
- Add CPU & Memory to ContainerInstance
- Parse them in map_ecstask_to_containerinstance
## How this effect ```pcs_container_instance.py```?
Since ```PCSContainerInstance``` inherits ```ContainerInstance```, we change it to use keyword argument for ```log_url``` to prevent breaks;

Differential Revision: D38553232

fbshipit-source-id: 32f83534c6185409209ace601b9f3a7a61c21938
  • Loading branch information
ziqih authored and facebook-github-bot committed Aug 9, 2022
1 parent 881bd9b commit 0255cf9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
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

0 comments on commit 0255cf9

Please sign in to comment.