-
Notifications
You must be signed in to change notification settings - Fork 14.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfix: Invalid name when trimmed pod_id
ends with hyphen in ``Kube…
#15443
Conversation
…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`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
On top of this, I wonder if we should keep the name sanitizing logic consistent between executor and operator by passing the task name through _strip_unsafe_kubernetes_special_chars
instead of using re.sub(r'[^a-z0-9.-]+', '-', name.lower())
in KubernetesPodOperator._set_name
.
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. |
("pod-name-with-hyphen-", "pod-name-with-hyphen"), | ||
("pod-name-with-double-hyphen--", "pod-name-with-double-hyphen"), | ||
("pod0-name", "pod0-name"), | ||
("simple", "simple"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
("simple", "simple"), | |
("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"), |
|
||
# 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}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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}" | |
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)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created #15445 to address it
Oops, too slow, guess we can address these in a follow up PR. |
Missed a case in (apache#15443) where `.` can be followed by another `.`.
Missed a case in (#15443) where `.` can be followed by another `.`.
…rnetesPodOperator`` (apache#15443) 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`. (cherry picked from commit 130f9e3)
Missed a case in (apache#15443) where `.` can be followed by another `.`. (cherry picked from commit 1e66ce8)
…rnetesPodOperator`` (apache#15443) 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`. (cherry picked from commit 130f9e3)
Missed a case in (apache#15443) where `.` can be followed by another `.`. (cherry picked from commit 1e66ce8)
…rnetesPodOperator`` (#15443) 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`. (cherry picked from commit 130f9e3)
…rnetesPodOperator``
When a pod name is more than
MAX_LABEL_LEN
(63 characters), it is trimmed to 63 charsairflow/airflow/kubernetes/pod_generator.py
Lines 470 to 472 in 8711f90
and we add a safe UUID to the
pod_id
joined by a dot.
. However the regexfor Kubernetes name does not allow
-
followed by a.
.Valid Regex:
This commit strips any hypens at the end of the trimmed
pod_id
.^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.