dstandish commented on code in PR #27736:
URL: https://github.com/apache/airflow/pull/27736#discussion_r1024987897


##########
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:
   Both KPO and k8s executor randomize in the same way, with that 
`make_unique_pod_id` function.
   
   The difference with KPO is the user can choose the pod name, and that's 
what's happening in the bit of code you reference there.
   
   Recently I made it so that with KPO we can omit name and it will use 
task_id.  Eventually we can use the `create_pod_id` function from core but I 
didn't do that initially because I don't like it's behavior.  But i'm improving 
that [here](https://github.com/apache/airflow/pull/27736) and after some time 
we can update KPO to use that function when name not supplied.



-- 
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]

Reply via email to