mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 19:01:54 +00:00
round_variants was built by walking round_include. When a primary's variant switches its couplings off the planner resolves no prerequisites, round_include collapses to the primary, and no dependency gets an index at all. derive_includes then evaluates them at base config, where an unrendered Jinja coupling counts as enabled, so the closure inflates to everything reachable instead of what the variant declares. Measured: svc-ai-litellm round 1 deploys 10 apps instead of 32, web-app-bigbluebutton round 1 and web-app-peertube round 1 drop from 34 to 10 and 11. Every other round of every role measured is unchanged, including all fourteen nextcloud rounds. The apps that leave are not dependencies of the round: svc-ai-litellm declares litellm, lmstudio, ollama and postgres and no sso at all, while bigbluebutton and peertube declare sso but switch it off in variant 1 together with dashboard, matomo, css, logout and prometheus. complexity/cli.py:300 already documents the rule this makes true: the planner hands each pulled-in dependency round_index if round_index is below its variant count else 0, and pulls_at_zero implements exactly that. The coverage model was describing behaviour the planner only delivered for apps inside the include. init.py filters the printed variant map to the apps actually shown, because round_variants now carries 266 entries and round 1 would otherwise print 112 of them on one line while ten apps deploy. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
116 lines
4.3 KiB
Python
116 lines
4.3 KiB
Python
"""Matrix-deploy planner.
|
|
|
|
Pure function — reads role metadata via cached YAML helpers and emits
|
|
``PlanEntry`` tuples; no filesystem side effects. The include set per
|
|
round is resolved by the ``CombinedResolver`` (see ``.legacy_resolver``):
|
|
each role contributes its own pulled-in providers and the include is
|
|
the union. A service-key is therefore pulled in as soon as ANY role in
|
|
the round-aware closure says it should be (literal ``True`` OR the
|
|
``"{{ '<role>' in group_names }}"`` Jinja form, both accepted by
|
|
``utils.roles.applications.services.registry.is_explicit_truth``); if
|
|
EVERY role marks it ``False`` it stays out of the include.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from utils.cache.applications import get_variants
|
|
|
|
from . import legacy_resolver
|
|
|
|
if TYPE_CHECKING:
|
|
from collections.abc import Sequence
|
|
|
|
from .spec import PlanEntry
|
|
|
|
|
|
def filter_plan_to_variants(
|
|
plan: list[PlanEntry],
|
|
variants: list[int] | None,
|
|
) -> list[PlanEntry]:
|
|
"""Pin a matrix plan to a subset of rounds when `variants` is set.
|
|
|
|
`variants=None` returns the plan unchanged (full-matrix mode). This is the
|
|
runner-split entry point: a role with more variants than one runner should
|
|
iterate is sliced into bundles (e.g. ``0,1,2`` on one runner and ``3,4`` on
|
|
the next), each bundle passed as `variants`. Out-of-range indices raise
|
|
`ValueError` so the caller surfaces a clean operator error.
|
|
"""
|
|
if variants is None:
|
|
return plan
|
|
available = sorted(entry[0] for entry in plan)
|
|
missing = sorted(v for v in variants if v not in available)
|
|
if missing:
|
|
raise ValueError(
|
|
f"variants {missing} out of range; available rounds: {available}"
|
|
)
|
|
wanted = set(variants)
|
|
return [entry for entry in plan if entry[0] in wanted]
|
|
|
|
|
|
def plan_dev_inventory_matrix(
|
|
*,
|
|
roles_dir: str,
|
|
primary_apps: Sequence[str],
|
|
base_inventory_dir: str,
|
|
) -> list[PlanEntry]:
|
|
"""Return ``[(round_index, inventory_dir, round_variants, include, purge_set), ...]`` — per-round variant-closure plus a plan-constant union for the inter-round wipe."""
|
|
if not primary_apps:
|
|
raise ValueError("plan_dev_inventory_matrix: primary_apps must not be empty")
|
|
|
|
variants_per_app = get_variants(roles_dir=roles_dir)
|
|
primary_variant_counts = {
|
|
app_id: max(1, len(variants_per_app.get(app_id) or [{}]))
|
|
for app_id in primary_apps
|
|
}
|
|
total_rounds = max(primary_variant_counts.values(), default=1)
|
|
base = str(base_inventory_dir).rstrip("/")
|
|
|
|
per_variant_includes: list[tuple[str, ...]] = []
|
|
primary_round_variants_per_round: list[dict[str, int]] = []
|
|
for round_index in range(total_rounds):
|
|
primary_round_variants = {
|
|
app_id: round_index if round_index < count else 0
|
|
for app_id, count in primary_variant_counts.items()
|
|
}
|
|
primary_round_variants_per_round.append(primary_round_variants)
|
|
|
|
services_overrides = legacy_resolver._build_services_overrides_for_round(
|
|
roles_dir=roles_dir,
|
|
round_index=round_index,
|
|
primary_app_variants=primary_round_variants,
|
|
)
|
|
per_variant_includes.append(
|
|
legacy_resolver._resolve_round_include(
|
|
primary_apps=primary_apps,
|
|
services_overrides=services_overrides,
|
|
)
|
|
)
|
|
|
|
seen_union: set[str] = set()
|
|
union_apps: list[str] = []
|
|
for variant_include in per_variant_includes:
|
|
for dep in variant_include:
|
|
if dep not in seen_union:
|
|
seen_union.add(dep)
|
|
union_apps.append(dep)
|
|
purge_set: tuple[str, ...] = tuple(union_apps)
|
|
|
|
plan: list[PlanEntry] = []
|
|
for round_index in range(total_rounds):
|
|
primary_round_variants = primary_round_variants_per_round[round_index]
|
|
round_include = per_variant_includes[round_index]
|
|
|
|
round_variants = dict(primary_round_variants)
|
|
for dep, dep_variants in variants_per_app.items():
|
|
if dep in round_variants:
|
|
continue
|
|
dep_count = max(1, len(dep_variants or [{}]))
|
|
round_variants[dep] = round_index if round_index < dep_count else 0
|
|
|
|
inv_dir = f"{base}-{round_index}" if total_rounds > 1 else base
|
|
plan.append((round_index, inv_dir, round_variants, round_include, purge_set))
|
|
|
|
return plan
|