Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@haircommander
Copy link
Member

What type of PR is this?

/kind bug

/kind cleanup
/kind dependency-change
/kind deprecation
/kind design
/kind documentation
/kind failing-test
/kind feature
/kind flake

What this PR does / why we need it:

This PR changes the behavior of container and pod creation to save the progress of a creation request if we timeout, and quickly return that progress if it's re-requested.

Specifically, it adds

  • ResourceCache package, which keeps track of pods and containers between a timed out request and a successful one
  • updates server to save the progress of a pod or container request
  • add unit tests and integration tests
  • have each new request watch the resource and wait until it's created. This is important because currently this situation causes cri-o to spam the kubelet with "name is reserved" errors. Waiting until the resource is created (or for a timeout) will significantly reduce the number of these errors, making a standard error seem less catastrophic

This is carrying #4266, plus adding the watcher idiom.

Which issue(s) this PR fixes:

fixes #4221

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Fix a bug where a timeout in RunPodSandbox or CreateContainer requests caused CRI-O to delete the newly created resource. Now, it saves that resource, until the kubelet re-requests it, thus allowing kubelet and CRI-O to reconcile quicker when nodes are under load.

@openshift-ci-robot openshift-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. kind/bug Categorizes issue or PR as related to a bug. labels Nov 30, 2020
@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 30, 2020
@haircommander haircommander changed the title Handle timeout backup Improve timeout handling Nov 30, 2020
@haircommander
Copy link
Member Author

A week ago I was able to verify this fix worked.
using https://github.com/RobertKrawitz/OpenShift4-tools/blob/master/clusterbuster and an openshift cluster with and without these patches lead to these two reports (using https://github.com/RobertKrawitz/OpenShift4-tools/blob/master/monitor-pod-status to generate the report):

./clusterbuster -P server -b 5 -c 1 -p 10 -r 4 -N 75 -d 2 --parallel-deployments=2 --bytes=750000

without this patch:

15:17:36 Pods: 0P 0R 0C 0O 0T 0E 0X 0I 0U  / 0   NS: 0A 0T  / 0   Sec: 0A 0S    Node: 3R 0N  / 3 
15:18:36 Pods: 0P 25R 0C 55O 0T 0E 0X 0I 0U  / 80   NS: 75A 0T  / 75   Sec: 0A 675S    Node: 3R 0N  / 3 
15:19:36 Pods: 62P 53R 0C 231O 0T 0E 0X 0I 0U  / 346   NS: 75A 0T  / 75   Sec: 0A 675S    Node: 3R 0N  / 3 
15:20:36 Pods: 98P 97R 0C 446O 0T 0E 0X 0I 0U  / 641   NS: 75A 0T  / 75   Sec: 0A 675S    Node: 3R 0N  / 3 
15:21:36 Pods: 80P 167R 0C 503O 0T 0E 0X 0I 0U  / 750   NS: 75A 0T  / 75   Sec: 0A 675S    Node: 3R 0N  / 3 
15:22:36 Pods: 54P 258R 0C 438O 0T 0E 0X 0I 0U  / 750   NS: 75A 0T  / 75   Sec: 0A 675S    Node: 3R 0N  / 3 
15:23:40 Pods: 54P 413R 0C 264O 0T 0E 19X 0I 0U  / 750   NS: 75A 0T  / 75   Sec: 0A 675S    Node: 3R 0N  / 3 
15:24:36 Pods: 54P 420R 0C 232O 0T 0E 44X 0I 0U  / 750   NS: 75A 0T  / 75   Sec: 0A 675S    Node: 2R 1N  / 3 
15:25:36 Pods: 54P 432R 0C 181O 0T 0E 83X 0I 0U  / 750   NS: 75A 0T  / 75   Sec: 0A 675S    Node: 2R 1N  / 3 
15:26:36 Pods: 54P 432R 0C 181O 0T 0E 83X 0I 0U  / 750   NS: 75A 0T  / 75   Sec: 0A 675S    Node: 1R 2N  / 3 
15:27:39 Pods: 54P 432R 0C 181O 0T 0E 83X 0I 0U  / 750   NS: 75A 0T  / 75   Sec: 0A 675S    Node: 1R 2N  / 3 
15:28:39 Pods: 54P 432R 0C 181O 0T 0E 83X 0I 0U  / 750   NS: 75A 0T  / 75   Sec: 0A 675S    Node: 1R 2N  / 3 

