Skip to content

Commit

Permalink
Fix deploy to k8s: set container name in new deployment, don't attemp…
Browse files Browse the repository at this point in the history
…t to create service if exist (#140)

* fix deployment

* adapt test_callback to oda_api
  • Loading branch information
dsavchenko authored Feb 15, 2024
1 parent b686dae commit 8f197a8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
26 changes: 22 additions & 4 deletions nb2workflow/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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")
Expand Down
9 changes: 8 additions & 1 deletion tests/test_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8f197a8

Please sign in to comment.