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

Fix: Pod terminating stuck because of trying to umount not actual mounted dir #114605

Merged
merged 2 commits into from Feb 1, 2023
Merged

Fix: Pod terminating stuck because of trying to umount not actual mounted dir #114605

merged 2 commits into from Feb 1, 2023

Conversation

mochizuki875
Copy link
Member

@mochizuki875 mochizuki875 commented Dec 20, 2022

What type of PR is this?

/kind bug

What this PR does / why we need it:

Fix the problem Pod terminating stuck because of trying to umount not actual mounted dir.
In addition, I refactored releted methods and functions.

Which issue(s) this PR fixes:

Fixes #114546

Special notes for your reviewer:

NONE

Does this PR introduce a user-facing change?

Fix the problem Pod terminating stuck because of trying to umount not actual mounted dir.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. kind/bug Categorizes issue or PR as related to a bug. 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. labels Dec 20, 2022
@k8s-ci-robot
Copy link
Contributor

Welcome @mochizuki875!

It looks like this is your first PR to kubernetes/kubernetes 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kubernetes has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 20, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @mochizuki875. 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.

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-priority Indicates a PR lacks a `priority/foo` label and requires one. label Dec 20, 2022
@k8s-ci-robot k8s-ci-robot added sig/storage Categorizes an issue or PR as relevant to SIG Storage. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Dec 20, 2022
@mochizuki875
Copy link
Member Author

/sig storage

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Dec 20, 2022
@msau42
Copy link
Member

msau42 commented Dec 22, 2022

/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 Dec 22, 2022
@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 3, 2023
@mochizuki875
Copy link
Member Author

Hi @andyzhangx , thank you for fixing the issue #114736.
Actually, I've come accross the same issue using In-Tree NFS Volume Plugin(#114546) and try to fix it in this PR.
This PR has the same fixes as your PR, with the addition of using common variable names and logic for Unmount, tryUnmount, and forceUmount.
So could you please check this PR?

@mochizuki875
Copy link
Member Author

/sig node

@k8s-ci-robot k8s-ci-robot added the sig/node Categorizes an issue or PR as relevant to SIG Node. label Jan 4, 2023
@andyzhangx
Copy link
Member

Hi @andyzhangx , thank you for fixing the issue #114736. Actually, I've come accross the same issue using In-Tree NFS Volume Plugin(#114546) and try to fix it in this PR. This PR has the same fixes as your PR, with the addition of using common variable names and logic for Unmount, tryUnmount, and forceUmount. So could you please check this PR?

@mochizuki875 could you point out which line of code fix the original nfs unmount stuck issue in this PR? thanks.

@mochizuki875
Copy link
Member Author

mochizuki875 commented Jan 4, 2023

@andyzhangx
Thank you for your reply!
When Pod is terminated, NFS VolumePlugin calls CleanupMountWithForce.

return mount.CleanupMountWithForce(dir, forceUnmounter, true /* extensiveMountPointCheck */, unMountTimeout)

And then, calls UnmountWithForce.