with this patch:

15:56:03 Pods: 0P 0R 0C 0O 0T 0E 0X 0I 0U  / 0   NS: 0A 0T  / 0   Sec: 0A 0S    Node: 3R 0N  / 3 
15:57:03 Pods: 11P 95R 0C 91O 0T 0E 0X 0I 0U  / 197   NS: 75A 0T  / 75   Sec: 0A 675S    Node: 3R 0N  / 3 
15:58:05 Pods: 48P 221R 0C 196O 0T 0E 0X 0I 0U  / 465   NS: 75A 0T  / 75   Sec: 0A 675S    Node: 3R 0N  / 3 
15:59:05 Pods: 132P 286R 0C 288O 0T 0E 0X 0I 0U  / 706   NS: 75A 0T  / 75   Sec: 0A 675S    Node: 3R 0N  / 3 
16:00:03 Pods: 125P 358R 0C 267O 0T 0E 0X 0I 0U  / 750   NS: 75A 0T  / 75   Sec: 0A 675S    Node: 3R 0N  / 3 
16:01:06 Pods: 97P 482R 0C 171O 0T 0E 0X 0I 0U  / 750   NS: 75A 0T  / 75   Sec: 0A 675S    Node: 3R 0N  / 3 
16:02:04 Pods: 96P 558R 0C 96O 0T 0E 0X 0I 0U  / 750   NS: 75A 0T  / 75   Sec: 0A 675S    Node: 2R 1N  / 3 
16:03:04 Pods: 96P 558R 0C 96O 0T 0E 0X 0I 0U  / 750   NS: 75A 0T  / 75   Sec: 0A 675S    Node: 1R 2N  / 3

Note: both clusters did eventually fail (the test case specifically had to overload it to trigger this situation) but with the patches we were able to get more pods running (558R vs 432R). Also note in the "with patch" case, we have 0X which means 0 container create errors vs 83X or 83 containers that were spamming kubelet logs with "name is reserved" errors

@haircommander haircommander added this to the 1.20 milestone Nov 30, 2020
@codecov
Copy link

codecov bot commented Nov 30, 2020

Codecov Report

Merging #4394 (cfdf40e) into master (8b67a70) will increase coverage by 0.07%.
The diff coverage is 44.18%.

@@            Coverage Diff             @@
##           master    #4394      +/-   ##
==========================================
+ Coverage   40.50%   40.57%   +0.07%     
==========================================
  Files         116      117       +1     
  Lines        9330     9407      +77     
==========================================
+ Hits         3779     3817      +38     
- Misses       5125     5164      +39     
  Partials      426      426              

@haircommander
Copy link
Member Author

/retest

@haircommander
Copy link
Member Author

/retest

1 similar comment
@saschagrunert
Copy link
Member

/retest

Copy link
Member

@saschagrunert saschagrunert left a comment

Choose a reason for hiding this comment

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

LGTM

@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: haircommander, saschagrunert

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

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [haircommander,saschagrunert]

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

@haircommander haircommander force-pushed the handle-timeout-backup branch 4 times, most recently from d7343e5 to 89ed57b Compare December 1, 2020 19:56
@haircommander
Copy link
Member Author

/retest

Copy link
Contributor

@fidencio fidencio left a comment

Choose a reason for hiding this comment

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

@haircommander, a few basic comments but looks good in general.

@haircommander
Copy link
Member Author

blocked on #4241 btw

@fidencio
Copy link
Contributor

fidencio commented Dec 2, 2020

