Skip to content

Commit

Permalink
Merge pull request #864 from manics/namespace-deletion-all
Browse files Browse the repository at this point in the history
CI: Cleanup namespaces in parallel
  • Loading branch information
consideRatio authored Oct 14, 2024
2 parents 452039e + 263bf89 commit d5738ce
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,22 @@ async def watch_kubernetes(kube_client, kube_ns):
raise exc


async def _delete_namespace(client, namespace):
await client.delete_namespace(namespace, body={}, grace_period_seconds=0)
for _ in range(20): # Usually finishes a good deal faster
try:
await client.read_namespace(namespace)
except ApiException as e:
if e.status == 404:
return
else:
raise
else:
print("waiting for %s to delete" % namespace)
await asyncio.sleep(1)
raise Exception(f"Namespace {namespace} not deleted after 20 s")


@pytest_asyncio.fixture(scope="session")
async def kube_client(request, kube_ns, kube_another_ns):
"""fixture for the Kubernetes client object.
Expand Down Expand Up @@ -279,19 +295,11 @@ async def kube_client(request, kube_ns, kube_another_ns):

# allow opting out of namespace cleanup, for post-mortem debugging
if not os.environ.get("KUBESPAWNER_DEBUG_NAMESPACE"):
for namespace in expected_namespaces:
await client.delete_namespace(namespace, body={}, grace_period_seconds=0)
for _ in range(20): # Usually finishes a good deal faster
try:
await client.read_namespace(namespace)
except ApiException as e:
if e.status == 404:
return
else:
raise
else:
print("waiting for %s to delete" % namespace)
await asyncio.sleep(1)
# Delete in parallel so that if one deletion fails we still clean up the others
ns_deletions = asyncio.gather(
*[_delete_namespace(client, ns) for ns in expected_namespaces]
)
await ns_deletions


async def wait_for_pod(kube_client, kube_ns, pod_name, timeout=90):
Expand Down

0 comments on commit d5738ce

Please sign in to comment.