Skip to content

Commit

Permalink
To test more, but elbv2 with obj vs array working
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnPreston committed Mar 5, 2024
1 parent b4aec49 commit c0b302c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 25 deletions.
7 changes: 3 additions & 4 deletions ecs_composex/compose/x_resources/services_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(
settings: ComposeXSettings,
):
self.services = []
self.families_targets: list = []
self.families_targets: list[tuple] = []
self.families_scaling = []
self.arn_parameter = None
super().__init__(name, definition, module, settings)
Expand Down Expand Up @@ -148,7 +148,7 @@ def set_services_targets(self, settings: ComposeXSettings) -> None:
if not isinstance(self.services, dict):
raise TypeError(
"Services as list have been deprecated since version 1.0"
"You can use the upgrade_scripts to patch your existing compose files.e"
"You can use the upgrade_scripts to patch your existing compose files."
)
self.set_services_targets_from_dict(settings)
self.debug_families_targets()
Expand Down Expand Up @@ -211,9 +211,8 @@ def set_services_scaling(self, settings: ComposeXSettings):
LOG.debug(f"{self.module.res_key}.{self.name} No Services defined.")
return
if not isinstance(self.services, dict):
TypeError(
raise TypeError(
"Services scaling must be in a mapping/dict format."
"List format has been deprecated since 1.0"
)
return
self.set_services_targets_scaling_from_dict(settings)
16 changes: 8 additions & 8 deletions ecs_composex/elbv2/elbv2_ecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,21 +605,21 @@ def handle_services_association(
add_outputs(template, load_balancer.outputs)
identified = []
for target in load_balancer.families_targets:
family: ComposeFamily = target[0]
print("TARGET?", target)
if target[1].launch_type == "EXTERNAL":
LOG.error(
f"x-elbv2.{load_balancer.name} - Target family {target[0].name} uses EXTERNAL launch type. Ignoring"
f"x-elbv2.{load_balancer.name} - Target family {family.name} uses EXTERNAL launch type. Ignoring"
)
continue
tgt_group = define_service_target_group_definition(
load_balancer, target[0], target[1], target[2], res_root_stack
load_balancer, family, target[1], target[2], res_root_stack
)
for service in load_balancer.services:
target_name = f"{target[0].name}:{target[1].name}"
if target_name not in service["name"]:
for service_name, service in load_balancer.services.items():
target_name = f"{family.name}:{target[1].name}"
if target_name not in service_name:
continue
if target_name == service["name"] and tgt_group.Port == int(
service["port"]
):
if target_name == service_name and tgt_group.Port == int(service["port"]):
service["target_arn"] = Ref(tgt_group)
identified.append(True)
break
Expand Down
9 changes: 4 additions & 5 deletions ecs_composex/elbv2/elbv2_stack/elbv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def set_listeners(self, template):
)
if (
f"{target_parts.group('family')}:{target_parts.group('container')}"
not in [svc["name"] for svc in self.services]
not in self.services
):
listener_def["Targets"].remove(target)
if keyisset("Targets", listener_def) or keyisset(
Expand Down Expand Up @@ -191,8 +191,7 @@ def set_services_targets(self, settings):
if not self.services:
LOG.debug(f"{self.module.res_key}.{self.name} No Services defined.")
return
for service_def in self.services:
family_combo_name = service_def["name"]
for family_combo_name, service_def in self.services.items():
service_name = family_combo_name.split(":")[-1]
family_name = NONALPHANUM.sub("", family_combo_name.split(":")[0])
LOG.info(
Expand Down Expand Up @@ -223,7 +222,7 @@ def set_services_targets(self, settings):
f_service.family,
f_service,
service_def,
f"{service_def['name']}{service_def['port']}",
f"{family_combo_name}{service_def['port']}",
)
)
break
Expand All @@ -235,7 +234,7 @@ def set_services_targets(self, settings):
self.debug_families_targets()

def validate_services(self):
services_names = list({service["name"] for service in self.services})
services_names = list(self.services.keys())
if len(services_names) == 1:
LOG.info(
f"LB {self.name} only has a unique service. LB will be deployed with the service stack."
Expand Down
2 changes: 1 addition & 1 deletion ecs_composex/elbv2/elbv2_stack/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ def map_service_target(lb, listener_service_def: dict) -> None:


def validate_duplicate_targets(lb: Elbv2, listener: ComposeListener) -> None:
t_targets = [s["name"] for s in lb.services]
t_targets = list(lb.services.keys())
duplicate_services: bool = len(t_targets) != len(set(t_targets))
if duplicate_services:
for listener_target in listener.services:
Expand Down
14 changes: 7 additions & 7 deletions ecs_composex/elbv2/x-elbv2.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,13 @@
}
},
"Services": {
"type": "array",
"items": {
"$ref": "#/definitions/TargetDef"
"type": "object",
"additionalProperties": false,
"patternProperties": {
"x-": {},
"^[a-zA-Z0-9\\:_\\-]+$": {
"$ref": "#/definitions/TargetDef"
}
}
},
"TargetGroups": {
Expand Down Expand Up @@ -263,15 +267,11 @@
"type": "object",
"additionalProperties": false,
"required": [
"name",
"protocol",
"port",
"healthcheck"
],
"properties": {
"name": {
"type": "string"
},
"protocol": {
"$ref": "#/definitions/Protocol"
},
Expand Down

0 comments on commit c0b302c

Please sign in to comment.