Skip to content

Commit

Permalink
Further fix trimmed pod_id for KubernetesPodOperator (apache#15445)
Browse files Browse the repository at this point in the history
Missed a case in (apache#15443) where `.` can be followed by another `.`.

(cherry picked from commit 1e66ce8)
  • Loading branch information
kaxil committed Apr 26, 2021
1 parent cdfe3b0 commit 085bfc3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 3 additions & 5 deletions airflow/kubernetes/pod_generator.py
Expand Up @@ -467,12 +467,10 @@ def make_unique_pod_id(pod_id: str) -> str:
return None

safe_uuid = uuid.uuid4().hex # safe uuid will always be less than 63 chars
trimmed_pod_id = pod_id[:MAX_LABEL_LEN]

# Since we use '.' as separator we need to remove all the occurences of '-' if any
# in the trimmed_pod_id as the regex does not allow '-' followed by '.'.
safe_pod_id = f"{trimmed_pod_id.rstrip('-')}.{safe_uuid}"
# Strip trailing '-' and '.' as they cant be followed by '.'
trimmed_pod_id = pod_id[:MAX_LABEL_LEN].rstrip('-.')

safe_pod_id = f"{trimmed_pod_id}.{safe_uuid}"
return safe_pod_id


Expand Down
3 changes: 3 additions & 0 deletions tests/kubernetes/test_pod_generator.py
Expand Up @@ -663,6 +663,9 @@ def test_pod_name_confirm_to_max_length(self, _, pod_id):
("pod-name-with-double-hyphen--", "pod-name-with-double-hyphen"),
("pod0-name", "pod0-name"),
("simple", "simple"),
("pod-name-with-dot.", "pod-name-with-dot"),
("pod-name-with-double-dot..", "pod-name-with-double-dot"),
("pod-name-with-hyphen-dot-.", "pod-name-with-hyphen-dot"),
)
)
def test_pod_name_is_valid(self, pod_id, expected_starts_with):
Expand Down

0 comments on commit 085bfc3

Please sign in to comment.