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

dockershim/sandbox: clean up pod network even if SetUpPod() failed #62874

Conversation

dcbw
Copy link
Member

@dcbw dcbw commented Apr 19, 2018

If the CNI network plugin completes successfully, but something fails
between that success and dockerhsim's sandbox setup code, plugin resources
may not be cleaned up. A non-trivial amount of code runs after the
plugin itself exits and the CNI driver's SetUpPod() returns, and any error
condition recognized by that code would cause this leakage.

The Kubernetes CRI RunPodSandbox() request does not attempt to clean
up on errors, since it cannot know how much (if any) networking
was actually set up. It depends on the CRI implementation to do
that cleanup for it.

In the dockershim case, a SetUpPod() failure means networkReady is
FALSE for the sandbox, and TearDownPod() will not be called later by
garbage collection even though networking was configured, because
dockershim can't know how far SetUpPod() got.

Concrete examples include if the sandbox's container is somehow
removed during during that time, or another OS error is encountered,
or the plugin returns a malformed result to the CNI driver.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1532965

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 19, 2018
@dcbw dcbw requested review from freehan and Random-Liu April 19, 2018 19:35
@dcbw
Copy link
Member Author

dcbw commented Apr 19, 2018

/test pull-kubernetes-e2e-gce

@dcbw
Copy link
Member Author

dcbw commented Apr 19, 2018

/test pull-kubernetes-local-e2e-containerized

// TODO(random-liu): Do we need to teardown network here?
// Ensure network resources are cleaned up even if the plugin
// succeeded but an error happened between that success and here.
ds.network.TearDownPod(config.GetMetadata().Namespace, config.GetMetadata().Name, cID)
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure if it's OK to skip error of TearDownPod here, maybe a warning at least?

Copy link
Member Author

Choose a reason for hiding this comment

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

@resouer done

@dcbw dcbw force-pushed the dockershim-SetUpPod-cleanup-on-failure branch from 6dddcd9 to 135a2f4 Compare April 20, 2018 15:51
@dcbw
Copy link
Member Author

dcbw commented Apr 20, 2018

/retest

@dcbw
Copy link
Member Author

dcbw commented Apr 20, 2018

/test pull-kubernetes-kubemark-e2e-gce

1 similar comment
@dcbw
Copy link
Member Author

dcbw commented Apr 23, 2018

/test pull-kubernetes-kubemark-e2e-gce

@dcbw
Copy link
Member Author

dcbw commented Apr 23, 2018

@resouer @danwinship PTAL, and if it's OK an lgtm would be awesome, thanks!

