@@ -29,6 +29,7 @@ import (
29
29
30
30
"golang.org/x/sys/unix"
31
31
"k8s.io/klog/v2"
32
+ "k8s.io/kubernetes/pkg/volume/util/hostutil"
32
33
"k8s.io/utils/mount"
33
34
)
34
35
@@ -108,9 +109,21 @@ func prepareSubpathTarget(mounter mount.Interface, subpath Subpath) (bool, strin
108
109
notMount = true
109
110
}
110
111
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
+ }
114
127
}
115
128
116
129
// bindPathTarget is in /var/lib/kubelet and thus reachable without any
0 commit comments