Skip to content

Conversation

@SimonOsipov
Copy link

Closes: #16600

In order to have a more readable naming of KubernetesExecutor Pod, decided to remove deleting "dashes" as per the documentation it is allowed.

@SimonOsipov SimonOsipov requested a review from dimberman as a code owner June 24, 2021 17:28
@boring-cyborg boring-cyborg bot added the provider:cncf-kubernetes Kubernetes (k8s) provider related issues label Jun 24, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Jun 24, 2021

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
Here are some useful points:

  • Pay attention to the quality of your code (flake8, pylint and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it’s a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

Copy link
Member

@uranusjr uranusjr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some test cases will also be needed.

:return: Pod name stripped of any unsafe characters
"""
return ''.join(ch.lower() for ch in list(string) if ch.isalnum())
return ''.join(ch.lower() for ch in list(string) if ch.isalnum() or ch in ['-'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s probably easier to do a re.sub instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate more on why using an additional module would be more effective? I am fairly new to Python, so I am eager for knowledge.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not many reasons TBH, just it’s probably easier to understand IMO.

return re.sub(r"[^-a-z0-9]+", string.lower())

It may also be easier to implement additional logic, such as avoiding - in the beginning of the string (which the logic you implement right now does not do).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we are to use regex, we should use a precompiled regex object. If we are not going to use regex here, then i think we should just do the comparison with ch == '-' without creating a new list in memory.

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
@SimonOsipov
Copy link
Author

Some test cases will also be needed.

def test_pod_name_confirm_to_max_length(self, _, pod_id):
name = PodGenerator.make_unique_pod_id(pod_id)
assert len(name) <= 253
parts = name.split(".")
if len(pod_id) <= 63:
assert len(parts[0]) == len(pod_id)
else:
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"),
("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):
name = PodGenerator.make_unique_pod_id(pod_id)
regex = r"^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$"
assert (
len(name) <= 253 and all(ch.lower() == ch for ch in name) and re.match(regex, name)
), "pod_id is invalid - fails allowed regex check"
assert name.rsplit(".")[0] == expected_starts_with

It seems like already provided test cases are enough (they are with dashes). Also, regex is valid for using dashes.

@uranusjr
Copy link
Member

It seems like already provided test cases are enough

Some more should be added since the logic now has more allowed characters. Name with leading dash/dot/underscore, for example.

@kaxil
Copy link
Member

kaxil commented Jun 25, 2021

There were also #15443 and #15445

'-' followed by '.' isn't allowed which caused issues when pod_id was trimmed

cc @houqp

Copy link
Member

@houqp houqp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on what @kaxil said, i don't see specific code to guard against that regression?

:return: Pod name stripped of any unsafe characters
"""
return ''.join(ch.lower() for ch in list(string) if ch.isalnum())
return ''.join(ch.lower() for ch in list(string) if ch.isalnum() or ch in ['-'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we are to use regex, we should use a precompiled regex object. If we are not going to use regex here, then i think we should just do the comparison with ch == '-' without creating a new list in memory.

@SimonOsipov
Copy link
Author

I am sorry, have been sick lately, can we return to this MR?
What was the decision and what additional things needs to be done to implement this (I would like to take and complete them) =)

@uranusjr @kaxil @houqp

@houqp
Copy link
Member

houqp commented Jul 15, 2021

@SimonOsipov i think you need to write code to check and remove trailing - after the truncation so when we concat them with ., it won't result in invalid pod name in k8s. And of course add some unit tests for it :)

@uranusjr
Copy link
Member

I think #17057 covers this.

@uranusjr uranusjr closed this Jul 21, 2021
@uranusjr
Copy link
Member

#17057 only covers the kubernetes_helper_functions.py part of this PR; we still need other parts of this.

@uranusjr uranusjr reopened this Jul 21, 2021
@github-actions
Copy link

github-actions bot commented Sep 5, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Sep 5, 2021
@SimonOsipov
Copy link
Author

I terribly apologize, I a bit felt out of the issue I created. Is this issue still valid?

@github-actions github-actions bot removed the stale Stale PRs per the .github/workflows/stale.yml policy file label Sep 7, 2021
@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Oct 22, 2021
@github-actions github-actions bot closed this Oct 28, 2021
@SimonOsipov SimonOsipov deleted the feature-pod-naming-with-dash branch November 8, 2021 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

provider:cncf-kubernetes Kubernetes (k8s) provider related issues stale Stale PRs per the .github/workflows/stale.yml policy file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pod naming ignores dashes and underscores

4 participants