ensure only we're mounting/unmounting the right pod's container disk during migration
@@ -53,15 +53,27 @@ func GetVolumeMountDirOnGuest(vmi *v1.VirtualMachineInstance) string {
}
func GetVolumeMountDirOnHost(vmi *v1.VirtualMachineInstance) (string, bool, error) {
+ basepath := ""
+ foundEntries := 0
+ foundBasepath := ""
for podUID, _ := range vmi.Status.ActivePods {
- basepath := fmt.Sprintf("%s/%s/volumes/kubernetes.io~empty-dir/container-disks", podsBaseDir, string(podUID))
+ basepath = fmt.Sprintf("%s/%s/volumes/kubernetes.io~empty-dir/container-disks", podsBaseDir, string(podUID))
exists, err := diskutils.FileExists(basepath)
if err != nil {
return "", false, err
} else if exists {
- return basepath, true, nil
+ foundEntries++
+ foundBasepath = basepath
}
}
+
+ if foundEntries == 1 {
+ return foundBasepath, true, nil
+ } else if foundEntries > 1 {
+ // Don't mount until outdated pod environments are removed
+ // otherwise we might stomp on a previous cleanup
+ return "", false, fmt.Errorf("Found multiple pods active for vmi %s/%s. Waiting on outdated pod directories to be removed", vmi.Namespace, vmi.Name)
+ }
return "", false, nil
}
