13
13
# under the License.
14
14
15
15
import os
16
+ import shutil
16
17
import traceback
18
+ import uuid
17
19
20
+ from rally .common import cfg
18
21
from rally .env import platform
19
22
20
23
from rally_plugins .services .kube import kube as k8s_service
21
24
25
+ CONF = cfg .CONF
26
+
22
27
23
28
@platform .configure (name = "existing" , platform = "kubernetes" )
24
29
class KubernetesPlatform (platform .Platform ):
@@ -122,6 +127,11 @@ def check_health(self):
122
127
return {"available" : True }
123
128
124
129
def cleanup (self , task_uuid = None ):
130
+ for key in ("certificate-authority" , "client-certificate" ,
131
+ "client-key" ):
132
+ if key in self .spec :
133
+ if os .path .exists (self .spec [key ]):
134
+ os .remove (self .spec [key ])
125
135
return {
126
136
"message" : "Coming soon!" ,
127
137
"discovered" : 0 ,
@@ -138,6 +148,32 @@ def info(self):
138
148
version = k8s_service .Kubernetes (self .platform_data ).get_version ()
139
149
return {"info" : version }
140
150
151
+ @staticmethod
152
+ def _create_cert_files (cert_auth , ccert , ckey ):
153
+ """Store certification key files
154
+
155
+ :param cert_auth: certificate authority file
156
+ :param ccert: client certificate file
157
+ :param ckey: client key file
158
+ """
159
+ certs = os .path .abspath (os .path .expanduser (CONF .kubernetes .cert_dir ))
160
+ if not os .path .exists (certs ):
161
+ os .makedirs (certs )
162
+
163
+ name_uuid = str (uuid .uuid4 ())
164
+ new_cert_auth = os .path .join (certs , name_uuid + "_cert_auth" )
165
+ new_ccert = os .path .join (certs , name_uuid + "_ccert" )
166
+ new_ckey = os .path .join (certs , name_uuid + "_ckey" )
167
+ shutil .copyfile (cert_auth , new_cert_auth )
168
+ shutil .copyfile (ccert , new_ccert )
169
+ shutil .copyfile (ckey , new_ckey )
170
+
171
+ return {
172
+ "cert_auth" : new_cert_auth ,
173
+ "ccert" : new_ccert ,
174
+ "ckey" : new_ckey
175
+ }
176
+
141
177
@classmethod
142
178
def _get_doc (cls ):
143
179
doc = cls .__doc__ .strip ()
@@ -220,13 +256,14 @@ def create_spec_from_sys_environ(cls, sys_environ):
220
256
if ckey and ccert :
221
257
ckey = os .path .abspath (os .path .expanduser (ckey ))
222
258
ccert = os .path .abspath (os .path .expanduser (ccert ))
259
+ cfiles = cls ._create_cert_files (cert_auth , ccert , ckey )
223
260
return {
224
261
"available" : True ,
225
262
"spec" : {
226
263
"server" : host ,
227
- "certificate-authority" : cert_auth ,
228
- "client-certificate" : ccert ,
229
- "client-key" : ckey ,
264
+ "certificate-authority" : cfiles . get ( " cert_auth" ) ,
265
+ "client-certificate" : cfiles . get ( " ccert" ) ,
266
+ "client-key" : cfiles . get ( " ckey" ) ,
230
267
"tls_insecure" : tls_insecure
231
268
}
232
269
}
0 commit comments