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

replace utcnow with now, due to utcnow will be deprecated #2215

Merged

Conversation

showjason
Copy link
Contributor

What type of PR is this?

What this PR does / why we need it:

datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version

Which issue(s) this PR fixes:

Fixes #2213

Special notes for your reviewer:

Does this PR introduce a user-facing change?


Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 30, 2024
@@ -1028,7 +1028,7 @@ def test_load_gcp_token_no_refresh(self):
def test_load_gcp_token_with_refresh(self):
def cred(): return None
cred.token = TEST_ANOTHER_DATA_BASE64
cred.expiry = datetime.datetime.utcnow()
cred.expiry = datetime.datetime.now(tz=UTC).replace(tzinfo=None)
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 elaborate why do we do .replace(tzinfo=None)?

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!
Because the output of datetime.datetime.utcnow() is timezone-naive, but datetime.datetime.now(tz=UTC)'s output is not, hence I utilize .replace(tzinfo=None) to replace the timezone information from the datetime object. Essentially, it converts the datetime object to a timezone-naive form, without any specific time zone associated with it.
For an instance:
datetime.datetime.utcnow() output is :
2024-04-02 12:25:49.213759
datetime.datetime.now(tz=UTC) output is:
2024-04-02 12:25:49.213766+00:00
datetime.datetime.now(tz=UTC).replace(tzinfo=None) output is:
2024-04-02 12:25:49.213766

Hope above explanation makes sense

Copy link
Member

Choose a reason for hiding this comment

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

Got it. Thanks for the explanation!

@roycaihw
Copy link
Member

roycaihw commented Apr 1, 2024

Had one question. LGTM otherwise.
/release-note-none

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Apr 1, 2024
@roycaihw roycaihw added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Apr 1, 2024
@k8s-ci-robot k8s-ci-robot removed the needs-kind Indicates a PR lacks a `kind/foo` label and requires one. label Apr 1, 2024
@roycaihw
Copy link
Member

roycaihw commented Apr 2, 2024

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 2, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: roycaihw, showjason

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 2, 2024
@k8s-ci-robot k8s-ci-robot merged commit e0234d3 into kubernetes-client:master Apr 2, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecation warning datetime.datetime.utcnow().
3 participants