Skip to content
Merged
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
6 changes: 5 additions & 1 deletion docs/_claims/docs/self-hosting/cdk.md.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,11 @@ text = "In a script, add --force, which deletes without asking."
by = ["exempt:instruction"]

[[unit]]
text = "If deleting a stack fails with a target group \"in use by a listener\" (#1618), run the teardown again."
text = "One cdk destroy run deletes the Fargate stack whatever target group is live: every listener rule and the test listener depend on both target groups (#1618)."
by = ["test:infrastructure/tests/test_listeners_depend_on_both_target_groups.py::test_every_listener_rule_and_the_test_listener_depend_on_both_groups"]

[[unit]]
text = "A stack last deployed before that change still has the old order, and its deletion can fail with a target group \"in use by a listener\"; run the teardown again."
by = ["exempt:instruction"]

[[unit]]
Expand Down
9 changes: 6 additions & 3 deletions docs/self-hosting/cdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -742,9 +742,12 @@ The glue, analytics and counters stacks exist only in a full deployment; skip
their lines in a core one, a full checkout deployed with the core profile
included.

If deleting a stack fails with a target group "in use by a listener"
([#1618](https://github.com/Controlvar/controlvar/issues/1618)), run the
teardown again. The installer's message says "run uninstall again; it continues
One `cdk destroy` run deletes the Fargate stack whatever target group is live:
every listener rule and the test listener depend on both target groups
([#1618](https://github.com/Controlvar/controlvar/issues/1618)). A stack last
deployed before that change still has the old order, and its deletion can fail
with a target group "in use by a listener"; run the teardown again. The
installer's message says "run uninstall again; it continues
where it stopped", and a second run completes.

The buckets outside `prod` are emptied before they are deleted:
Expand Down
10 changes: 10 additions & 0 deletions infrastructure/cdk/stacks/fargate_service_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,13 @@ def __init__(
conditions=[elbv2.ListenerCondition.path_patterns(list(paths))],
target_groups=[live_target_groups[live]],
)
# #1618: CodeDeploy swaps which target group a listener points at,
# so on destroy either one may still be in use. Delete the rule
# before BOTH groups. `{id}Rule` is the construct add_target_groups
# creates.
rule = self.https_listener.node.find_child(f"ApiPaths{priority}Rule")
rule.node.add_dependency(self.blue_target_group)
rule.node.add_dependency(self.green_target_group)

# --- Test Listener (port 8443) ---
# CodeDeploy uses this listener to route traffic to the green (new)
Expand All @@ -677,6 +684,9 @@ def __init__(
"TestListener",
**test_listener_kwargs,
)
# #1618: as for the rules above, the listener goes before both groups.
self.test_listener.node.add_dependency(self.blue_target_group)
self.test_listener.node.add_dependency(self.green_target_group)

# Imported immutably, and this is the whole fix for the dependency
# cycle. Passing the ComputeStack's SecurityGroup *object* to the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Deleting the Fargate stack works in one run (#1618).

CodeDeploy swaps which of the blue and green target groups the live listener
rules point at, outside CloudFormation. CloudFormation deletes in reverse
dependency order, and a rule depended on only the group the template names,
so on a stack left on the other colour it could delete that group first and
fail with "in use by a listener". Every listener rule and the test listener
therefore depend on BOTH groups. Asserted on a real ``app.synth()``.
"""

from __future__ import annotations

import pytest

from .test_dashboard_service import _by_type, _fargate, _one_id, _synth

LB = "AWS::ElasticLoadBalancingV2::"


@pytest.mark.regression
@pytest.mark.parametrize("live", ["blue", "green"])
def test_every_listener_rule_and_the_test_listener_depend_on_both_groups(live):
resources = _fargate(_synth("dev", {"api_live_target_group": live}))
both = {
_one_id(resources, "BlueTargetGroup", LB + "TargetGroup"),
_one_id(resources, "GreenTargetGroup", LB + "TargetGroup"),
}
rules = _by_type(resources, LB + "ListenerRule")
assert rules, "no listener rules were synthesised"
test_listener = _one_id(resources, "BackendALBTestListener", LB + "Listener")
subjects = {**rules, test_listener: resources[test_listener]}
for logical_id, resource in subjects.items():
depends_on = resource.get("DependsOn", [])
if isinstance(depends_on, str):
depends_on = [depends_on]
assert both <= set(depends_on), (
f"{logical_id} (live={live}) depends on {sorted(depends_on)}, "
f"not on both target groups {sorted(both)}"
)
Loading