22
33from  typing  import  List 
44
5- from  kr8s .asyncio .objects  import  APIObject ,  Deployment , Pod , Service 
5+ from  kr8s .asyncio .objects  import  Deployment , Pod , Service ,  new_class 
66
77
8- class  DaskCluster (APIObject ):
9-     version  =  "kubernetes.dask.org/v1" 
10-     endpoint  =  "daskclusters" 
11-     kind  =  "DaskCluster" 
12-     plural  =  "daskclusters" 
13-     singular  =  "daskcluster" 
14-     namespaced  =  True 
8+ class  DaskCluster (new_class ("DaskCluster" , "kubernetes.dask.org/v1" )):
159    scalable  =  True 
1610    scalable_spec  =  "worker.replicas" 
1711
1812    async  def  worker_groups (self ) ->  List [DaskWorkerGroup ]:
19-         return  await  self .api .get (
20-             DaskWorkerGroup .endpoint ,
13+         return  await  DaskWorkerGroup .list (
2114            label_selector = f"dask.org/cluster-name={ self .name }  " ,
2215            namespace = self .namespace ,
2316        )
2417
2518    async  def  scheduler_pod (self ) ->  Pod :
2619        pods  =  []
2720        while  not  pods :
28-             pods  =  await  self .api .get (
29-                 Pod .endpoint ,
21+             pods  =  await  Pod .list (
3022                label_selector = "," .join (
3123                    [
3224                        f"dask.org/cluster-name={ self .name }  " ,
@@ -41,8 +33,7 @@ async def scheduler_pod(self) -> Pod:
4133    async  def  scheduler_deployment (self ) ->  Deployment :
4234        deployments  =  []
4335        while  not  deployments :
44-             deployments  =  await  self .api .get (
45-                 Deployment .endpoint ,
36+             deployments  =  await  Deployment .list (
4637                label_selector = "," .join (
4738                    [
4839                        f"dask.org/cluster-name={ self .name }  " ,
@@ -57,8 +48,7 @@ async def scheduler_deployment(self) -> Deployment:
5748    async  def  scheduler_service (self ) ->  Service :
5849        services  =  []
5950        while  not  services :
60-             services  =  await  self .api .get (
61-                 Service .endpoint ,
51+             services  =  await  Service .list (
6252                label_selector = "," .join (
6353                    [
6454                        f"dask.org/cluster-name={ self .name }  " ,
@@ -79,19 +69,12 @@ async def ready(self) -> bool:
7969        )
8070
8171
82- class  DaskWorkerGroup (APIObject ):
83-     version  =  "kubernetes.dask.org/v1" 
84-     endpoint  =  "daskworkergroups" 
85-     kind  =  "DaskWorkerGroup" 
86-     plural  =  "daskworkergroups" 
87-     singular  =  "daskworkergroup" 
88-     namespaced  =  True 
72+ class  DaskWorkerGroup (new_class ("DaskWorkerGroup" , "kubernetes.dask.org/v1" )):
8973    scalable  =  True 
9074    scalable_spec  =  "worker.replicas" 
9175
9276    async  def  pods (self ) ->  List [Pod ]:
93-         return  await  self .api .get (
94-             Pod .endpoint ,
77+         return  await  Pod .list (
9578            label_selector = "," .join (
9679                [
9780                    f"dask.org/cluster-name={ self .spec .cluster }  " ,
@@ -103,8 +86,7 @@ async def pods(self) -> List[Pod]:
10386        )
10487
10588    async  def  deployments (self ) ->  List [Deployment ]:
106-         return  await  self .api .get (
107-             Deployment .endpoint ,
89+         return  await  Deployment .list (
10890            label_selector = "," .join (
10991                [
11092                    f"dask.org/cluster-name={ self .spec .cluster }  " ,
@@ -119,34 +101,19 @@ async def cluster(self) -> DaskCluster:
119101        return  await  DaskCluster .get (self .spec .cluster , namespace = self .namespace )
120102
121103
122- class  DaskAutoscaler (APIObject ):
123-     version  =  "kubernetes.dask.org/v1" 
124-     endpoint  =  "daskautoscalers" 
125-     kind  =  "DaskAutoscaler" 
126-     plural  =  "daskautoscalers" 
127-     singular  =  "daskautoscaler" 
128-     namespaced  =  True 
129- 
104+ class  DaskAutoscaler (new_class ("DaskAutoscaler" , "kubernetes.dask.org/v1" )):
130105    async  def  cluster (self ) ->  DaskCluster :
131106        return  await  DaskCluster .get (self .spec .cluster , namespace = self .namespace )
132107
133108
134- class  DaskJob (APIObject ):
135-     version  =  "kubernetes.dask.org/v1" 
136-     endpoint  =  "daskjobs" 
137-     kind  =  "DaskJob" 
138-     plural  =  "daskjobs" 
139-     singular  =  "daskjob" 
140-     namespaced  =  True 
141- 
109+ class  DaskJob (new_class ("DaskJob" , "kubernetes.dask.org/v1" )):
142110    async  def  cluster (self ) ->  DaskCluster :
143111        return  await  DaskCluster .get (self .name , namespace = self .namespace )
144112
145113    async  def  pod (self ) ->  Pod :
146114        pods  =  []
147115        while  not  pods :
148-             pods  =  await  self .api .get (
149-                 Pod .endpoint ,
116+             pods  =  await  Pod .list (
150117                label_selector = "," .join (
151118                    [
152119                        f"dask.org/cluster-name={ self .name }  " ,
0 commit comments