You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/04/19 22:01:00 UTC

[GitHub] [airflow] kaxil opened a new pull request #15443: Bugfix: Invalid name when trimmed `pod_id` ends with hyphen in ``Kube…

kaxil opened a new pull request #15443:
URL: https://github.com/apache/airflow/pull/15443


   …rnetesPodOperator``
   
   When a pod name is more than `MAX_LABEL_LEN` (63 characters), it is trimmed to 63 chars
   
   https://github.com/apache/airflow/blob/8711f90ab820ed420ef317b931e933a2062c891f/airflow/kubernetes/pod_generator.py#L470-L472
   
   and we add a safe UUID to the `pod_id` joined by a dot `.`. However the regex
   for Kubernetes name does not allow `-` followed by a `.`.
   
   Valid Regex:
   
   ```
   ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
   ```
   
   This commit strips any hypens at the end of the trimmed `pod_id`.
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   ---
   **^ Add meaningful description above**
   
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
   In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/master/UPDATING.md).
   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] jedcunningham commented on a change in pull request #15443: Bugfix: Invalid name when trimmed `pod_id` ends with hyphen in ``Kube…

Posted by GitBox <gi...@apache.org>.
jedcunningham commented on a change in pull request #15443:
URL: https://github.com/apache/airflow/pull/15443#discussion_r616234903



##########
File path: tests/kubernetes/test_pod_generator.py
##########
@@ -656,6 +657,24 @@ def test_pod_name_confirm_to_max_length(self, _, pod_id):
             assert len(parts[0]) <= 63
         assert len(parts[1]) <= 63
 
+    @parameterized.expand(
+        (
+            ("pod-name-with-hyphen-", "pod-name-with-hyphen"),
+            ("pod-name-with-double-hyphen--", "pod-name-with-double-hyphen"),
+            ("pod0-name", "pod0-name"),
+            ("simple", "simple"),

Review comment:
       ```suggestion
               ("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"),
   ```

##########
File path: airflow/kubernetes/pod_generator.py
##########
@@ -469,7 +469,10 @@ def make_unique_pod_id(pod_id: str) -> str:
 
         safe_uuid = uuid.uuid4().hex  # safe uuid will always be less than 63 chars
         trimmed_pod_id = pod_id[:MAX_LABEL_LEN]
-        safe_pod_id = f"{trimmed_pod_id}.{safe_uuid}"
+
+        # 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}"

Review comment:
       ```suggestion
           trimmed_pod_id = pod_id[:MAX_LABEL_LEN].rstrip('-')  # Strip trailing '-' as it cant be followed by '.'
           safe_pod_id = f"{trimmed_pod_id}.{safe_uuid}"
   ```
   
   Maybe?  Either way, your comment is wrong as it only removes trailing dashes, and occurrences has a typo.
   
   What about the '..' case (and more, maybe trimming until the last char is a-z0-9)?




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] github-actions[bot] commented on pull request #15443: Bugfix: Invalid name when trimmed `pod_id` ends with hyphen in ``Kube…

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #15443:
URL: https://github.com/apache/airflow/pull/15443#issuecomment-822835671


   The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest master at your convenience, or amend the last commit of the PR, and push it with --force-with-lease.


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] kaxil commented on a change in pull request #15443: Bugfix: Invalid name when trimmed `pod_id` ends with hyphen in ``Kube…

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #15443:
URL: https://github.com/apache/airflow/pull/15443#discussion_r616265823



##########
File path: airflow/kubernetes/pod_generator.py
##########
@@ -469,7 +469,10 @@ def make_unique_pod_id(pod_id: str) -> str:
 
         safe_uuid = uuid.uuid4().hex  # safe uuid will always be less than 63 chars
         trimmed_pod_id = pod_id[:MAX_LABEL_LEN]
-        safe_pod_id = f"{trimmed_pod_id}.{safe_uuid}"
+
+        # 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}"

Review comment:
       Created https://github.com/apache/airflow/pull/15445 to address it




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] kaxil merged pull request #15443: Bugfix: Invalid name when trimmed `pod_id` ends with hyphen in ``Kube…

Posted by GitBox <gi...@apache.org>.
kaxil merged pull request #15443:
URL: https://github.com/apache/airflow/pull/15443


   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] jedcunningham commented on pull request #15443: Bugfix: Invalid name when trimmed `pod_id` ends with hyphen in ``Kube…

Posted by GitBox <gi...@apache.org>.
jedcunningham commented on pull request #15443:
URL: https://github.com/apache/airflow/pull/15443#issuecomment-822848741


   Oops, too slow, guess we can address these in a follow up PR.


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org