diff --git a/nb2workflow/deploy.py b/nb2workflow/deploy.py index dca40ac1..3c767484 100644 --- a/nb2workflow/deploy.py +++ b/nb2workflow/deploy.py @@ -397,17 +397,27 @@ def deploy_k8s(container_info, ]}}}}) ] ) + except sp.CalledProcessError: sp.check_call( ["kubectl", "create", "deployment", deployment_name, "-n", namespace, "--image=" + container_info['image']] ) + time.sleep(5) # avoid race condition. time for deployment to be created in k8s + + # needed to set the proper container name sp.check_call( - ["kubectl", "expose", "deployment", deployment_name, "--name", deployment_name, - "--port", "8000", "-n", namespace] + ["kubectl", "patch", "deployment", deployment_name, "-n", namespace, + "--type", "merge", + "-p", + json.dumps( + {"spec":{"template":{"spec":{ + "containers":[ + {"name": deployment_name, "image": container_info['image']} + ]}}}}) + ] ) - + finally: - time.sleep(5) # avoid race condition. time for deployment to be created in k8s sp.check_call( ["kubectl", "patch", "deployment", deployment_name, "-n", namespace, "--type", "strategic", @@ -423,6 +433,14 @@ def deploy_k8s(container_info, ]}}}}) ] ) + + # expose if service doesn't exist + try: + sp.check_call(["kubectl", "get", "service", deployment_name, "-n", namespace]) + except sp.CalledProcessError: + sp.check_call( + ["kubectl", "expose", "deployment", deployment_name, "--name", deployment_name, + "--port", "8000", "-n", namespace]) if check_live: logging.info("will check live") diff --git a/tests/test_callback.py b/tests/test_callback.py index edca8660..539a869a 100644 --- a/tests/test_callback.py +++ b/tests/test_callback.py @@ -65,6 +65,13 @@ def test_worker_run(): with open(path.join(workdir, status_callback_file)) as json_file: progress_params = json.load(json_file) - test_data = dict(action='progress', stage='simulation', progress=50, substage='spectra', subprogress=30, message='some message') + test_data = dict(action='progress', + stage='simulation', + progress=50, + substage='spectra', + subprogress=30, + message='some message', + progress_max=100.0, + subprogress_max=100.0) assert progress_params == test_data