@@ -380,39 +380,28 @@ async def test_recreate_scheduler_pod(k8s_cluster, kopf_runner, gen_cluster):
380380async def test_recreate_worker_pods (k8s_cluster , kopf_runner , gen_cluster ):
381381 with kopf_runner as runner :
382382 async with gen_cluster () as (cluster_name , ns ):
383- scheduler_deployment_name = "simple-scheduler"
384- worker_deployment_name = "simple-default-worker"
385- service_name = "simple-scheduler"
386- while scheduler_deployment_name not in k8s_cluster .kubectl (
387- "get" , "pods" , "-n" , ns
388- ):
389- await asyncio .sleep (0.1 )
390- while service_name not in k8s_cluster .kubectl ("get" , "svc" , "-n" , ns ):
391- await asyncio .sleep (0.1 )
392- while worker_deployment_name not in k8s_cluster .kubectl (
393- "get" , "pods" , "-n" , ns
394- ):
395- await asyncio .sleep (0.1 )
396- k8s_cluster .kubectl (
397- "delete" ,
398- "pods" ,
399- "-l" ,
400- "dask.org/cluster-name=simple,dask.org/component=worker" ,
401- "-n" ,
402- ns ,
403- )
404- k8s_cluster .kubectl (
405- "wait" ,
406- "--for=condition=Ready" ,
407- "-l" ,
408- "dask.org/cluster-name=simple,dask.org/component=worker" ,
409- "pod" ,
410- "-n" ,
411- ns ,
412- "--timeout=60s" ,
383+ cluster = await DaskCluster .get (cluster_name , namespace = ns )
384+ # Get the default worker group
385+ while not (wgs := await cluster .worker_groups ()):
386+ await asyncio .sleep (0.1 )
387+ [wg ] = wgs
388+ # Wait for worker Pods to be created
389+ while not (pods := await wg .pods ()):
390+ await asyncio .sleep (0.1 )
391+ # Store number of workers
392+ n_pods = len (pods )
393+ # Wait for worker Pods to be ready
394+ await asyncio .gather (
395+ * [pod .wait (conditions = "condition=Ready" , timeout = 60 ) for pod in pods ]
413396 )
414- assert worker_deployment_name in k8s_cluster .kubectl (
415- "get" , "pods" , "-n" , ns
397+ # Delete a worker Pod
398+ await pods [0 ].delete ()
399+ # Wait for Pods to be recreated
400+ while len ((pods := await wg .pods ())) < n_pods :
401+ await asyncio .sleep (0.1 )
402+ # Wait for worker Pods to be ready
403+ await asyncio .gather (
404+ * [pod .wait (conditions = "condition=Ready" , timeout = 60 ) for pod in pods ]
416405 )
417406
418407
0 commit comments