Skip to content

Commit ab76049

Browse files
committed
restricts nonzero items
1 parent 2a9de4c commit ab76049

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

services/autoscaling/src/simcore_service_autoscaling/modules/auto_scaling_core.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import functools
66
import itertools
77
import logging
8-
import typing
98
from typing import Final, cast
109

1110
import arrow
@@ -338,29 +337,22 @@ async def _sorted_allowed_instance_types(app: FastAPI) -> list[EC2InstanceType]:
338337
allowed_instance_type_names = list(
339338
app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_ALLOWED_TYPES
340339
)
341-
assert set(allowed_instance_type_names).issubset(
342-
typing.get_args(InstanceTypeType)
343-
) # nosec
340+
341+
assert (
342+
allowed_instance_type_names
343+
), "EC2_INSTANCES_ALLOWED_TYPES cannot be empty!" # nosec
344344

345345
allowed_instance_types: list[
346346
EC2InstanceType
347347
] = await ec2_client.get_ec2_instance_capabilities(
348348
cast(set[InstanceTypeType], set(allowed_instance_type_names))
349349
)
350350

351-
if allowed_instance_type_names:
352-
353-
def _as_selection(instance_type: EC2InstanceType) -> int:
354-
return allowed_instance_type_names.index(f"{instance_type.name}")
351+
def _as_selection(instance_type: EC2InstanceType) -> int:
352+
# NOTE: will raise ValueError if allowed_instance_types not in allowed_instance_type_names
353+
return allowed_instance_type_names.index(f"{instance_type.name}")
355354

356-
allowed_instance_types.sort(key=_as_selection)
357-
else:
358-
# NOTE An empty set to get_ec2_instance_capabilities it will return ALL of the instances
359-
_logger.warning(
360-
"All %s instances are allowed since EC2_INSTANCES_ALLOWED_TYPES is set to empty (=%s)",
361-
len(allowed_instance_types),
362-
allowed_instance_type_names,
363-
)
355+
allowed_instance_types.sort(key=_as_selection)
364356
return allowed_instance_types
365357

366358

0 commit comments

Comments
 (0)