if err := mounter.UnmountWithForce(mountPath, umountTimeout); err != nil {

Finally, tryUnmount and forceUmount are called.
https://github.com/kubernetes/kubernetes/blob/891eb75b8956c94c59dbfab29e78f12863202088/staging/src/k8s.io/mount-utils/mount_linux.go#L373-L383

Before your PR(#114736), there was not the check logic of umount result in tryUnmount and forceUmount, so an error occured and kubelet could not finish the terminating proccess of Pod if NFS volume is not mounted to Pod.(In this case, umount command returns "not mounted".)
So I added checkUmountError function as a common logic to check a result of umount command.
https://github.com/kubernetes/kubernetes/blob/891eb75b8956c94c59dbfab29e78f12863202088/staging/src/k8s.io/mount-utils/mount_linux.go#L796-L811

And I implemented checkUmountError to Unmount, tryUnmount, and forceUmount because they need same logic to check a result of umount command.

https://github.com/kubernetes/kubernetes/blob/891eb75b8956c94c59dbfab29e78f12863202088/staging/src/k8s.io/mount-utils/mount_linux.go#L361-L369
https://github.com/kubernetes/kubernetes/blob/891eb75b8956c94c59dbfab29e78f12863202088/staging/src/k8s.io/mount-utils/mount_linux.go#L766-L794

Also, although it is a small detail, the names of variables that indicate the same meaning were different between Unmount, tryUnmount, and forceUmount(ex. target and path, command and cmd), so I corrected to common names.

@bart0sh
Copy link
Contributor

bart0sh commented Jan 6, 2023

/priority important-soon
/triage accepted

@k8s-ci-robot k8s-ci-robot added priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. triage/accepted Indicates an issue or PR is ready to be actively worked on. labels Jan 6, 2023
SIG Node PR Triage automation moved this from Needs Reviewer to Done Feb 1, 2023
@k8s-ci-robot k8s-ci-robot added this to the v1.27 milestone Feb 1, 2023
@mochizuki875 mochizuki875 deleted the feature_114546 branch February 1, 2023 15:26
@@ -620,3 +621,28 @@ func makeFakeCommandAction(stdout string, err error) testexec.FakeCommandAction
return testexec.InitFakeCmd(&c, cmd, args...)
}
}

func TestNotMountedBehaviorOfUnmount(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

This breaks running unit tests without superuser mode

Running unit tests downstream, this is the only failing unit test:

{Failed  === RUN   TestNotMountedBehaviorOfUnmount
    mount_linux_test.go:719: Expect complete Unmount(), but it dose not: unmount failed: exit status 32
        Unmounting arguments: /tmp/kubelet-umount2687109515
        Output: umount: /tmp/kubelet-umount2687109515: must be superuser to unmount.
    mount_linux_test.go:723: Expect complete tryUnmount(), but it does not: unmount failed: exit status 32
        Unmounting arguments: /tmp/kubelet-umount2687109515
        Output: umount: /tmp/kubelet-umount2687109515: must be superuser to unmount.
    mount_linux_test.go:729: Expect complete forceUnmount(), but it does not: unmount failed: exit status 32
        Unmounting arguments: /tmp/kubelet-umount2687109515
        Output: umount: /tmp/kubelet-umount2687109515: must be superuser to unmount.
--- FAIL: TestNotMountedBehaviorOfUnmount (0.03s)

Copy link
Member

Choose a reason for hiding this comment

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

Opened a revert: #115732

k8s-ci-robot added a commit that referenced this pull request Feb 13, 2023
Revert #114605: its unit test requires root permission
mochizuki875 added a commit to mochizuki875/kubernetes that referenced this pull request Feb 14, 2023
k8s-ci-robot added a commit that referenced this pull request Mar 8, 2023
…t-test

Revert "Revert #114605: its unit test requires root permission"
dlipovetsky pushed a commit to dlipovetsky/kubernetes that referenced this pull request Apr 6, 2023
Fix: Pod terminating stuck because of trying to umount not actual mounted dir
@saurav-agarwalla
Copy link

Are there any plans to backport this to older Kubernetes versions? This seems like a critical fix.

@humblec
Copy link
Contributor

humblec commented Jul 5, 2023

@ljosyula considering you have filed the PRs for 1.25 and 1.26, can you file one for 1.24 as well?

cartermckinnon pushed a commit to cartermckinnon/kubernetes that referenced this pull request Aug 8, 2023
cartermckinnon pushed a commit to cartermckinnon/kubernetes that referenced this pull request Aug 8, 2023
k8s-ci-robot added a commit that referenced this pull request Sep 6, 2023
…of-#115769-upstream-release-1.26

Automated cherry pick of #115769: Revert "Revert #114605: its unit test requires root
k8s-ci-robot added a commit that referenced this pull request Sep 6, 2023
…of-#115769-upstream-release-1.25

Automated cherry pick of #115769: Revert "Revert #114605: its unit test requires root
rayowang pushed a commit to rayowang/kubernetes that referenced this pull request Feb 9, 2024
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. 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. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Development

Successfully merging this pull request may close these issues.

Pod terminating stuck because of trying to umount not actual mounted dir