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 mount unmount failure for a Windows pod #63272

Conversation

andyzhangx
Copy link
Member

What this PR does / why we need it:
IsLikelyNotMountPoint func does not return correctly, for invalid symlink, it should return true(not a mount point), now it will always return false:

func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) {
stat, err := os.Lstat(file)
if err != nil {
return true, err
}
// If current file is a symlink, then it is a mountpoint.
if stat.Mode()&os.ModeSymlink != 0 {
return false, nil

func doUnmountMountPoint(mountPath string, mounter mount.Interface, extensiveMountPointCheck bool, corruptedMnt bool) error {
if !corruptedMnt {
var notMnt bool
var err error
if extensiveMountPointCheck {
notMnt, err = mount.IsNotMountPoint(mounter, mountPath)
} else {
notMnt, err = mounter.IsLikelyNotMountPoint(mountPath)
}
if err != nil {
return err
}
if notMnt {
glog.Warningf("Warning: %q is not a mountpoint, deleting", mountPath)
return os.Remove(mountPath)

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #63249

Special notes for your reviewer:

Release note:

fix mount unmount failure for a Windows pod

/sig windows
/assign @msau42

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/windows Categorizes an issue or PR as relevant to SIG Windows. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 28, 2018
@andyzhangx
Copy link
Member Author

/test pull-kubernetes-cross

@andyzhangx andyzhangx force-pushed the IsLikelyNotMountPoint-windows-fix branch from 1c1dfda to 4e92e60 Compare April 28, 2018 06:46

for _, test := range tests {
filePath := filepath.Join(base, test.fileName)
if test.fileValid {
Copy link
Member

Choose a reason for hiding this comment

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

You could potentially pass in a setup method per test case, instead of combining all the scenarios here, to make it easier to comprehend each test case separately.

Copy link
Member Author

Choose a reason for hiding this comment

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

@msau42 thanks for the suggestion, I have made a new commit with setUp func, the test code is more clear now

@andyzhangx andyzhangx force-pushed the IsLikelyNotMountPoint-windows-fix branch from 4e92e60 to f3698b0 Compare May 1, 2018 02:40
Copy link
Member Author

@andyzhangx andyzhangx left a comment

Choose a reason for hiding this comment

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

@msau42 thanks for the suggestion, I have made a new commit with setUp func, the test code is more clear now


for _, test := range tests {
filePath := filepath.Join(base, test.fileName)
if test.fileValid {
Copy link
Member Author

Choose a reason for hiding this comment

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

@msau42 thanks for the suggestion, I have made a new commit with setUp func, the test code is more clear now

@andyzhangx
Copy link
Member Author

/test pull-kubernetes-cross

@andyzhangx
Copy link
Member Author

/test pull-kubernetes-verify

2 similar comments
@andyzhangx
Copy link
Member Author

/test pull-kubernetes-verify

@andyzhangx
Copy link
Member Author

/test pull-kubernetes-verify

@andyzhangx
Copy link
Member Author

@msau42 PTAL, thanks.


func TestIsLikelyNotMountPoint(t *testing.T) {
mounter := Mounter{"fake/path"}
base, err := ioutil.TempDir("", "TestIsLikelyNotMountPoint")
Copy link
Member

Choose a reason for hiding this comment

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

Should you make the TempDir per test case so that you won't run into name collision issues?

Copy link
Member Author

Choose a reason for hiding this comment

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

@msau42 I have already merged a PR: #63399 which fixes this issue, and also rebased on the latest master branch, now every test case in mount_windows_test.go will make TempDir

Copy link
Member

Choose a reason for hiding this comment

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

I actually mean each test case in tests uses a new tmpdir. That way you don't need to rely on each test case filename to be unique

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @msau42 actually ioutil.TempDir("", "") will create a new tmpdir with a unique name, add a prefix like "TestIsLikelyNotMountPoint" is for debugging purpose, so when it fails, I could comment out defer os.RemoveAll(base) and find the tmp directory easily. Anyway, whether I set prefix or not, ioutil.TempDir will still create a unique dir.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry I think I'm not being clear. I was suggesting a new tempdir for each iteration in the testcase loop

Copy link
Member Author

Choose a reason for hiding this comment

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

@msau42 good point, I have changed the test case, create a new tempdir for every single test case, PTAL

@andyzhangx andyzhangx force-pushed the IsLikelyNotMountPoint-windows-fix branch from f3698b0 to 51b0649 Compare May 8, 2018 05:51
fix comments

fix comments on unit test

fix comments
@andyzhangx andyzhangx force-pushed the IsLikelyNotMountPoint-windows-fix branch from 51b0649 to 1d24f48 Compare May 9, 2018 02:41
@msau42
Copy link
Member

msau42 commented May 9, 2018

/lgtm

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

/test pull-kubernetes-e2e-gce

@andyzhangx
Copy link
Member Author

/assign @jsafrane PTAL, thanks

@andyzhangx
Copy link
Member Author

/test pull-kubernetes-bazel-test
/test pull-kubernetes-e2e-kops-aws

@jsafrane
Copy link
Member

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andyzhangx, jsafrane, msau42

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 15, 2018
@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@andyzhangx
Copy link
Member Author

/test pull-kubernetes-integration

@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 89b747b into kubernetes:master May 15, 2018
andyzhangx added a commit to andyzhangx/kubernetes that referenced this pull request Jun 8, 2018
k8s-github-robot pushed a commit that referenced this pull request Jun 26, 2018
…3272-upstream-release-1.9

Automatic merge from submit-queue.

Automated cherry pick of #63272: fix IsLikelyNotMountPoint func on Windows

Cherry pick of #63272 on release-1.9.

#63272: fix IsLikelyNotMountPoint func on Windows
k8s-github-robot pushed a commit that referenced this pull request Jul 20, 2018
…3272-upstream-release-1.10

Automatic merge from submit-queue.

Automated cherry pick of #63272: fix IsLikelyNotMountPoint func on Windows

Cherry pick of #63272 on release-1.10.

#63272: fix IsLikelyNotMountPoint func on Windows
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 Denotes a PR that will be considered when it comes time to generate release notes. sig/windows Categorizes an issue or PR as relevant to SIG Windows. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Windows pod with azure disk mount is in terminating state forever
5 participants