forked from kr8s-org/kr8s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
32 lines (28 loc) · 1010 Bytes
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# SPDX-FileCopyrightText: Copyright (c) 2023-2024, Kr8s Developers (See LICENSE for list)
# SPDX-License-Identifier: BSD 3-Clause License
import os
import time
import pytest
from pytest_kind.cluster import KindCluster
@pytest.fixture(scope="session", autouse=True)
def k8s_cluster(request) -> KindCluster:
image = None
if version := os.environ.get("KUBERNETES_VERSION"):
image = f"kindest/node:v{version}"
kind_cluster = KindCluster(
name="pytest-kind",
image=image,
)
kind_cluster.create()
os.environ["KUBECONFIG"] = str(kind_cluster.kubeconfig_path)
# CI fix, wait for default service account to be created before continuing
while True:
try:
kind_cluster.kubectl("get", "serviceaccount", "default")
break
except Exception:
time.sleep(1)
yield kind_cluster
del os.environ["KUBECONFIG"]
if not request.config.getoption("keep_cluster"): # pragma: no cover
kind_cluster.delete()