// Ensure network resources are cleaned up even if the plugin
// succeeded but an error happened between that success and here.
if err := ds.network.TearDownPod(config.GetMetadata().Namespace, config.GetMetadata().Name, cID); err != nil {
glog.Warningf("Failed to clean up sandbox container %q network for pod %q: %v", createResp.ID, config.Metadata.Name, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm... is this going to cause spurious warnings? (Since TearDownPod may not deal well with being called on an only-partially-SetUp pod)

Also, this warning will end up getting printed before the SetUpPod() result, which will make it look in the logs like the TearDownPod failure is the cause of the SetUpPod() failure, rather than a result of it. (Though I guess that's true of the StopContainer() code below too...)

Copy link
Contributor

Choose a reason for hiding this comment

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

How about making the warning message more narrative? Like:

My original concern is: if we failed to ensure ns clean up, we should let users know, as there maybe garbage left behind.

Copy link
Member Author

Choose a reason for hiding this comment

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

@danwinship better now? Uses NewAggregate() to combine errors in the correct order.

@dcbw dcbw force-pushed the dockershim-SetUpPod-cleanup-on-failure branch from 135a2f4 to fa8c283 Compare April 24, 2018 16:16
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Apr 24, 2018
If the CNI network plugin completes successfully, but something fails
between that success and dockerhsim's sandbox setup code, plugin resources
may not be cleaned up. A non-trivial amount of code runs after the
plugin itself exits and the CNI driver's SetUpPod() returns, and any error
condition recognized by that code would cause this leakage.

The Kubernetes CRI RunPodSandbox() request does not attempt to clean
up on errors, since it cannot know how much (if any) networking
was actually set up. It depends on the CRI implementation to do
that cleanup for it.

In the dockershim case, a SetUpPod() failure means networkReady is
FALSE for the sandbox, and TearDownPod() will not be called later by
garbage collection even though networking was configured, because
dockershim can't know how far SetUpPod() got.

Concrete examples include if the sandbox's container is somehow
removed during during that time, or another OS error is encountered,
or the plugin returns a malformed result to the CNI driver.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1532965
@dcbw dcbw force-pushed the dockershim-SetUpPod-cleanup-on-failure branch from fa8c283 to 91321ef Compare April 24, 2018 16:23
@dcbw
Copy link
Member Author

dcbw commented Apr 24, 2018

/test pull-kubernetes-e2e-kops-aws

@danwinship
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 24, 2018
@dcbw
Copy link
Member Author

dcbw commented Apr 24, 2018

/test pull-kubernetes-e2e-kops-aws

@yujuhong
Copy link
Contributor

/lgtm

@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 24, 2018
@dcbw
Copy link
Member Author

dcbw commented Apr 24, 2018

/test pull-kubernetes-e2e-kops-aws

@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Apr 24, 2018

@dcbw: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-kubernetes-local-e2e-containerized 6dddcd9722ab0b459823212f02f3232f2901ca37 link /test pull-kubernetes-local-e2e-containerized

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.

@resouer
Copy link
Contributor

resouer commented Apr 25, 2018

/lgtm

Thanks for quick fix!

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: danwinship, dcbw, resouer, yujuhong

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

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel comment for consistent failures.

@k8s-github-robot
Copy link

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 61892ab into kubernetes:master Apr 25, 2018
dcbw added a commit to dcbw/origin that referenced this pull request May 1, 2018
…UpPod() failed

If the CNI network plugin completes successfully, but something fails
between that success and dockerhsim's sandbox setup code, plugin resources
may not be cleaned up. A non-trivial amount of code runs after the
plugin itself exits and the CNI driver's SetUpPod() returns, and any error
condition recognized by that code would cause this leakage.

The Kubernetes CRI RunPodSandbox() request does not attempt to clean
up on errors, since it cannot know how much (if any) networking
was actually set up. It depends on the CRI implementation to do
that cleanup for it.

In the dockershim case, a SetUpPod() failure means networkReady is
FALSE for the sandbox, and TearDownPod() will not be called later by
garbage collection even though networking was configured, because
dockershim can't know how far SetUpPod() got.

Concrete examples include if the sandbox's container is somehow
removed during during that time, or another OS error is encountered,
or the plugin returns a malformed result to the CNI driver.

Upstream: kubernetes/kubernetes#62874
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1532965
dcbw added a commit to dcbw/origin that referenced this pull request May 1, 2018
…UpPod() failed

If the CNI network plugin completes successfully, but something fails
between that success and dockerhsim's sandbox setup code, plugin resources
may not be cleaned up. A non-trivial amount of code runs after the
plugin itself exits and the CNI driver's SetUpPod() returns, and any error
condition recognized by that code would cause this leakage.

The Kubernetes CRI RunPodSandbox() request does not attempt to clean
up on errors, since it cannot know how much (if any) networking
was actually set up. It depends on the CRI implementation to do
that cleanup for it.

In the dockershim case, a SetUpPod() failure means networkReady is
FALSE for the sandbox, and TearDownPod() will not be called later by
garbage collection even though networking was configured, because
dockershim can't know how far SetUpPod() got.

Concrete examples include if the sandbox's container is somehow
removed during during that time, or another OS error is encountered,
or the plugin returns a malformed result to the CNI driver.

Upstream: kubernetes/kubernetes#62874
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1532965
(cherry picked from commit 08bdb94)
openshift-publish-robot pushed a commit to openshift/kubernetes that referenced this pull request May 7, 2018
…UpPod() failed

If the CNI network plugin completes successfully, but something fails
between that success and dockerhsim's sandbox setup code, plugin resources
may not be cleaned up. A non-trivial amount of code runs after the
plugin itself exits and the CNI driver's SetUpPod() returns, and any error
condition recognized by that code would cause this leakage.

The Kubernetes CRI RunPodSandbox() request does not attempt to clean
up on errors, since it cannot know how much (if any) networking
was actually set up. It depends on the CRI implementation to do
that cleanup for it.

In the dockershim case, a SetUpPod() failure means networkReady is
FALSE for the sandbox, and TearDownPod() will not be called later by
garbage collection even though networking was configured, because
dockershim can't know how far SetUpPod() got.

Concrete examples include if the sandbox's container is somehow
removed during during that time, or another OS error is encountered,
or the plugin returns a malformed result to the CNI driver.

Upstream: kubernetes#62874
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1532965

Origin-commit: 08bdb948741668e8d99923c89efc8f14990355b3
dcbw added a commit to dcbw/origin that referenced this pull request May 9, 2018
…UpPod() failed

If the CNI network plugin completes successfully, but something fails
between that success and dockerhsim's sandbox setup code, plugin resources
may not be cleaned up. A non-trivial amount of code runs after the
plugin itself exits and the CNI driver's SetUpPod() returns, and any error
condition recognized by that code would cause this leakage.

The Kubernetes CRI RunPodSandbox() request does not attempt to clean
up on errors, since it cannot know how much (if any) networking
was actually set up. It depends on the CRI implementation to do
that cleanup for it.

In the dockershim case, a SetUpPod() failure means networkReady is
FALSE for the sandbox, and TearDownPod() will not be called later by
garbage collection even though networking was configured, because
dockershim can't know how far SetUpPod() got.

Concrete examples include if the sandbox's container is somehow
removed during during that time, or another OS error is encountered,
or the plugin returns a malformed result to the CNI driver.

Upstream: kubernetes/kubernetes#62874
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1532965
openshift-publish-robot pushed a commit to openshift/kubernetes that referenced this pull request May 9, 2018
…UpPod() failed

If the CNI network plugin completes successfully, but something fails
between that success and dockerhsim's sandbox setup code, plugin resources
may not be cleaned up. A non-trivial amount of code runs after the
plugin itself exits and the CNI driver's SetUpPod() returns, and any error
condition recognized by that code would cause this leakage.

The Kubernetes CRI RunPodSandbox() request does not attempt to clean
up on errors, since it cannot know how much (if any) networking
was actually set up. It depends on the CRI implementation to do
that cleanup for it.

In the dockershim case, a SetUpPod() failure means networkReady is
FALSE for the sandbox, and TearDownPod() will not be called later by
garbage collection even though networking was configured, because
dockershim can't know how far SetUpPod() got.

Concrete examples include if the sandbox's container is somehow
removed during during that time, or another OS error is encountered,
or the plugin returns a malformed result to the CNI driver.

Upstream: kubernetes#62874
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1532965

Origin-commit: 2ad8991a3fed1c3ba84b8baf853f8bb8e2a2e6f5
liggitt pushed a commit to liggitt/kubernetes that referenced this pull request May 11, 2018
…UpPod() failed

If the CNI network plugin completes successfully, but something fails
between that success and dockerhsim's sandbox setup code, plugin resources
may not be cleaned up. A non-trivial amount of code runs after the
plugin itself exits and the CNI driver's SetUpPod() returns, and any error
condition recognized by that code would cause this leakage.

The Kubernetes CRI RunPodSandbox() request does not attempt to clean
up on errors, since it cannot know how much (if any) networking
was actually set up. It depends on the CRI implementation to do
that cleanup for it.

In the dockershim case, a SetUpPod() failure means networkReady is
FALSE for the sandbox, and TearDownPod() will not be called later by
garbage collection even though networking was configured, because
dockershim can't know how far SetUpPod() got.

Concrete examples include if the sandbox's container is somehow
removed during during that time, or another OS error is encountered,
or the plugin returns a malformed result to the CNI driver.

Upstream: kubernetes#62874
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1532965
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. 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.

7 participants