Ensure that k8s job ids are unique

This commit is contained in:
Nuwan Goonasekera
2020-10-06 19:02:43 +05:30
parent 535e4c52a5
commit 3b427177fc
2 changed files with 7 additions and 3 deletions
+2 -2
View File
@@ -226,7 +226,7 @@ class KubernetesJobRunner(AsynchronousJobRunner):
(see pod selector) and an appropriate restart policy."""
k8s_spec_template = {
"metadata": {
"labels": {"app": self.__produce_unique_k8s_job_name(ajs.job_wrapper.get_id_tag())}
"labels": {"app": self.__produce_unique_k8s_job_name(ajs.job_wrapper.get_id_tag())[:-5]}
},
"spec": {
"volumes": self.runner_params['k8s_mountable_volumes'],
@@ -526,7 +526,7 @@ class KubernetesJobRunner(AsynchronousJobRunner):
"""Attempts to delete a dispatched job to the k8s cluster"""
job = job_wrapper.get_job()
try:
name = self.__produce_unique_k8s_job_name(job.get_id_tag())
name = job.job_runner_external_id
namespace = self.runner_params['k8s_namespace']
job_to_delete = find_job_object_by_name(self._pykube_api, name, namespace)
if job_to_delete:
+5 -1
View File
@@ -1,7 +1,9 @@
"""Interface layer for pykube library shared between Galaxy and Pulsar."""
import logging
import os
import random
import re
import string
import uuid
try:
@@ -57,7 +59,9 @@ def produce_unique_k8s_job_name(app_prefix=None, instance_id=None, job_id=None):
if instance_id and len(instance_id) > 0:
job_name += "%s-" % instance_id
return job_name + job_id
unique_id = ''.join(random.choices(string.ascii_lowercase, k=4))
return job_name + job_id + "-" + unique_id
def pull_policy(params):