eladkal commented on code in PR #27736:
URL: https://github.com/apache/airflow/pull/27736#discussion_r1024925793
##########
airflow/kubernetes/pod_generator.py:
##########
@@ -445,29 +455,27 @@ def make_unique_pod_id(pod_id: str) -> str | None:
r"""
Kubernetes pod names must consist of one or more lowercase
rfc1035/rfc1123 labels separated by '.' with a maximum length of 253
- characters. Each label has a maximum length of 63 characters.
+ characters.
Name must pass the following regex for validation
``^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$``
+ (But note that this method actually doesn't guarantee that!)
+
For more details, see:
https://github.com/kubernetes/kubernetes/blob/release-1.1/docs/design/identifiers.md
- :param pod_id: a dag_id with only alphanumeric characters
+ :param pod_id: requested pod name
:return: ``str`` valid Pod name of appropriate length
"""
if not pod_id:
return None
- safe_uuid = uuid.uuid4().hex # safe uuid will always be less than 63
chars
-
- # Get prefix length after subtracting the uuid length. Clean up '.'
and '-' from
- # end of podID ('.' can't be followed by '-').
- label_prefix_length = MAX_LABEL_LEN - len(safe_uuid) - 1 # -1 for
separator
- trimmed_pod_id = pod_id[:label_prefix_length].rstrip("-.")
-
- # previously used a '.' as the separator, but this could create errors
in some situations
- return f"{trimmed_pod_id}-{safe_uuid}"
+ max_pod_id_len = 100 # arbitrarily chosen
+ suffix = rand_str(8) # 8 seems good enough
+ base_pod_id_len = max_pod_id_len - len(suffix) - 1 # -1 for separator
+ trimmed_pod_id = pod_id[:base_pod_id_len].rstrip("-.")
+ return f"{trimmed_pod_id}-{suffix}"
Review Comment:
Shouldn't the logic be also the same for KPO?
https://github.com/apache/airflow/blob/610f57fdd1739815660718cfd784efc4dbe96397/airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py#L514-L518
The goal is the same so why are we randomize differently or am I missing
something here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]