From ad0ec2388fd84820b1292c5302500d0d5a8de5fd Mon Sep 17 00:00:00 2001 From: Andrei Vagin Date: Tue, 25 Jul 2017 08:15:55 +0300 Subject: [PATCH] flexvol: remove a mount directory in a error case flexVolumeMounter.SetUpAt creates a directory, where a volume has to be mounted, and we have to remove this directory in error cases. Otherwise we will see errors like this: Orphaned pod 673b66d9-70f7-11e7-a5fa-525400307392 found, but volume paths are still present on disk https://github.com/kubernetes/kubernetes/issues/49383 Signed-off-by: Andrei Vagin --- pkg/volume/flexvolume/mounter.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/volume/flexvolume/mounter.go b/pkg/volume/flexvolume/mounter.go index 316928c429..f75a3d6651 100644 --- a/pkg/volume/flexvolume/mounter.go +++ b/pkg/volume/flexvolume/mounter.go @@ -17,6 +17,7 @@ limitations under the License. package flexvolume import ( + "os" "strconv" "k8s.io/kubernetes/pkg/util/mount" @@ -74,6 +75,7 @@ func (f *flexVolumeMounter) SetUpAt(dir string, fsGroup *int64) error { // Extract secret and pass it as options. if err := addSecretsToOptions(extraOptions, f.spec, f.podNamespace, f.driverName, f.plugin.host); err != nil { + os.Remove(dir) return err } @@ -90,6 +92,7 @@ func (f *flexVolumeMounter) SetUpAt(dir string, fsGroup *int64) error { } if err != nil { + os.Remove(dir) return err }