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 failed Dask worker pod launch due to invalid username characters #928

Merged
merged 2 commits into from
Jun 24, 2022
Merged
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
17 changes: 15 additions & 2 deletions Tools/dea_tools/dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
create_local_dask_cluster
create_dask_gateway_cluster

Last modified: March 2020
Last modified: June 2022

'''

Expand Down Expand Up @@ -111,9 +111,22 @@ def create_dask_gateway_cluster(profile='r5_L', workers=2):
"""
try:
gateway = Gateway()

# Close any existing clusters
cluster_names = gateway.list_clusters()
if len(cluster_names) > 0:
print("Cluster(s) still running:", cluster_names)
for n in cluster_names:
cluster = gateway.connect(n.name)
cluster.shutdown()

options = gateway.cluster_options()
options['profile'] = profile
options['jupyterhub_user'] = os.getenv('JUPYTERHUB_USER')

# limit username to alphanumeric characters
# kubernetes pods won't launch if labels contain anything other than [a-Z, -, _]
options['jupyterhub_user'] = ''.join(c if c.isalnum() else '-' for c in os.getenv('JUPYTERHUB_USER'))

cluster = gateway.new_cluster(options)
cluster.scale(workers)
return cluster
Expand Down