Skip to content

Commit 6970a8c

Browse files
authored
KubeCluster.shutdown_on_close should be False when created from_name (#727)
* KubeCluster.shutdown_on_close should be False when created from_name * Allow users to specify crete_mode and shutdown_on_close options * Update cluster from_name test * Forgot to add async arg * async cm * Update for kr8s PR
1 parent bebb5d1 commit 6970a8c

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

dask_kubernetes/operator/kubecluster/kubecluster.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,12 @@ def from_name(cls, name, **kwargs):
878878
--------
879879
>>> cluster = KubeCluster.from_name(name="simple-cluster")
880880
"""
881-
return cls(name=name, create_mode=CreateMode.CONNECT_ONLY, **kwargs)
881+
defaults = {"create_mode": CreateMode.CONNECT_ONLY, "shutdown_on_close": False}
882+
kwargs = defaults | kwargs
883+
return cls(
884+
name=name,
885+
**kwargs,
886+
)
882887

883888

884889
def make_cluster_spec(

dask_kubernetes/operator/kubecluster/tests/test_kubecluster.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from dask.distributed import Client
55
from distributed.utils import TimeoutError
66

7+
from dask_kubernetes.operator.objects import DaskCluster
78
from dask_kubernetes.operator import KubeCluster, make_cluster_spec
89
from dask_kubernetes.exceptions import SchedulerStartupError
910

@@ -95,13 +96,22 @@ def test_multiple_clusters_simultaneously_same_loop(kopf_runner, docker_image):
9596
assert client2.submit(lambda x: x + 1, 10).result() == 11
9697

9798

98-
def test_cluster_from_name(kopf_runner, docker_image, ns):
99+
@pytest.mark.asyncio
100+
async def test_cluster_from_name(kopf_runner, docker_image, ns):
99101
with kopf_runner:
100-
with KubeCluster(
101-
name="abc", namespace=ns, image=docker_image, n_workers=1
102+
async with KubeCluster(
103+
name="abc",
104+
namespace=ns,
105+
image=docker_image,
106+
n_workers=1,
107+
asynchronous=True,
102108
) as firstcluster:
103-
with KubeCluster.from_name("abc", namespace=ns) as secondcluster:
109+
async with KubeCluster.from_name(
110+
"abc", namespace=ns, asynchronous=True
111+
) as secondcluster:
104112
assert firstcluster == secondcluster
113+
cluster = await DaskCluster.get("abc", namespace=ns)
114+
assert cluster.status["phase"] == "Running"
105115

106116

107117
def test_cluster_scheduler_info_updated(kopf_runner, docker_image, ns):

0 commit comments

Comments
 (0)