4
4
import os
5
5
import subprocess
6
6
import tempfile
7
+ import uuid
7
8
8
9
from kopf .testing import KopfRunner
9
10
from pytest_kind .cluster import KindCluster
10
11
11
- from dask_kubernetes .common .utils import check_dependency , get_current_namespace
12
+ from dask_kubernetes .common .utils import check_dependency
12
13
13
14
DIR = pathlib .Path (__file__ ).parent .absolute ()
14
15
@@ -60,50 +61,48 @@ def install_istio(k8s_cluster):
60
61
)
61
62
62
63
63
- @pytest .fixture (scope = "session" )
64
+ @pytest .fixture (autouse = True )
64
65
def ns (k8s_cluster ):
65
- return get_current_namespace ()
66
-
67
-
68
- def run_generate (crd_path , patch_path , temp_path ):
69
- subprocess .run (
70
- ["k8s-crd-resolver" , "-r" , "-j" , patch_path , crd_path , temp_path ],
71
- check = True ,
72
- env = {** os .environ },
73
- )
66
+ ns = "dask-k8s-pytest-" + uuid .uuid4 ().hex [:10 ]
67
+ k8s_cluster .kubectl ("create" , "ns" , ns )
68
+ yield ns
69
+ k8s_cluster .kubectl ("delete" , "ns" , ns , "--wait=false" , "--ignore-not-found=true" )
74
70
75
71
76
72
@pytest .fixture (scope = "session" , autouse = True )
77
73
def install_gateway (k8s_cluster ):
78
- check_dependency ("helm" )
79
- # To ensure the operator can coexist with Gateway
80
- subprocess .run (
81
- [
82
- "helm" ,
83
- "upgrade" ,
84
- "dask-gateway" ,
85
- "dask-gateway" ,
86
- "--install" ,
87
- "--repo=https://helm.dask.org" ,
88
- "--create-namespace" ,
89
- "--namespace" ,
90
- "dask-gateway" ,
91
- ],
92
- check = True ,
93
- env = {** os .environ },
94
- )
95
- yield
96
- subprocess .run (
97
- [
98
- "helm" ,
99
- "delete" ,
100
- "--namespace" ,
101
- "dask-gateway" ,
102
- "dask-gateway" ,
103
- ],
104
- check = True ,
105
- env = {** os .environ },
106
- )
74
+ if bool (os .environ .get ("TEST_DASK_GATEWAY" , False )):
75
+ check_dependency ("helm" )
76
+ # To ensure the operator can coexist with Gateway
77
+ subprocess .run (
78
+ [
79
+ "helm" ,
80
+ "upgrade" ,
81
+ "dask-gateway" ,
82
+ "dask-gateway" ,
83
+ "--install" ,
84
+ "--repo=https://helm.dask.org" ,
85
+ "--create-namespace" ,
86
+ "--namespace" ,
87
+ "dask-gateway" ,
88
+ ],
89
+ check = True ,
90
+ env = {** os .environ },
91
+ )
92
+ yield
93
+ subprocess .run (
94
+ [
95
+ "helm" ,
96
+ "delete" ,
97
+ "--namespace" ,
98
+ "dask-gateway" ,
99
+ "dask-gateway" ,
100
+ ],
101
+ check = True ,
102
+ env = {** os .environ },
103
+ )
104
+ else :
105
+ yield
107
106
108
107
109
108
@pytest .fixture (scope = "session" , autouse = True )
@@ -112,6 +111,13 @@ def customresources(k8s_cluster):
112
111
temp_dir = tempfile .TemporaryDirectory ()
113
112
crd_path = os .path .join (DIR , "operator" , "customresources" )
114
113
114
+ def run_generate (crd_path , patch_path , temp_path ):
115
+ subprocess .run (
116
+ ["k8s-crd-resolver" , "-r" , "-j" , patch_path , crd_path , temp_path ],
117
+ check = True ,
118
+ env = {** os .environ },
119
+ )
120
+
115
121
for crd in ["daskcluster" , "daskworkergroup" , "daskjob" , "daskautoscaler" ]:
116
122
run_generate (
117
123
os .path .join (crd_path , f"{ crd } .yaml" ),
0 commit comments