aboutsummaryrefslogtreecommitdiffstats
path: root/sdv/docker/sdvstate/tools/kube_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'sdv/docker/sdvstate/tools/kube_utils.py')
-rw-r--r--sdv/docker/sdvstate/tools/kube_utils.py66
1 files changed, 63 insertions, 3 deletions
diff --git a/sdv/docker/sdvstate/tools/kube_utils.py b/sdv/docker/sdvstate/tools/kube_utils.py
index 3468ac6..9c543db 100644
--- a/sdv/docker/sdvstate/tools/kube_utils.py
+++ b/sdv/docker/sdvstate/tools/kube_utils.py
@@ -18,6 +18,8 @@
Kubernetes cluster api helper functions
"""
+import time
+
from kubernetes import client, config
from kubernetes.stream import stream
@@ -77,9 +79,67 @@ def kube_curl(*args):
args = list(args)
args.insert(0, "curl")
- labels = "application=prometheus-openstack-exporter,component=exporter"
- pod = get_pod_with_labels(labels)
- response = kube_exec(pod, args)
+ try:
+ pod = get_pod_with_labels("application=sdvstate-curl")
+ except IndexError:
+ create_kube_curl_pod()
+ pod = get_pod_with_labels("application=sdvstate-curl")
+ finally:
+ response = kube_exec(pod, args)
return response
+
+
+def create_kube_curl_pod():
+ """
+ Create a sandbox pod(image: curlimages/curl:7.76.1) for
+ curl utility inside kubernetes cluster.
+ """
+ print(("Creating pod sdvstate-curl..."))
+ pod_manifest = {
+ 'apiVersion': 'v1',
+ 'kind': 'Pod',
+ 'metadata': {
+ 'name': 'sdvstate-curl',
+ 'labels': {
+ 'application': 'sdvstate-curl'
+ }
+ },
+ 'spec': {
+ 'containers': [{
+ 'image': 'curlimages/curl:7.76.1',
+ 'name': 'sdvstate-curl',
+ 'command': ["/bin/sh"],
+ "args": [
+ "-c",
+ "while true; do sleep 5; done"
+ ]
+ }]
+ }
+ }
+
+ api = kube_api()
+ response = api.create_namespaced_pod(body=pod_manifest,
+ namespace='default')
+ # wait 1 minute or less for pod to create.
+ seconds_left = 60
+ while seconds_left:
+ resp = api.read_namespaced_pod(name='sdvstate-curl',
+ namespace='default')
+ if resp.status.phase == 'Running':
+ break
+ time.sleep(3)
+ seconds_left -= 3
+
+ if seconds_left == 0:
+ raise Exception("sdvstate-curl pod taking took long to create, tests failed...")
+
+
+def delete_kube_curl_pod():
+ """
+ Cleans curl utility pod
+ """
+ api = kube_api()
+ api.delete_namespaced_pod(name='sdvstate-curl', body={},
+ namespace='default')