rail-knative/tests/test_substrate_requests.py
tegwick 76cb9c7ad9 RAIL-KNATIVE-WP-0003: cap Knative HPAs for one node, trim substrate CPU requests to 60m
Declare maxReplicas activator 20->3, webhook 5->2, 3scale-kourier-gateway
10->3 and 10m CPU requests for all six substrate containers (220m->60m),
per the resource-control node budget of 2026-10-21 (CUST-WP-0071,
RESOURCE-WP-0008). Read-only BEFORE evidence under
docs/evidence/2026-10-21-hpa-caps-before/. Not applied; railiance-cluster
overlays must follow (handoff in T02).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assistant: claude-code
Assistant-Model: opus
Assistant-Process: 8340@bnt-lap001
Assistant-Session: 2e192b3d-b3e8-4403-94d4-d55a2c8b476c
2026-10-21 08:40:35 +02:00

55 lines
2.2 KiB
Python

from pathlib import Path
import yaml
ROOT = Path(__file__).parents[1]
SUBSTRATE = ROOT / "substrate/v1.22.0"
# 220m live since 2026-09-21; trimmed to 10m each by RAIL-KNATIVE-WP-0003.
# See docs/substrate-runbook.md.
DECLARED = {
("knative-serving", "activator", "activator"): "10m",
("knative-serving", "autoscaler", "autoscaler"): "10m",
("knative-serving", "controller", "controller"): "10m",
("knative-serving", "webhook", "webhook"): "10m",
("knative-serving", "net-kourier-controller", "controller"): "10m",
("kourier-system", "3scale-kourier-gateway", "kourier-gateway"): "10m",
}
def test_patches_declare_exactly_the_cpu_requests():
found = {}
for doc in yaml.safe_load_all((SUBSTRATE / "cpu-requests.patch.yaml").read_text()):
assert doc["kind"] == "Deployment"
(container,) = doc["spec"]["template"]["spec"]["containers"]
# Only CPU requests: no limits, no memory, nothing else.
assert container["resources"] == {"requests": {"cpu": container["resources"]["requests"]["cpu"]}}
key = (doc["metadata"]["namespace"], doc["metadata"]["name"], container["name"])
found[key] = container["resources"]["requests"]["cpu"]
assert found == DECLARED
def test_kustomization_patches_the_pinned_assets():
k = yaml.safe_load((SUBSTRATE / "kustomization.yaml").read_text())
assert k["resources"] == ["core.yaml", "kourier.yaml"]
assert k["patches"] == [
{"path": "cpu-requests.patch.yaml"},
{"path": "hpa-caps.patch.yaml"},
]
# Single-node ceilings, RAIL-KNATIVE-WP-0003. minReplicas stays upstream (1).
HPA_CAPS = {
("knative-serving", "activator"): 3,
("knative-serving", "webhook"): 2,
("kourier-system", "3scale-kourier-gateway"): 3,
}
def test_hpa_patches_only_cap_max_replicas():
found = {}
for doc in yaml.safe_load_all((SUBSTRATE / "hpa-caps.patch.yaml").read_text()):
assert doc["apiVersion"] == "autoscaling/v2"
assert doc["kind"] == "HorizontalPodAutoscaler"
assert set(doc["spec"]) == {"maxReplicas"}
found[(doc["metadata"]["namespace"], doc["metadata"]["name"])] = doc["spec"]["maxReplicas"]
assert found == HPA_CAPS