Skip to content

Commit

Permalink
RFC 1123 compliant job names
Browse files Browse the repository at this point in the history
  • Loading branch information
oavdeev committed Sep 22, 2021
1 parent c784b16 commit 48abada
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions metaflow/plugins/aws/eks/kubernetes.py
Expand Up @@ -5,6 +5,7 @@
import shlex
import time
import re
import hashlib

from metaflow import util
from metaflow.datastore.util.s3tail import S3Tail
Expand Down Expand Up @@ -44,6 +45,28 @@ class KubernetesKilledException(MetaflowException):
headline = "Kubernetes Batch job killed"


def gen_job_name(flow_name,
run_id,
step_name,
task_id,
attempt
):
""" Generate RFC 1123 compatible job name """
long_name = "-".join(
[
flow_name,
run_id,
step_name.replace('_', '-'),
task_id,
attempt,
]
).lower()
hash = hashlib.sha256(long_name.encode('utf-8')).hexdigest()

# has to be under 63 chars total
return long_name[:57] + '-' + hash[:5]


class Kubernetes(object):
def __init__(
self,
Expand Down Expand Up @@ -150,15 +173,13 @@ def create_job(
# attempt_id while submitting the job to the Kubernetes cluster. If
# that is indeed the case, we can rely on Kubernetes to generate a name
# for us.
job_name = "-".join(
[
self._flow_name,
self._run_id,
self._step_name,
self._task_id,
self._attempt,
]
).lower()
job_name = gen_job_name(
self._flow_name,
self._run_id,
self._step_name,
self._task_id,
self._attempt,
)

job = (
KubernetesClient()
Expand Down

0 comments on commit 48abada

Please sign in to comment.