11
11
import kubernetes_asyncio as kubernetes
12
12
from importlib_metadata import entry_points
13
13
from kubernetes_asyncio .client import ApiException
14
+ from kr8s .asyncio .objects import APIObject
14
15
15
16
from dask_kubernetes .common .auth import ClusterAuth
16
17
from dask_kubernetes .common .networking import get_scheduler_address
17
- from dask_kubernetes .aiopykube import HTTPClient , KubeConfig
18
- from dask_kubernetes .aiopykube .dask import DaskCluster
19
18
from distributed .core import rpc , clean_exception
20
19
from distributed .protocol .pickle import dumps
21
20
@@ -40,6 +39,45 @@ class SchedulerCommError(Exception):
40
39
"""Raised when unable to communicate with a scheduler."""
41
40
42
41
42
+ class DaskCluster (APIObject ):
43
+ version = "kubernetes.dask.org/v1"
44
+ endpoint = "daskclusters"
45
+ kind = "DaskCluster"
46
+ plural = "daskclusters"
47
+ singular = "daskcluster"
48
+ namespaced = True
49
+ scalable = True
50
+ scalable_spec = "worker.replicas"
51
+
52
+
53
+ class DaskWorkerGroup (APIObject ):
54
+ version = "kubernetes.dask.org/v1"
55
+ endpoint = "daskworkergroups"
56
+ kind = "DaskWorkerGroup"
57
+ plural = "daskworkergroups"
58
+ singular = "daskworkergroup"
59
+ namespaced = True
60
+ scalable = True
61
+
62
+
63
+ class DaskAutoscaler (APIObject ):
64
+ version = "kubernetes.dask.org/v1"
65
+ endpoint = "daskautoscalers"
66
+ kind = "DaskAutoscaler"
67
+ plural = "daskautoscalers"
68
+ singular = "daskautoscaler"
69
+ namespaced = True
70
+
71
+
72
+ class DaskJob (APIObject ):
73
+ version = "kubernetes.dask.org/v1"
74
+ endpoint = "daskjobs"
75
+ kind = "DaskJob"
76
+ plural = "daskjobs"
77
+ singular = "daskjob"
78
+ namespaced = True
79
+
80
+
43
81
def _get_annotations (meta ):
44
82
return {
45
83
annotation_key : annotation_value
@@ -347,10 +385,8 @@ async def handle_scheduler_service_status(
347
385
# Otherwise mark it as Running
348
386
else :
349
387
phase = "Running"
350
-
351
- api = HTTPClient (KubeConfig .from_env ())
352
- cluster = await DaskCluster .objects (api , namespace = namespace ).get_by_name (
353
- labels ["dask.org/cluster-name" ]
388
+ cluster = await DaskCluster .get (
389
+ labels ["dask.org/cluster-name" ], namespace = namespace
354
390
)
355
391
await cluster .patch ({"status" : {"phase" : phase }})
356
392
@@ -986,8 +1022,5 @@ async def daskcluster_autoshutdown(spec, name, namespace, logger, **kwargs):
986
1022
logger .warn ("Unable to connect to scheduler, skipping autoshutdown check." )
987
1023
return
988
1024
if idle_since and time .time () > idle_since + spec ["idleTimeout" ]:
989
- api = HTTPClient (KubeConfig .from_env ())
990
- cluster = await DaskCluster .objects (api , namespace = namespace ).get_by_name (
991
- name
992
- )
1025
+ cluster = await DaskCluster .get (name , namespace = namespace )
993
1026
await cluster .delete ()
0 commit comments