mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 01:40:07 +00:00
fix 68211: modified subpath configmap mount fails when container restart
This commit is contained in:
parent
1c11ff7a26
commit
6c2562a579
@ -158,6 +158,11 @@ func (hu *HostUtil) EvalHostSymlinks(pathname string) (string, error) {
|
|||||||
return filepath.EvalSymlinks(pathname)
|
return filepath.EvalSymlinks(pathname)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindMountInfo returns the mount info on the given path.
|
||||||
|
func (hu *HostUtil) FindMountInfo(path string) (mount.MountInfo, error) {
|
||||||
|
return findMountInfo(path, procMountInfoPath)
|
||||||
|
}
|
||||||
|
|
||||||
// isShared returns true, if given path is on a mount point that has shared
|
// isShared returns true, if given path is on a mount point that has shared
|
||||||
// mount propagation.
|
// mount propagation.
|
||||||
func isShared(mount string, mountInfoPath string) (bool, error) {
|
func isShared(mount string, mountInfoPath string) (bool, error) {
|
||||||
|
@ -29,6 +29,7 @@ import (
|
|||||||
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
"k8s.io/kubernetes/pkg/volume/util/hostutil"
|
||||||
"k8s.io/utils/mount"
|
"k8s.io/utils/mount"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -108,9 +109,21 @@ func prepareSubpathTarget(mounter mount.Interface, subpath Subpath) (bool, strin
|
|||||||
notMount = true
|
notMount = true
|
||||||
}
|
}
|
||||||
if !notMount {
|
if !notMount {
|
||||||
// It's already mounted
|
linuxHostUtil := hostutil.NewHostUtil()
|
||||||
klog.V(5).Infof("Skipping bind-mounting subpath %s: already mounted", bindPathTarget)
|
mntInfo, err := linuxHostUtil.FindMountInfo(bindPathTarget)
|
||||||
return true, bindPathTarget, nil
|
if err != nil {
|
||||||
|
return false, "", fmt.Errorf("error calling findMountInfo for %s: %s", bindPathTarget, err)
|
||||||
|
}
|
||||||
|
if mntInfo.Root != subpath.Path {
|
||||||
|
// It's already mounted but not what we want, unmount it
|
||||||
|
if err = mounter.Unmount(bindPathTarget); err != nil {
|
||||||
|
return false, "", fmt.Errorf("error ummounting %s: %s", bindPathTarget, err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// It's already mounted
|
||||||
|
klog.V(5).Infof("Skipping bind-mounting subpath %s: already mounted", bindPathTarget)
|
||||||
|
return true, bindPathTarget, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// bindPathTarget is in /var/lib/kubelet and thus reachable without any
|
// bindPathTarget is in /var/lib/kubelet and thus reachable without any
|
||||||
|
Loading…
Reference in New Issue
Block a user