Skip to content
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

[AIRFLOW-6585] Fixed Timestamp bug in RefreshKubeConfigLoader #11219

Merged
merged 10 commits into from
Oct 23, 2020
Merged

[AIRFLOW-6585] Fixed Timestamp bug in RefreshKubeConfigLoader #11219

merged 10 commits into from
Oct 23, 2020

Conversation

Seltsamsel
Copy link
Contributor

Jira

https://issues.apache.org/jira/browse/AIRFLOW-6585

Description

This is basically #7153 which I extended by using pendulum to parse time strings as asked in #7153 (review) . Since that PR is closed I opened a new one.
Original description:
When using the KubernetesPodOperator on an aws kubernetes cluster, the aws-iam-authenticator is used to obtain kubernetes authentication tokens. The aws tokens contain ISO-8601 formatted timestamps, which couldn't be parsed in case of a "Z" (Zulu Time) timezone.

@boring-cyborg boring-cyborg bot added the k8s label Oct 1, 2020
@boring-cyborg
Copy link

boring-cyborg bot commented Oct 1, 2020

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/master/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

@Seltsamsel
Copy link
Contributor Author

@ashb you reviewed this before. Can you have a look?

import yaml
from kubernetes.client import Configuration
from kubernetes.config.exec_provider import ExecProvider
from kubernetes.config.kube_config import KUBE_CONFIG_DEFAULT_LOCATION, KubeConfigLoader


def _parse_timestamp(ts_str: str) -> int:
parsed_dt = pendulum.parse(ts_str)
if isinstance(parsed_dt, pendulum.DateTime):
Copy link
Member

Choose a reason for hiding this comment

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

What's this for? Doesn't pendulum throw an error if it can't parse?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is, that pendulum.parse type annotations says it return typing.Union[Date, Time, DateTime, Duration], however not all of these implement timetuple().
One of the CI tests (I guess it was mypy) yelled at me for not covering the other possible return types. I was not able to find an input string which didn't result in either a parser error or in a return type DateTime so it doesn't really matter I guess.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, cast from the typing module or a # type: comment is probably the way to go then

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, yes, cast sounds like it was made exactly for cases like this. Never heard about it before. I adjusted the code.

ts = _parse_timestamp("2020-01-13T13:42:20Z")
self.assertEqual(1578922940, ts)

def test_parse_timestamp_should_convert_regular_timezone_to_unix_timestamp(self):
Copy link
Member

Choose a reason for hiding this comment

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

Could you test an error condition too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.

@Seltsamsel
Copy link
Contributor Author

@ashb is this ok or do you want a different approach regarding pendulum?

@ashb ashb merged commit 24e2152 into apache:master Oct 23, 2020
@boring-cyborg
Copy link

boring-cyborg bot commented Oct 23, 2020

Awesome work, congrats on your first merged pull request!

michalmisiewicz pushed a commit to michalmisiewicz/airflow that referenced this pull request Oct 30, 2020
…#11219)

Co-authored-by: Jan Brusch <jan.brusch@neuland-bfi.de>
Co-authored-by: Marian Cepok <marian.cepok@neuland-bfi.de>
szn pushed a commit to szn/airflow that referenced this pull request Nov 1, 2020
…#11219)

Co-authored-by: Jan Brusch <jan.brusch@neuland-bfi.de>
Co-authored-by: Marian Cepok <marian.cepok@neuland-bfi.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants