-
Notifications
You must be signed in to change notification settings - Fork 39.5k
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
Unmount subpath should only scan the first level of files/directories #82698
Unmount subpath should only scan the first level of files/directories #82698
Conversation
Welcome @janario! |
Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA. It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.
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. |
Hi @janario. 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 Once the patch is verified, the new status will be reflected by the 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. |
/ok-to-test |
I signed it |
/retest |
Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA. It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.
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. |
Bug triage for 1.17 here with a gentle reminder that code freeze for this release is on Nov. 18. Is this PR still intended for 1.17? |
It would be good to have it |
@@ -241,7 +241,8 @@ func doCleanSubPaths(mounter mount.Interface, podDir string, volumeName string) | |||
if err = doCleanSubPath(mounter, fullContainerDirPath, filepath.Base(path)); err != nil { | |||
return err | |||
} | |||
return nil | |||
// skip subdirs of the volume: it only matters the first level to unmount, otherwise it would try to unmount subdir of the volume | |||
return filepath.SkipDir |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is going to work when the subpath could be a file. SkipDir will skip the rest of the directory in that case. How about we change this back to use ioutil.ReadDir
? I unfortunately can't remember why I had changed it to Walk in the first place. Thanks for catching this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ioutil.ReadDir
was my first try :) , but I've had some problems in some e2e tests with file stale handle
. I guess ioutil.ReadDir
is too eager
For files I'm expecting them to be in the first level and get unmounted
/var/lib/kubelet/pods/<uid>/volume-subpaths/<volume>/<container name>/0 < my-dir
/var/lib/kubelet/pods/<uid>/volume-subpaths/<volume>/<container name>/1 < my-file
But I'll add a test case to make it sure, I'll send an update here soon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
about the test case, just checked and it is already covered https://github.com/kubernetes/kubernetes/pull/82698/files#r341848461
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The existing case doesn't quite cover the scenario I'm thinking about. According to golang docs, "If the function returns SkipDir when invoked on a non-directory file, Walk skips the remaining files in the containing directory."
Which I think is not what we want? If "0" was a file and "1" was a directory, then I believe that means "1" will get skipped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@msau42
very good point 👍
added case with files and directories
https://github.com/kubernetes/kubernetes/pull/82698/files#diff-b962320d780ac74dffce9da68eda4f4cR551
/var/lib/kubelet/pods/<uid>/volume-subpaths/<volume>/<container name>/0 < my-file0
/var/lib/kubelet/pods/<uid>/volume-subpaths/<volume>/<container name>/1 < my-dir1
/var/lib/kubelet/pods/<uid>/volume-subpaths/<volume>/<container name>/2 < my-dir2
/var/lib/kubelet/pods/<uid>/volume-subpaths/<volume>/<container name>/3 < my-file3
let me know what you think about it
name: "subpath-with-files", | ||
prepare: func(base string) ([]mount.MountPoint, error) { | ||
path := filepath.Join(base, containerSubPathDirectoryName, testVol, "container1", "0") | ||
path2 := filepath.Join(base, containerSubPathDirectoryName, testVol, "container1", "1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's also possible for the path to be a file. Can you add a test case for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was about to add a case for subpath with file, but turns out it already have one test case for that
Do you see something else to cover?
16fc4d1
to
df8841f
Compare
/assign @jsafrane |
@msau42 Thanks for the code review, I've just checked and replied your comments Let me know if you find something else 👍 Also I've re-based master into my branch, it will re-run the tests |
/retest |
Correction: Code freeze is on Thursday, November 14. Sorry for the mix up. |
df8841f
to
4e041a8
Compare
} | ||
return mounts, nil | ||
}, | ||
unmount: func(mountpath string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why we need this unmount function? The RemoveAll
is especially scary if the test gets the path wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is set to test with the FakeMounter
The unmount process expects the directory to be empty after the unmount which will then remove the directory
Using the FakeMounter
I do a clean up, to avoid it to fail in the remove
The bug itself is that without the skipDir it would start to try to unmount all the were inside my volume, which won't exist after the root unmount
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where I'm confused is that there's nothing under the "0", "1", etc test directories?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from the latest changes this is how the files look like:
janario@ubuntu:/tmp/clean-subpaths-subpath-with-files-825360851/volume-subpaths/vol1$ tree .
.
└── container1
├── 0
├── 1
│ └── my-dir-1
├── 2
│ └── my-dir-2
└── 3
5 directories, 2 files
then the filepath.Walk
starts with
- 0 (file): unmount function doesn't do anything because it is a file and the file gets removed here
- 1 (dir with sub dirs): unmount function will remove
my-dir-1
but not1
- 2 (dir with sub dirs): same as dir
1
- 3 (file): same as file
0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but I think I got your point, the scenario is created from my test case, so in the unmount from my scenario should know that my-dir-1
and my-dir-2
will always be empty
so there is no need for a recursive remove
I've just changed it to not recursive remove
let me know what do you think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation! I didn't realize there were directories created underneath, so this makes sense to me.
I contemplated whether or not we should just add the cleanup dir logic to the FakeMounter, but then we would need the RemoveAll to be more generic, and I'm very wary of using RemoveAll anywhere. So I think this is fine.
86e44e8
to
c9e9715
Compare
/test pull-kubernetes-e2e-gce-100-performance |
/test pull-kubernetes-e2e-gce-csi-serial |
/lgtm |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: janario, jsafrane 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 |
Thank you all 😉✌️ |
What type of PR is this?
/kind bug
What this PR does / why we need it:
Scenario:
Cronjobs with volume (nfs) mounted multiple time with different subpaths.
When the pod is deleted it tries to clean up all the mounting folders but it shows a lot of warns from files that are present in my volume itself
When I look the files before the umount
my-dir
is actually in a different path from the one printed out on the warn/var/lib/kubelet/pods/c15338f0-d579-11e9-8725-06831030d3a2/volume-subpaths/janario/app/1/my-dir
not/var/lib/kubelet/pods/c15338f0-d579-11e9-8725-06831030d3a2/volume-subpaths/janario/app/my-dir
Turns out, looking at the code, the umount process (subpath_linux.go doCleanSubPaths
filepath.Walk
) is doing:volume-subpaths/janario/app/1/
['my-dir']subpath_linux.go doCleanSubPaths
should only scans the first level of directories/files which are the actual mounting pointsDoes this PR introduce a user-facing change?: