Skip to content

Conversation

@dobsonj
Copy link
Member

@dobsonj dobsonj commented Jun 3, 2021

What type of PR is this?

/kind bug

What this PR does / why we need it:

See issue #101911 for the full story. It is possible in some situations for the volume of a terminating pod to be added back to the DSW after being removed, because pods are currently added and removed based on two different caches. As a result, the orphaned volume cleanup code can call RemoveAll on the pod dir, which deletes vol_data.json, and causes NodeUnstageVolume to fail when attempting to unmount the volume.

To avoid this issue, this PR instead uses rmdir on the volumes dir during orphaned volume cleanup which will fail if any files are left in the volumes directory. The other subpaths under the pod directory CAN have files that need to be removed during orphan cleanup, so those continue to use RemoveAll.

Here is an example pod directory that needs to be cleaned up:

/var/lib/kubelet/pods/de33b3cd-9542-4245-b20b-892204fa49f5:
containers  etc-hosts  plugins  volumes

This PR recursively calls rmdir on the volumes directory which will be successful only if there are no files or mounts left behind. Then it calls RemoveAll on the other subpaths (containers, etc-hosts, plugins). And if both of those are successful, it calls rmdir on the pod directory itself.

Which issue(s) this PR fixes:

Fixes #101911

Special notes for your reviewer:

cc: @msau42 @gnufied @jingxu97

Does this PR introduce a user-facing change?

NONE

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. kind/bug Categorizes issue or PR as related to a bug. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jun 3, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @dobsonj. Thanks for your PR.

I'm waiting for a kubernetes 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.

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.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. do-not-merge/contains-merge-commits Indicates a PR which contains merge commits. labels Jun 3, 2021
@k8s-ci-robot k8s-ci-robot added area/kubelet sig/node Categorizes an issue or PR as relevant to SIG Node. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jun 3, 2021
@msau42
Copy link
Member

msau42 commented Jun 3, 2021

/ok-to-test
/assign @gnufied @jingxu97

@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 Jun 3, 2021
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/contains-merge-commits Indicates a PR which contains merge commits. label Jun 3, 2021
@dobsonj
Copy link
Member Author

dobsonj commented Jun 4, 2021

/test all
They passed once, and then didn't run again after I removed the merge commit.

@dobsonj
Copy link
Member Author

dobsonj commented Jun 4, 2021

/retest

Copy link
Member

Choose a reason for hiding this comment

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

nit: I would probably move fd.Close in a defer after opening the file and and assumning no errors were thrown.

Copy link
Member Author

Choose a reason for hiding this comment

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

This looks like a deliberate decision in the original implementation. The comment right above that (line 96) says:

// Close directory, because windows won't remove opened directory.

if we were to defer instead, the fd would be closed after the remove() call, which could introduce issues on Windows systems.

Copy link
Member

Choose a reason for hiding this comment

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

ah okay.

Copy link
Member

@gnufied gnufied left a comment

Choose a reason for hiding this comment

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

Is there a way we can add some unit tests for this?

@dobsonj
Copy link
Member Author

dobsonj commented Jun 7, 2021

Is there a way we can add some unit tests for this?

Yes, I added one new test case for kubelet_volumes (where cleanupOrphanedPodDirs is tested), along with a new set of tests for RemoveDirsOneFilesystem.

@dobsonj
Copy link
Member Author

dobsonj commented Jun 7, 2021

/test all

@dobsonj dobsonj marked this pull request as ready for review June 7, 2021 19:47
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 15, 2021
@dobsonj
Copy link
Member Author

dobsonj commented Jun 21, 2021

@liggitt @ehashman any other feedback on this PR? I'd like to move it forward if I've addressed your comments.

@gnufied
Copy link
Member

gnufied commented Jun 21, 2021

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 21, 2021
@liggitt
Copy link
Member

liggitt commented Jun 23, 2021

I'll defer to node/storage approvers on this one. Once this has approval from them, I can ack if needed to get the new OWNERS file in place.

@gnufied
Copy link
Member

gnufied commented Jun 23, 2021

/approve

Copy link
Member

@ehashman ehashman left a comment

Choose a reason for hiding this comment

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

I'm not very familiar with this code but the description, test, and implementation in pkg/kubelet/kubelet_volumes.go LGTM with SIG Storage's 👍

Copy link
Member

Choose a reason for hiding this comment

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

@mrunalp
Copy link
Contributor

mrunalp commented Jun 29, 2021

/approve

1 similar comment
@liggitt
Copy link
Member

liggitt commented Jun 29, 2021

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dobsonj, gnufied, liggitt, mrunalp

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:

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 Jun 29, 2021
@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 or /hold comment for consistent failures.

1 similar 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 or /hold comment for consistent failures.

@k8s-ci-robot k8s-ci-robot merged commit 756203f into kubernetes:master Jun 29, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.22 milestone Jun 29, 2021
@dobsonj dobsonj deleted the 101911 branch July 22, 2021 22:56
k8s-ci-robot added a commit that referenced this pull request Aug 6, 2021
…576-upstream-release-1.20

Automated cherry pick of #102576: kubelet: do not call RemoveAll on volumes directory for
k8s-ci-robot added a commit that referenced this pull request Aug 6, 2021
…576-upstream-release-1.21

Automated cherry pick of #102576: kubelet: do not call RemoveAll on volumes directory for
k8s-ci-robot added a commit that referenced this pull request Aug 6, 2021
…576-upstream-release-1.19

Automated cherry pick of #102576: kubelet: do not call RemoveAll on volumes directory for
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/kubelet area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note-none Denotes a PR that doesn't merit a release note. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/storage Categorizes an issue or PR as relevant to SIG Storage. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

NodeUnstageVolume not called because unmounter fails when vol_data.json is deleted

10 participants