prole/tests/installer/test_garage_common.py
chrisfu b1755f4e7b Stabilize prod deployment flow and harden Garage/CNPG ops
Switch production config to k8s/GKE contexts and align service naming. Add immutable StatefulSet update fallback for Garage across k3d/k3s/k8s. Harden CNPG deploy and backup bootstrap paths, and update installer coverage for CNPG webhook and Garage common ops.

Co-authored-by: Junie <junie@jetbrains.com>
2026-04-11 20:19:36 -07:00

83 lines
2.5 KiB
Python

from __future__ import annotations
from subprocess import CompletedProcess
import pytest
from knoe.core.ops import _garage_common as garage_common
def test_apply_garage_statefulset_with_recreate_on_immutable_error(monkeypatch):
calls: list[tuple[list[str], bool]] = []
def _fake_kubectl(args, *, env=None, input_text=None, timeout=300, check=False):
calls.append((args, check))
if len(calls) == 1:
return CompletedProcess(
args,
1,
"",
"The StatefulSet \"garage\" is invalid: spec: Forbidden: updates to statefulset spec for fields other than",
)
return CompletedProcess(args, 0, "", "")
monkeypatch.setattr(garage_common, "_kubectl", _fake_kubectl)
logs: list[str] = []
garage_common._apply_garage_statefulset_with_recreate(
namespace="knoe-system",
manifest="/tmp/garage-statefulset.yaml",
log=logs.append,
)
assert len(calls) == 3
assert calls[0][1] is False
assert calls[1][1] is True
assert calls[2][1] is True
assert calls[1][0] == [
"-n",
"knoe-system",
"delete",
"statefulset",
"garage",
"--ignore-not-found=true",
"--wait=true",
]
assert any("recreating statefulset/garage" in line for line in logs)
def test_apply_garage_statefulset_with_recreate_raises_on_other_errors(monkeypatch):
calls: list[list[str]] = []
def _fake_kubectl(args, *, env=None, input_text=None, timeout=300, check=False):
calls.append(args)
return CompletedProcess(args, 1, "", "boom")
monkeypatch.setattr(garage_common, "_kubectl", _fake_kubectl)
with pytest.raises(RuntimeError, match="boom"):
garage_common._apply_garage_statefulset_with_recreate(
namespace="knoe-system",
manifest="/tmp/garage-statefulset.yaml",
)
assert len(calls) == 1
def test_apply_garage_statefulset_with_recreate_returns_on_success(monkeypatch):
calls: list[tuple[list[str], bool]] = []
def _fake_kubectl(args, *, env=None, input_text=None, timeout=300, check=False):
calls.append((args, check))
return CompletedProcess(args, 0, "", "")
monkeypatch.setattr(garage_common, "_kubectl", _fake_kubectl)
garage_common._apply_garage_statefulset_with_recreate(
namespace="knoe-system",
manifest="/tmp/garage-statefulset.yaml",
)
assert len(calls) == 1
assert calls[0][1] is False