deer-flow/backend/tests/test_helm_init_containers.py
Bas Cancrinus 7ae36b469d
fix(helm): make the gateway init containers' image and resources conf… (#8161)
* fix(helm): make the gateway init containers' image and resources configurable

init-home and init-extensions hard-coded busybox:1.36 and set no resources.
Clusters that pull only from a mirror could not start the gateway, and a
namespace ResourceQuota on limits.* rejected the pod, although every main
container already has a configurable image and requests+limits.

Add gateway.initContainers.image (repository/tag, default busybox:1.36, same
convention as nginx.image) and gateway.initContainers.resources (modest
requests+limits by default, matching the chart README's resource defaults).
Add a helm-template test for the defaults and the overrides.

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

* docs(helm): explain mirroring gateway init images

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
2026-11-12 16:44:42 +08:00

52 lines
2.2 KiB
Python

"""The gateway's init containers must follow the chart's image and resource values.
``init-home`` and ``init-extensions`` hard-coded ``busybox:1.36`` and set no
resources. Clusters that pull only from a mirror could not start the gateway, and
a namespace ResourceQuota on ``limits.*`` rejected the pod, while every main
container already has configurable images and requests+limits.
"""
from __future__ import annotations
import shutil
import subprocess
from pathlib import Path
import pytest
import yaml
REPO_ROOT = Path(__file__).resolve().parents[2]
CHART = REPO_ROOT / "deploy" / "helm" / "deer-flow"
def _init_containers(*settings: str) -> list[dict]:
helm = shutil.which("helm")
if helm is None:
pytest.skip("helm is unavailable")
command = [helm, "template", "deer-flow", str(CHART)]
for setting in settings:
command.extend(["--set", setting])
rendered = subprocess.run(command, check=True, capture_output=True, text=True, encoding="utf-8").stdout
gateways = [document for document in yaml.safe_load_all(rendered) if isinstance(document, dict) and document.get("kind") == "Deployment" and document["metadata"]["name"].endswith("-gateway")]
assert len(gateways) == 1
init_containers = gateways[0]["spec"]["template"]["spec"]["initContainers"]
assert [container["name"] for container in init_containers] == ["init-home", "init-extensions"]
return init_containers
def test_init_containers_keep_busybox_with_requests_and_limits_by_default() -> None:
for container in _init_containers():
assert container["image"] == "busybox:1.36"
assert set(container["resources"]) == {"requests", "limits"}
assert set(container["resources"]["limits"]) == {"cpu", "memory"}
def test_init_containers_use_configured_image_and_resources() -> None:
for container in _init_containers(
"gateway.initContainers.image.repository=registry.example.com/mirror/busybox",
"gateway.initContainers.image.tag=1.36.1",
"gateway.initContainers.resources.limits.memory=32Mi",
):
assert container["image"] == "registry.example.com/mirror/busybox:1.36.1"
assert container["resources"]["limits"]["memory"] == "32Mi"