chart_from_ci_cache should not be a generator

- In case of exception, it yields twice, which is invalid contextmanager
behaviour
This commit is contained in:
Gaël Goinvic committed 2026-02-25 11:07:05 +01:00
1 parent bbb079b64b
commit 8a2302f771
2 files changed
+27 -27

No files matched your search

+22 -22
View File
@@ -154,16 +154,16 @@ async def cert_manager(helm_client, kube_client):
if os.environ.get("SKIP_CERT_MANAGER", "false") != "false":
return
async with chart_from_ci_cache(helm_client, "oci://quay.io/jetstack/charts/cert-manager") as chart:
await helm_client.install_or_upgrade_release(
"cert-manager",
chart,
yaml.safe_load((Path(__file__).parent / "files/charts/cert-manager.yml").open()),
namespace="cert-manager",
create_namespace=True,
atomic=True,
wait=True,
)
chart = await chart_from_ci_cache(helm_client, "oci://quay.io/jetstack/charts/cert-manager")
await helm_client.install_or_upgrade_release(
"cert-manager",
chart,
yaml.safe_load((Path(__file__).parent / "files/charts/cert-manager.yml").open()),
namespace="cert-manager",
create_namespace=True,
atomic=True,
wait=True,
)
ca_folder = Path(__file__).parent.parent.parent.parent / ".ca"
if not ca_folder.exists():
@@ -230,20 +230,20 @@ async def cert_manager(helm_client, kube_client):
@pytest.fixture(scope="session")
async def prometheus_operator_crds(helm_client):
if os.environ.get("SKIP_SERVICE_MONITORS_CRDS", "false") == "false":
async with chart_from_ci_cache(
chart = await chart_from_ci_cache(
helm_client,
"oci://ghcr.io/prometheus-community/charts/prometheus-operator-crds",
) as chart:
# Install or upgrade a release
await helm_client.install_or_upgrade_release(
"prometheus-operator-crds",
chart,
{},
namespace="prometheus-operator",
create_namespace=True,
atomic=True,
wait=True,
)
)
# Install or upgrade a release
await helm_client.install_or_upgrade_release(
"prometheus-operator-crds",
chart,
{},
namespace="prometheus-operator",
create_namespace=True,
atomic=True,
wait=True,
)
@pytest.fixture(scope="session")
+5 -5
View File
@@ -259,8 +259,7 @@ async def forward_matching_logs(input_logs_queue: asyncio.Queue, output_matchers
output_logs_queue.put_nowait(log_line)
@asynccontextmanager
async def chart_from_ci_cache(helm_client: pyhelm3.Client, chart_ref: str) -> AsyncGenerator[pyhelm3.Chart]:
async def chart_from_ci_cache(helm_client: pyhelm3.Client, chart_ref: str) -> pyhelm3.Chart:
project_root = Path(__file__).parent.parent.parent.parent
if os.environ.get("CI"):
helm_cache = project_root / ".pyhelm_cache"
@@ -274,12 +273,13 @@ async def chart_from_ci_cache(helm_client: pyhelm3.Client, chart_ref: str) -> As
shutil.rmtree(cached_ref)
# pull_chart returns a Chart object, not a Path, type annotation is wrong
chart.ref.copy(cached_ref) # type: ignore
yield chart # type: ignore
# pull_chart removes the pulled chart, we return the cached one
return await helm_client.get_chart(cached_ref) # type: ignore
except Exception:
# Fall back to cache if remote fetch fails
if cached_ref.exists():
yield await helm_client.get_chart(cached_ref)
return await helm_client.get_chart(cached_ref)
else:
raise # Re-raise if neither remote nor cache is available
else:
yield await helm_client.get_chart(chart_ref)
return await helm_client.get_chart(chart_ref)