Skip to content

🌱Use context.WithTimeoutCause and context.WithCancelCause for better readability #11705

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

Merged
merged 1 commit into from
Feb 11, 2025

Conversation

Amulyam24
Copy link
Contributor

@Amulyam24 Amulyam24 commented Jan 20, 2025

What this PR does / why we need it:
This PR replaces context.WithTimeoutCause and context.WithCancelCause instead of context.Timeout and context.WithCancel for better readability of issues when the standard context deadline exceeded error is emitted.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #11280

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-area PR is missing an area label size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jan 20, 2025
@Amulyam24 Amulyam24 changed the title Use context.WithTimeoutCause instead of context.Timeout for better readability 🌱Use context.WithTimeoutCause instead of context.Timeout for better readability Jan 20, 2025
@Amulyam24
Copy link
Contributor Author

On looking into the occurrences of context.WithCancel, there were mostly in testing files. I have added the changes to non testing files as of now. Please let me know if that has to be handled as well.

@Amulyam24
Copy link
Contributor Author

/cc @sbueringer

@sbueringer
Copy link
Member

On looking into the occurrences of context.WithCancel, there were mostly in testing files. I have added the changes to non testing files as of now. Please let me know if that has to be handled as well.

Definitely fine to not change anything in test files

@sbueringer sbueringer added the area/misc Issues or PRs not related to any other area label Jan 21, 2025
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/needs-area PR is missing an area label label Jan 21, 2025
Copy link
Member

@sbueringer sbueringer left a comment

Choose a reason for hiding this comment

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

Thx for opening this PR. I think it's better to express "why the timeout/context expired" vs expressiong what we were doing when it expired. The latter is usually handled when we wrap the error

@sbueringer
Copy link
Member

On looking into the occurrences of context.WithCancel, there were mostly in testing files. I have added the changes to non testing files as of now. Please let me know if that has to be handled as well.

Not sure if you pushed your latest commit :) I didn't see any changes to context.Cancel in non-test files. (there are also a few more cases of context.WithTimeout in non-test files, but you might have been looking for initial feedback before addressing these :))

@Amulyam24
Copy link
Contributor Author

but you might have been looking for initial feedback before addressing these :))

That's right, I will address the review the comments and cover the remaining occurrences in non test files as well.

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jan 22, 2025
@Amulyam24 Amulyam24 changed the title 🌱Use context.WithTimeoutCause instead of context.Timeout for better readability 🌱Use context.WithTimeoutCause and context.WithCancelCause for better readability Jan 22, 2025
@Amulyam24 Amulyam24 requested a review from sbueringer January 22, 2025 09:43
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 28, 2025
@sbueringer
Copy link
Member

@Amulyam24 Can you please rebase? Thank you! :)

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 30, 2025
@Amulyam24
Copy link
Contributor Author

@Amulyam24 Can you please rebase? Thank you! :)

Hi @sbueringer, rebased the PR. PTAL, Thanks!

@sbueringer
Copy link
Member

sbueringer commented Feb 4, 2025

Please take a look at the linter findings: https://github.com/kubernetes-sigs/cluster-api/actions/runs/13054341109?pr=11705

The tests have probably been broken due to some changes related to ctx (but I can look for that during review)

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 5, 2025
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 6, 2025
@Amulyam24
Copy link
Contributor Author

/retest

@Amulyam24
Copy link
Contributor Author

@sbueringer, the lint and failing tests are fixed. Minor change was missed during to rebase.
Not sure why the netlify test is failing, The PR is ready for review, PTAL.

@sbueringer
Copy link
Member

Thank you very much!

/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 Feb 11, 2025
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 99923fcce58d5666ecce447ff9ffb4c0057461ec

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sbueringer

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 Feb 11, 2025
@Amulyam24
Copy link
Contributor Author

/retest

@k8s-ci-robot k8s-ci-robot merged commit d9c3c90 into kubernetes-sigs:main Feb 11, 2025
18 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.10 milestone Feb 11, 2025
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. area/misc Issues or PRs not related to any other area cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use context.WithTimeoutCause & context.WithCancelCause instead of context.WithTimeout & context.WithCancel
3 participants