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 check for subpath source #105512

Merged

Conversation

gnufied
Copy link
Member

@gnufied gnufied commented Oct 6, 2021

Fix #105472

I have verified that this fixes CSI/NFS and other volume types and at the same time it keeps older behaviour for configmaps/secrets etc. This code relies on the fact that most volume types create a mount point in /var/lib/kubelet/pods/xxxx/volumes/ when being mounted. The check here won't work for volume types that don't create mount point for main volume (but it is not a regression, at least). For configmaps etc - no bind mount is created unless user specifies subpaths.

For NFS volume with fix:

9660:I1006 18:38:53.488871  766496 subpath_linux.go:122] Skipping bind-mounting subpath /var/lib/kubelet/pods/f7b2da79-86eb-4a66-a9f8-5f3853c708be/volume-subpaths/manual-pv/sandbox/0, volumePath: /var/lib/kubelet/pods/f7b2da79-86eb-4a66-a9f8-5f3853c708be/volumes/kubernetes.io~nfs/manual-pv, path: /var/lib/kubelet/pods/f7b2da79-86eb-4a66-a9f8-5f3853c708be/volumes/kubernetes.io~nfs/manual-pv/foobar
Do not unmount and mount subpath bind mounts during container creation unless bind mount changes

@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. 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. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Oct 6, 2021
@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 Oct 6, 2021
@gnufied
Copy link
Member Author

gnufied commented Oct 6, 2021

/sig storage

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 6, 2021
@gnufied
Copy link
Member Author

gnufied commented Oct 6, 2021

/kind bug

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. and removed do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Oct 6, 2021
@gnufied
Copy link
Member Author

gnufied commented Oct 6, 2021

/assign @msau42 @jingxu97

@gnufied gnufied force-pushed the add-subpath-mount-source-check branch from 1b13067 to c2cf45e Compare October 6, 2021 18:59
@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 Oct 6, 2021
pkg/volume/util/hostutil/hostutil_linux.go Outdated Show resolved Hide resolved
(volumeMountInfo.Major == mntInfo.Major && volumeMountInfo.Minor == mntInfo.Minor) {
klog.V(5).Infof("Skipping bind-mounting subpath %s, volumePath: %s, path: %s", bindPathTarget, subpath.VolumePath, subpath.Path)
return true, bindPathTarget, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Here the error is ignored because of ConfigMaps?

Copy link
Member

Choose a reason for hiding this comment

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

I think this could use a comment to explain the reason to exempt these subpath bind mounts from the Unmount call below. IIUC, the configmap and secret subpaths should still trigger unmount, but bind mounts should not?
Does mount.PathWithinBase(subpath.Path, subpath.VolumePath) only return true for bind mounts then?

Copy link
Member

Choose a reason for hiding this comment

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

Would it be feasible to add a unit test for this path?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have changed this logic to hardcode just the volume types that will trigger unmount and mount. I think apart from that every other volume type should use previously mounted subpath bind mount.

@dobsonj
Copy link
Member

dobsonj commented Oct 6, 2021

/retest

@@ -164,6 +164,28 @@ func (hu *HostUtil) FindMountInfo(path string) (mount.MountInfo, error) {
return findMountInfo(path, procMountInfoPath)
}

// FindExactMountInfo returns exact mount point that matches given path
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe add more details about the difference between FindMountInfo and FindExactMountInfo?

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed this function. I think the only volume types that really need to trigger mount and unmount is intree ephemeral types.

@jingxu97
Copy link
Contributor

jingxu97 commented Oct 7, 2021

/assigne @fatedier

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Oct 8, 2021
@gnufied gnufied force-pushed the add-subpath-mount-source-check branch from ad66bc7 to f68c948 Compare November 9, 2021 21:05
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gnufied

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

@gnufied
Copy link
Member Author

gnufied commented Nov 9, 2021

@msau42 @jsafrane I have updated the code to use os.SameFile to compare bindmount target (i.e subpath bind mount kubelet creates) with subpath directory/file inside the volume. Since a bind mount has same inode number, device numbers as original file - this check should work. If subpath inside volume however changes (but bind mount does not), then they will mismatch and whenever container is restarted, it will cause old subpath bind mount to unmount and mounted again. PTAL.

@gnufied gnufied force-pushed the add-subpath-mount-source-check branch from f68c948 to e3d5b31 Compare November 10, 2021 16:12
},
}
for _, test := range tests {
klog.V(4).Infof("test %q", test.name)
Copy link
Member

@jsafrane jsafrane Nov 10, 2021

Choose a reason for hiding this comment

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

Just a suggestion for temp dirs + defer for os.RemoveAll

t.Run(test.name, func (t *testing.T){
    base, err = ioutil.TempDir()
    if err {...}
    defer os.RemoveAll(base)

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed.

@gnufied gnufied force-pushed the add-subpath-mount-source-check branch from e3d5b31 to 467bcd8 Compare November 10, 2021 16:53
@jsafrane
Copy link
Member

lgtm. Giving @msau42 a chance to review.

@gnufied
Copy link
Member Author

gnufied commented Nov 10, 2021

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 10, 2021
@msau42
Copy link
Member

msau42 commented Nov 11, 2021

/lgtm
/hold
can you update the release note?

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Nov 11, 2021
@gnufied
Copy link
Member Author

gnufied commented Nov 11, 2021

done.
/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 11, 2021
@gnufied
Copy link
Member Author

gnufied commented Nov 11, 2021

Unrelated failure:

goroutine 676 [running]:
k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/runtime.logPanic({0x50c15a0, 0x89ad100})
	/home/prow/go/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/runtime/runtime.go:74 +0xe6
k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/runtime.HandleCrash({0x0, 0x0, 0x461107})
	/home/prow/go/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/runtime/runtime.go:48 +0xb0
panic({0x50c15a0, 0x89ad100})
	/usr/local/go/src/runtime/panic.go:1047 +0x266
k8s.io/kubernetes/pkg/kubelet.TestSyncLabels.func1.2()

/retest

@k8s-ci-robot k8s-ci-robot merged commit ba94497 into kubernetes:master Nov 11, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.23 milestone Nov 11, 2021
k8s-ci-robot added a commit that referenced this pull request Nov 12, 2021
…512-upstream-release-1.22

Automated cherry pick of #105512: Add check for subpaths
k8s-ci-robot added a commit that referenced this pull request Nov 12, 2021
…512-upstream-release-1.21

Automated cherry pick of #105512: Add check for subpaths
k8s-ci-robot added a commit that referenced this pull request Nov 12, 2021
…512-upstream-release-1.20

Automated cherry pick of #105512: Add check for subpaths
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. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/storage Categorizes an issue or PR as relevant to SIG Storage. 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
None yet
Development

Successfully merging this pull request may close these issues.

subpath sources never match when containers are re-created
7 participants