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

[WIP] Add context and timeouts #404

Closed
wants to merge 1 commit into from

Conversation

karlkfi
Copy link
Contributor

@karlkfi karlkfi commented Sep 14, 2021

  • Add timeout flag to apply, destory, and preview cmds
  • Default to no timeout
  • Add context to TaskContext
  • Pass context through to all functions that use it
  • Rename prune-timeout flag to delete-timeout and add actual impl
  • Rename PruneOptions to Pruner (there's already prune.Options)
  • Rename PropagationPolicy to DeletionPropagationPolicy consistently
  • Wrap func calls and defs for readability
  • Remove Prune bool from solver.Options to simplify
    AppendPruneWaitTasks to always prune.
    Change Applier to only call AppendPruneWaitTasks if NoPrune.
    Change Destroyer to always call AppendPruneWaitTasks.
  • Replace task.ClearTimeout with context.Cancel
  • Add task.OnStatusEvent to fix WaitTask leaky abstraction.
    baseRunner was calling private funcs from WaitTask.
  • Move ResourceStatusCollector into TaskContext. It doesn't need to
    persist between runs. Moving it simplifies baseRunner.
    This required making some of the collector funcs public.
  • Remove Identifier from collector.ResourceStatus. Redundant with id.
  • Add collector.Get/Put funcs for encapsulation and thread-safety
  • Add locking to ResourceStatusCollector because a test was complaining
    about a race condition when updating status from another goroutine,
    like the poller does.
  • Add logging to taskrunner tests for easier debugging concurrency
  • Update task tests for cancel and timeout
  • Rename options vars to "opts" for consistency
  • Rewrite WaitTask context/timeout handling.
    TaskChannel is now only written to from one place, gated by an
    internal error channel and sync.Once.
    WaitTask now distinguishes between wait task timeout and parent
    context timeout.
  • Update task tests to reflect new behavior with context cancel/timeout

Note: This PR is probably too big. I started cleaning things up and kept finding things to fix. Let me know what I should leave out or punt to another PR.

- Add timeout flag to apply, destory, and preview cmds
- Default to no timeout
- Add context to TaskContext
- Pass context through to all functions that use it
- Rename prune-timeout flag to delete-timeout and add actual impl
- Rename PruneOptions to Pruner (there's already prune.Options)
- Rename PropagationPolicy to DeletionPropagationPolicy consistently
- Wrap func calls and defs for readability
- Remove Prune bool from solver.Options to simplify
  AppendPruneWaitTasks to always prune.
  Change Applier to only call AppendPruneWaitTasks if NoPrune.
  Change Destroyer to always call AppendPruneWaitTasks.
- Replace task.ClearTimeout with context.Cancel
- Add task.OnStatusEvent to fix WaitTask leaky abstraction.
  baseRunner was calling private funcs from WaitTask.
- Move ResourceStatusCollector into TaskContext. It doesn't need to
  persist between runs. Moving it simplifies baseRunner.
  This required making some of the collector funcs public.
- Remove Identifier from collector.ResourceStatus. Redundant with id.
- Add collector.Get/Put funcs for encapsulation and thread-safety
- Add locking to ResourceStatusCollector because a test was complaining
  about a race condition when updating status from another goroutine,
  like the poller does.
- Add logging to taskrunner tests for easier debugging concurrency
- Update task tests for cancel and timeout
- Rename options vars to "opts" for consistency
- Rewrite WaitTask context/timeout handling.
  TaskChannel is now only written to from one place, gated by an
  internal error channel and sync.Once.
  WaitTask now distinguishes between wait task timeout and parent
  context timeout.
- Update task tests to reflect new behavior with context cancel/timeout
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 14, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @karlkfi. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Sep 14, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: karlkfi
To complete the pull request process, please assign liujingfang1 after the PR has been reviewed.
You can assign the PR to them by writing /assign @liujingfang1 in a comment when ready.

The full list of commands accepted by this bot can be found 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 size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Sep 14, 2021
@seans3
Copy link
Contributor

seans3 commented Sep 14, 2021

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 14, 2021
@k8s-ci-robot
Copy link
Contributor

@karlkfi: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
cli-utils-presubmit-master-e2e 52130d8 link true /test cli-utils-presubmit-master-e2e

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

Copy link
Contributor

@seans3 seans3 left a comment

Choose a reason for hiding this comment

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

This is a massive PR, and it needs to be broken up in to safer, more digestible chunks. Renaming variables or functions should almost always be done in separate PR's to reduce risk and complexity. Smaller PR's are faster to merge and safer (as long as they are also well-tested).

On another note, do not worry about substantive changes to any code under the cmd hierarchy, since these commands are not exported; they are only used for testing and demonstration purposes.

@karlkfi
Copy link
Contributor Author

karlkfi commented Sep 15, 2021

Sure. I'll chop this into smaller PRs. Just wanted a place to stash a bunch of the tech debt fixes that I came up with while writing the apply-time-mutation PR. Was hoping to get some feedback on the stuff being done, but if it's too much, I'll pull stuff out, after I have time to figure out what's actually blocking the apply-time-mutation PR.

I think the ResourceCache and ResourceStatusCollector probably need to get merged.

But of course, the e2e tests here are failing, so I must have broken something. I couldn't figure out how to even debug the failures on this branch, so I spent some time improving the tests and testutils to make it easier: #405

Hopefully once that's merged I can come back to this and figure out what went wrong.

@karlkfi karlkfi changed the title Add context and timeouts [WIP] Add context and timeouts Sep 15, 2021
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 15, 2021
@karlkfi
Copy link
Contributor Author

karlkfi commented Sep 15, 2021

/hold

This PR needs a lot of work. It's just here for staging until I have time to break it up.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 15, 2021
@k8s-ci-robot
Copy link
Contributor

@karlkfi: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 17, 2021
@karlkfi
Copy link
Contributor Author

karlkfi commented Oct 8, 2021

A large chunk of this PR was extracted to #423

I'm gonna leave this open for a while tho, to remind me to extract some of the other bits that were refactored in this PR.

@karlkfi
Copy link
Contributor Author

karlkfi commented Oct 16, 2021

Global timeout option extracted to #439

Still TODO:

@karlkfi
Copy link
Contributor Author

karlkfi commented Nov 10, 2021

This is obsolete. The improvements have been made in other PRs and logged as backlog issues.

@karlkfi karlkfi closed this Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants