[READINESS] Update readiness python script 50/125750/1
authorothman touijer <othman.touijer@soprasteria.com>
Mon, 15 Nov 2021 10:19:33 +0000 (11:19 +0100)
committerothman touijer <othman.touijer@soprasteria.com>
Mon, 15 Nov 2021 10:19:33 +0000 (11:19 +0100)
Apply changes on ready.py file to replace some parts config parts
with a cleaner alternative. It now uses the "config" method from
python k8s package.
This is supposed to fix permission errors that arise when using a
service mesh. (suggested by Sylvain)

Issue-ID: OOM-2878
Signed-off-by: othman touijer <othman.touijer@soprasteria.com>
Change-Id: Ife2635111f3267c0920f0a2631c7102b7eedcd3a

ready.py

index 85c7f8a..85d5989 100755 (executable)
--- a/ready.py
+++ b/ready.py
@@ -30,17 +30,11 @@ import sys
 import time
 import random
 
-from kubernetes import client
+from kubernetes import client, config
 from kubernetes.client.rest import ApiException
 
-# extract env variables.
+# extract ns from env variable
 namespace = os.environ['NAMESPACE']
-cert = os.environ['CERT']
-host = os.environ['KUBERNETES_SERVICE_HOST']
-token_path = os.environ['TOKEN']
-
-with open(token_path, 'r') as token_file:
-    token = token_file.read().replace('\n', '')
 
 # setup logging
 log = logging.getLogger(__name__)
@@ -51,15 +45,10 @@ handler.setLevel(logging.INFO)
 log.addHandler(handler)
 log.setLevel(logging.INFO)
 
-configuration = client.Configuration()
-configuration.host = "https://" + host
-configuration.ssl_ca_cert = cert
-configuration.api_key['authorization'] = token
-configuration.api_key_prefix['authorization'] = 'Bearer'
-coreV1Api = client.CoreV1Api(client.ApiClient(configuration))
-api = client.AppsV1Api(client.ApiClient(configuration))
-batchV1Api = client.BatchV1Api(client.ApiClient(configuration))
-
+config.load_incluster_config()
+coreV1Api = client.CoreV1Api()
+api = client.AppsV1Api()
+batchV1Api = client.BatchV1Api()
 
 def is_job_complete(job_name):
     """