LGTM

@haircommander
Copy link
Member Author

/retest

@haircommander
Copy link
Member Author

/cherry-pick release-1.20

@openshift-cherrypick-robot

@haircommander: once the present PR merges, I will cherry-pick it on top of release-1.20 in a new PR and assign it to you.

Details

In response to this:

/cherry-pick release-1.20

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.

@mrunalp
Copy link
Member

mrunalp commented Dec 8, 2020

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 8, 2020
ResourceCache is a structure that keeps track of partially created Pods and Containers.
Its features include:
- tracking pods and containers after their initial creation times out
- automatic garbage collection (after a timer)

Signed-off-by: Peter Hunt <[email protected]>
Before when a client's request for a RunPodSandbox or ContainerCreate timed out, CRI-O would clean up the resource.

However, these requests usually fail when the node is under load. In these cases, it would be better to hold onto the progress,
not get rid of it.

This commit uses the previously created ResourceCache to cache the progress of a container creation and sandbox run.
When a duplicate name is detected, before erroring, the server checks in the ResourceCache to see if we've already
successfully created that resource. If so, we return it as if we'd just created it.

It also moves the SetCreated call to after the resource is deemed as not having timed out.

Hopefully, this reduces the load on already overloaded nodes.

Signed-off-by: Peter Hunt <[email protected]>
Even if we use the resource cache as is, the user is still bombarded with messages saying the name is reserved.

This is bad UX, and we're capable of improving it.

Add watcher idiom to resource cache, allowing a handler routine of RunPodSandbox or CreateContainer to
wait for a resource to be available.

Something that is key here is if the resource becomes available while we're watching for it,
*we still need to error on this request*
This is because we could get the resource from the cache, remove it (thus meaning it won't be cleaned up),
and the kubelet's request could time out, and it could try again. This would cause us to leak a resource.

This way, if we get into this situation, there needs to be three requests:
first that times out
second that discovers the resource is ready, but still errors
third that actually retrives that resource and returns it.

This will result in many fewer "name is reserved" errors (one every 2 seconds to one every 4 minutes)

Signed-off-by: Peter Hunt <[email protected]>
Now that we plan on caching the results of a pod sandbox creation, we shouldn't short circut the
network creation. In a perfect world, we'd give the CNI plugin unbounded time, which would allow
us to reuse even the longest of CNI creation time. However, this leads to the chance that the
CNI plugin runs forever, which is not ideal.

Instead, give the sandbox network creation 5 minutes (a minute more than the full request),
to improve the odds we have a completed sandbox that can be reused, rather than thrown away.

Signed-off-by: Peter Hunt <[email protected]>
timeout.bats is a test suite that tests different scenerios regarding to timeouts in
sandbox running and container creation.

It requires a crictl that knows about the -T option

Signed-off-by: Peter Hunt <[email protected]>
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Dec 8, 2020
@haircommander
Copy link
Member Author

there was a flake with the tests, I tweaked it a bit, I think this should be better

@mrunalp
Copy link
Member

mrunalp commented Dec 8, 2020

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 8, 2020
@haircommander
Copy link
Member Author

/retest

1 similar comment
@haircommander
Copy link
Member Author

/retest

@openshift-merge-robot
Copy link
Contributor

@haircommander: The following test failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
ci/prow/e2e-agnostic cfdf40e link /test e2e-agnostic

Full PR test history. Your PR dashboard.

Details

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.

@openshift-cherrypick-robot

@haircommander: new pull request created: #4421

Details

In response to this:

/cherry-pick release-1.20

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.


// Put takes a unique resource name (retrieved from the client request, not generated by the server)
// a newly created resource, and functions to cleanup that newly created resource.
// It adds the Resource to the ResourceStore, as well as starts a go routine that is responsible for cleaning up the
Copy link
Collaborator

Choose a reason for hiding this comment

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

the part about go routine is obsoleted

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. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CRI-O should be smarter about context timeouts

9 participants