diff --git a/group_vars/all/18_swarm.yml b/group_vars/all/18_swarm.yml index c20522d2fe..a473bb9e00 100644 --- a/group_vars/all/18_swarm.yml +++ b/group_vars/all/18_swarm.yml @@ -3,6 +3,11 @@ DEPLOYMENT_MODE: "{{ 'swarm' if (groups['svc-swarm-node'] | default([]) | length SWARM_CLUSTER_AVAILABLE: "{{ (groups['svc-swarm-node'] | default([]) | length) > 0 }}" +# Exception: a role default would be invisible to the by-path include in +# roles/svc-db-openldap/tasks/01_docker.yml, which reaches into +# roles/sys-svc-compose/tasks/utils/post_deploy.yml after the role has finished. +swarm_stack_converge_retries: 600 + IS_STACK_HOST: >- {{ DEPLOYMENT_MODE == 'compose' or inventory_hostname in (groups['svc-swarm-manager'] | default([])) }} diff --git a/roles/sys-svc-compose/handlers/swarm.yml b/roles/sys-svc-compose/handlers/swarm.yml index 44139da68f..30b14b2cd8 100644 --- a/roles/sys-svc-compose/handlers/swarm.yml +++ b/roles/sys-svc-compose/handlers/swarm.yml @@ -168,7 +168,7 @@ environment: STACK: "{{ application_id | get_entity_name }}" register: _swarm_stack_ready_handler - retries: "{{ swarm_stack_converge_retries | default(150) }}" + retries: "{{ swarm_stack_converge_retries }}" delay: 2 changed_when: false until: _swarm_stack_ready_handler is succeeded diff --git a/roles/sys-svc-compose/tasks/utils/post_deploy.yml b/roles/sys-svc-compose/tasks/utils/post_deploy.yml index e61991488f..8a5fc7ce0e 100644 --- a/roles/sys-svc-compose/tasks/utils/post_deploy.yml +++ b/roles/sys-svc-compose/tasks/utils/post_deploy.yml @@ -18,7 +18,7 @@ environment: STACK: "{{ application_id | get_entity_name }}" register: _swarm_tasks_ready - retries: 150 + retries: "{{ swarm_stack_converge_retries }}" delay: 2 changed_when: false until: _swarm_tasks_ready is succeeded diff --git a/tests/lint/repository/test_compose_build_retry_budget.py b/tests/lint/repository/test_compose_build_retry_budget.py index 60f8328a3b..897d59c11b 100644 --- a/tests/lint/repository/test_compose_build_retry_budget.py +++ b/tests/lint/repository/test_compose_build_retry_budget.py @@ -34,6 +34,9 @@ BUILDS = { } TIMEOUT_LOOKUP = re.compile(r"lookup\('timeout',\s*(\d+)\s*\)") +ROLE = PROJECT_ROOT / "roles" / "sys-svc-compose" +GATE = "swarm/stack_ready.sh" + def _tasks(path): return load_yaml_any(str(path), default_if_missing=[]) or [] @@ -94,6 +97,28 @@ class TestComposeBuildRetryBudget(unittest.TestCase): self.assertLess(worst, budget, f"{name} outgrows the sweep budget") self.assertLess(worst, cap, f"{name} outgrows the deploy step cap") + def test_every_convergence_gate_waits_the_same_budget(self) -> None: + """Both callers poll the same script for the same stack, so a budget that + fits one fits the other. They drifted once -- the handler was raised to + 600 while post_deploy kept a hardcoded 150 -- and the shorter one then + killed a healthy-but-slow stack on its own.""" + budgets = {} + for path in sorted(ROLE.rglob("*.yml")): + for task in _tasks(path): + if not isinstance(task, dict): + continue + if GATE in str(task.get("ansible.builtin.script", "")): + budgets[f"{path.relative_to(PROJECT_ROOT)}:{task.get('name')}"] = ( + str(task.get("retries")), + str(task.get("delay")), + ) + self.assertGreaterEqual(len(budgets), 2, f"gate callers not found: {budgets}") + self.assertEqual( + len(set(budgets.values())), + 1, + f"convergence gate callers disagree on their budget: {budgets}", + ) + def test_the_registry_exclusion_has_a_single_source(self) -> None: self.assertEqual(read_text(str(SWARM)).count("svc-registry-docker"), 1)