diff options
author | Krzysztof Kuzmicki <krzysztof.kuzmicki@nokia.com> | 2020-08-10 15:56:21 +0200 |
---|---|---|
committer | Grzegorz Lis <grzegorz.lis@nokia.com> | 2020-08-19 08:41:33 +0000 |
commit | e342cedaf3a4bdc47fe968a078e3cb6ee27cd0fa (patch) | |
tree | 067bbf5fbdddbc0d0861af7fc3dc2a8f36c5db70 | |
parent | 3a016ac8800ce72068dc49a8d2b4238b2be41af1 (diff) |
Make job completion function independent from container name3.0.1
Issue-ID: OOM-2535
Signed-off-by: Krzysztof Kuzmicki <krzysztof.kuzmicki@nokia.com>
Change-Id: I3dfd071a0a597108d61ef5c86c64fe79780e16a2
-rwxr-xr-x | ready.py | 32 |
1 files changed, 25 insertions, 7 deletions
@@ -1,6 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright © 2020 Orange +# Copyright © 2020 Nokia # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -56,7 +57,7 @@ configuration.ssl_ca_cert = cert configuration.api_key['authorization'] = token configuration.api_key_prefix['authorization'] = 'Bearer' coreV1Api = client.CoreV1Api(client.ApiClient(configuration)) -api = client.AppsV1(client.ApiClient(configuration)) +api = client.AppsV1Api(client.ApiClient(configuration)) batchV1Api = client.BatchV1Api(client.ApiClient(configuration)) @@ -247,12 +248,12 @@ def get_deployment_name(replicaset): DEF_TIMEOUT = 10 DESCRIPTION = "Kubernetes container readiness check utility" -USAGE = "Usage: ready.py [-t <timeout>] -c <container_name> " \ - "[-c <container_name> ...]\n" \ +USAGE = "Usage: ready.py [-t <timeout>] -c <container_name> .. | -j <job_name> .. \n" \ "where\n" \ "<timeout> - wait for container readiness timeout in min, " \ "default is " + str(DEF_TIMEOUT) + "\n" \ - "<container_name> - name of the container to wait for\n" + "<container_name> - name of the container to wait for\n" \ + "<job_name> - name of the job to wait for\n" def main(argv): @@ -266,10 +267,12 @@ def main(argv): """ # args are a list of container names container_names = [] + job_names = [] timeout = DEF_TIMEOUT try: - opts, _args = getopt.getopt(argv, "hc:t:", ["container-name=", + opts, _args = getopt.getopt(argv, "hj:c:t:", ["container-name=", "timeout=", + "job-name=", "help"]) for opt, arg in opts: if opt in ("-h", "--help"): @@ -277,13 +280,15 @@ def main(argv): sys.exit() elif opt in ("-c", "--container-name"): container_names.append(arg) + elif opt in ("-j", "--job-name"): + job_names.append(arg) elif opt in ("-t", "--timeout"): timeout = float(arg) except (getopt.GetoptError, ValueError) as exc: print("Error parsing input parameters: {}\n".format(exc)) print(USAGE) sys.exit(2) - if container_names.__len__() == 0: + if container_names.__len__() == 0 and job_names.__len__() == 0: print("Missing required input parameter(s)\n") print(USAGE) sys.exit(2) @@ -302,7 +307,20 @@ def main(argv): # spread in time potentially parallel execution in multiple # containers time.sleep(random.randint(5, 11)) - + for job_name in job_names: + timeout = time.time() + timeout * 60 + while True: + ready = is_job_complete(job_name) + if ready is True: + break + if time.time() > timeout: + log.warning("timed out waiting for '%s' to be ready", + job_name) + sys.exit(1) + else: + # spread in time potentially parallel execution in multiple + # containers + time.sleep(random.randint(5, 11)) if __name__ == "__main__": main(sys.argv[1:]) |