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

Convert internal timestamps to TZ-aware, treat user-provided TZ-naive ones as UTC #1068

Merged
merged 3 commits into from
Oct 9, 2023

Conversation

nolar
Copy link
Owner

@nolar nolar commented Oct 9, 2023

A few places inside Kopf were using TZ-naive timestamps internally:

  • Credentials expiration times.
  • Peering "last seen".
  • All tests.

Since datetime.datetime.utcnow() is deprecated in Python 3.12, we have to switch to TZ-aware "now" timestamps, and convert the rest for the ability to compare (Python cannot compare TZ-aware to TZ-naive).

This PR ensures that all internal timestamps are TZ-aware. All user-provided TZ-naive timestamps are treated as UTC for comparison (but stored "as is").

The timestamps provided by Kubernetes API & Kubernetes resources were always parsed as TZ-aware, so this should not cause any spike in K8s API activity for reformatting the timestamps. And even if hypothetically happens to do that, this change only applies to Kopf's own "progression" timestamps, so this only affects the handlers that are still in progress/retrying, not the final stable state of resources.

kopf/_core/actions/progression.py Dismissed Show dismissed Hide dismissed
kopf/_core/actions/progression.py Dismissed Show dismissed Hide dismissed
kopf/_core/actions/progression.py Dismissed Show dismissed Hide dismissed
kopf/_core/actions/progression.py Dismissed Show dismissed Hide dismissed
…etime

Signed-off-by: Sergey Vasilyev <nolar@nolar.info>
Signed-off-by: Sergey Vasilyev <nolar@nolar.info>
… ones as UTC

The old TZ-naive way is deprecated in Python 3.12 and soon will be removed. Switch to TZ-aware time for "now", and for all places that compare against "now".
Signed-off-by: Sergey Vasilyev <nolar@nolar.info>
@nolar nolar enabled auto-merge October 9, 2023 21:59
@nolar nolar merged commit 91e8fd6 into main Oct 9, 2023
25 of 28 checks passed
@nolar nolar deleted the tz-aware-timestamps branch October 9, 2023 22:03
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.

1 participant