Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deploy to k8s: set container name in new deployment, don't attempt to create service if exist #140

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Loading