Skip to content

Commit 9e271b1

Browse files
authored
Merge pull request #8 from olegeech-me/master
Import _create_cert_files upstream method
2 parents 54e223c + 505bf27 commit 9e271b1

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

rally_plugins/common/opts.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
help="Kubernetes total retries to read resource status"),
2525
cfg.FloatOpt("status_poll_interval",
2626
default=1.0,
27-
help="Kubernetes status poll interval")
27+
help="Kubernetes status poll interval"),
28+
cfg.StrOpt("cert_dir",
29+
default="~/.rally/cert",
30+
help="Directory for storing certification files")
2831
]
2932

3033

rally_plugins/platforms/existing.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@
1313
# under the License.
1414

1515
import os
16+
import shutil
1617
import traceback
18+
import uuid
1719

20+
from rally.common import cfg
1821
from rally.env import platform
1922

2023
from rally_plugins.services.kube import kube as k8s_service
2124

25+
CONF = cfg.CONF
26+
2227

2328
@platform.configure(name="existing", platform="kubernetes")
2429
class KubernetesPlatform(platform.Platform):
@@ -122,6 +127,11 @@ def check_health(self):
122127
return {"available": True}
123128

124129
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])
125135
return {
126136
"message": "Coming soon!",
127137
"discovered": 0,
@@ -138,6 +148,32 @@ def info(self):
138148
version = k8s_service.Kubernetes(self.platform_data).get_version()
139149
return {"info": version}
140150

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+
141177
@classmethod
142178
def _get_doc(cls):
143179
doc = cls.__doc__.strip()
@@ -220,13 +256,14 @@ def create_spec_from_sys_environ(cls, sys_environ):
220256
if ckey and ccert:
221257
ckey = os.path.abspath(os.path.expanduser(ckey))
222258
ccert = os.path.abspath(os.path.expanduser(ccert))
259+
cfiles = cls._create_cert_files(cert_auth, ccert, ckey)
223260
return {
224261
"available": True,
225262
"spec": {
226263
"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"),
230267
"tls_insecure": tls_insecure
231268
}
232269
}

0 commit comments

Comments
 (0)