Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Cleanup namespaces in parallel #864

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is new. Previously this function would wait up to 20s but not do anything if the namespace hadn't been deleted. Is that the behaviour we desire?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you did now is better!



@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