Skip to content

Commit

Permalink
Merge pull request #4034 from jmchilton/k8_name_fixed
Browse files Browse the repository at this point in the history
[17.05] Sanitize container names sending to Kubernetes.
  • Loading branch information
bgruening committed May 17, 2017
2 parents 6614e94 + be7dea4 commit 4125f79
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/galaxy/jobs/runners/kubernetes.py
Expand Up @@ -3,6 +3,7 @@
"""

import logging
import re
from os import environ as os_environ

from six import text_type
Expand Down Expand Up @@ -208,8 +209,12 @@ def __assemble_k8s_container_image_name(self, job_wrapper):
return k8s_cont_image

def __get_k8s_container_name(self, job_wrapper):
# TODO check if this is correct
return job_wrapper.job_destination.id
# These must follow a specific regex for Kubernetes.
raw_id = job_wrapper.job_destination.id
cleaned_id = re.sub("[^-a-z0-9]", "-", raw_id)
if cleaned_id.startswith("-") or cleaned_id.endswith("-"):
cleaned_id = "x%sx" % cleaned_id
return cleaned_id

def check_watched_item(self, job_state):
"""Checks the state of a job already submitted on k8s. Job state is a AsynchronousJobState"""
Expand Down

0 comments on commit 4125f79

Please sign in to comment.