Merge pull request #43878 from msau42/emptydir-rename

Automatic merge from submit-queue (batch tested with PRs 44362, 44421, 44468, 43878, 44480)

Delete EmptyDir volume directly instead of renaming the directory.

**What this PR does / why we need it**:
The volume operation executor can handle duplicate requests on the same volume now, so it is not necessary to rename the directory anymore.  This change can cause pod deletion to take longer for large emptydir volumes because now the pod waits for the volume to be deleted until it continues pod cleanup.  But this is actually required for local disk scheduling so that we don't schedule new pods that need emptydir volumes on the node if the previous emptydir has not be fully reclaimed yet.

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #43534

**Special notes for your reviewer**:

**Release note**:

NONE

cc @kubernetes/sig-storage-pr-reviews
This commit is contained in:
Kubernetes Submit Queue 2017-04-14 01:46:05 -07:00 committed by GitHub
commit c6bfa43c58
2 changed files with 3 additions and 104 deletions

View File

@ -329,11 +329,9 @@ func (ed *emptyDir) TearDownAt(dir string) error {
}
func (ed *emptyDir) teardownDefault(dir string) error {
tmpDir, err := volume.RenameDirectory(dir, ed.volName+".deleting~")
if err != nil {
return err
}
err = os.RemoveAll(tmpDir)
// Renaming the directory is not required anymore because the operation executor
// now handles duplicate operations on the same volume
err := os.RemoveAll(dir)
if err != nil {
return err
}

View File

@ -17,14 +17,8 @@ limitations under the License.
package volume
import (
"io"
"io/ioutil"
"os"
filepath "path/filepath"
"runtime"
"time"
"github.com/golang/glog"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
@ -234,96 +228,3 @@ func IsDeletedVolumeInUse(err error) bool {
func (err deletedVolumeInUseError) Error() string {
return string(err)
}
func RenameDirectory(oldPath, newName string) (string, error) {
newPath, err := ioutil.TempDir(filepath.Dir(oldPath), newName)
if err != nil {
return "", err
}
// os.Rename call fails on windows (https://github.com/golang/go/issues/14527)
// Replacing with copyFolder to the newPath and deleting the oldPath directory
if runtime.GOOS == "windows" {
err = copyFolder(oldPath, newPath)
if err != nil {
glog.Errorf("Error copying folder from: %s to: %s with error: %v", oldPath, newPath, err)
return "", err
}
os.RemoveAll(oldPath)
return newPath, nil
}
err = os.Rename(oldPath, newPath)
if err != nil {
return "", err
}
return newPath, nil
}
func copyFolder(source string, dest string) (err error) {
fi, err := os.Lstat(source)
if err != nil {
glog.Errorf("Error getting stats for %s. %v", source, err)
return err
}
err = os.MkdirAll(dest, fi.Mode())
if err != nil {
glog.Errorf("Unable to create %s directory %v", dest, err)
}
directory, _ := os.Open(source)
defer directory.Close()
objects, err := directory.Readdir(-1)
for _, obj := range objects {
if obj.Mode()&os.ModeSymlink != 0 {
continue
}
sourceFilePointer := source + "\\" + obj.Name()
destinationFilePointer := dest + "\\" + obj.Name()
if obj.IsDir() {
err = copyFolder(sourceFilePointer, destinationFilePointer)
if err != nil {
return err
}
} else {
err = copyFile(sourceFilePointer, destinationFilePointer)
if err != nil {
return err
}
}
}
return
}
func copyFile(source string, dest string) (err error) {
sourceFile, err := os.Open(source)
if err != nil {
return err
}
defer sourceFile.Close()
destFile, err := os.Create(dest)
if err != nil {
return err
}
defer destFile.Close()
_, err = io.Copy(destFile, sourceFile)
if err == nil {
sourceInfo, err := os.Stat(source)
if err != nil {
err = os.Chmod(dest, sourceInfo.Mode())
}
}
return
}