Skip to content

Commit 6c2562a

Browse files
committed
fix 68211: modified subpath configmap mount fails when container restart
1 parent 1c11ff7 commit 6c2562a

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

pkg/volume/util/hostutil/hostutil_linux.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ func (hu *HostUtil) EvalHostSymlinks(pathname string) (string, error) {
158158
return filepath.EvalSymlinks(pathname)
159159
}
160160

161+
// FindMountInfo returns the mount info on the given path.
162+
func (hu *HostUtil) FindMountInfo(path string) (mount.MountInfo, error) {
163+
return findMountInfo(path, procMountInfoPath)
164+
}
165+
161166
// isShared returns true, if given path is on a mount point that has shared
162167
// mount propagation.
163168
func isShared(mount string, mountInfoPath string) (bool, error) {

pkg/volume/util/subpath/subpath_linux.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929

3030
"golang.org/x/sys/unix"
3131
"k8s.io/klog/v2"
32+
"k8s.io/kubernetes/pkg/volume/util/hostutil"
3233
"k8s.io/utils/mount"
3334
)
3435

@@ -108,9 +109,21 @@ func prepareSubpathTarget(mounter mount.Interface, subpath Subpath) (bool, strin
108109
notMount = true
109110
}
110111
if !notMount {
111-
// It's already mounted
112-
klog.V(5).Infof("Skipping bind-mounting subpath %s: already mounted", bindPathTarget)
113-
return true, bindPathTarget, nil
112+
linuxHostUtil := hostutil.NewHostUtil()
113+
mntInfo, err := linuxHostUtil.FindMountInfo(bindPathTarget)
114+
if err != nil {
115+
return false, "", fmt.Errorf("error calling findMountInfo for %s: %s", bindPathTarget, err)
116+
}
117+
if mntInfo.Root != subpath.Path {
118+
// It's already mounted but not what we want, unmount it
119+
if err = mounter.Unmount(bindPathTarget); err != nil {
120+
return false, "", fmt.Errorf("error ummounting %s: %s", bindPathTarget, err)
121+
}
122+
} else {
123+
// It's already mounted
124+
klog.V(5).Infof("Skipping bind-mounting subpath %s: already mounted", bindPathTarget)
125+
return true, bindPathTarget, nil
126+
}
114127
}
115128

116129
// bindPathTarget is in /var/lib/kubelet and thus reachable without any

0 commit comments

Comments
 (0)