Skip to content

Commit

Permalink
Check if pathExists before performing Unmount
Browse files Browse the repository at this point in the history
  • Loading branch information
rkouj committed Jan 5, 2017
1 parent 215832b commit efd2eb7
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 32 deletions.
9 changes: 1 addition & 8 deletions pkg/volume/configmap/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,7 @@ func (c *configMapVolumeUnmounter) TearDown() error {
}

func (c *configMapVolumeUnmounter) TearDownAt(dir string) error {
glog.V(3).Infof("Tearing down volume %v for pod %v at %v", c.volName, c.podUID, dir)

// Wrap EmptyDir, let it do the teardown.
wrapped, err := c.plugin.host.NewWrapperUnmounter(c.volName, wrappedVolumeSpec(), c.podUID)
if err != nil {
return err
}
return wrapped.TearDownAt(dir)
return volume.UnmountViaEmptyDir(dir, c.plugin.host, c.volName, wrappedVolumeSpec(), c.podUID)
}

func getVolumeSource(spec *volume.Spec) (*api.ConfigMapVolumeSource, bool) {
Expand Down
9 changes: 1 addition & 8 deletions pkg/volume/downwardapi/downwardapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,7 @@ func (c *downwardAPIVolumeUnmounter) TearDown() error {
}

func (c *downwardAPIVolumeUnmounter) TearDownAt(dir string) error {
glog.V(3).Infof("Tearing down volume %v for pod %v at %v", c.volName, c.podUID, dir)

// Wrap EmptyDir, let it do the teardown.
wrapped, err := c.plugin.host.NewWrapperUnmounter(c.volName, wrappedVolumeSpec(), c.podUID)
if err != nil {
return err
}
return wrapped.TearDownAt(dir)
return volume.UnmountViaEmptyDir(dir, c.plugin.host, c.volName, wrappedVolumeSpec(), c.podUID)
}

func (b *downwardAPIVolumeMounter) getMetaDir() string {
Expand Down
7 changes: 7 additions & 0 deletions pkg/volume/empty_dir/empty_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,13 @@ func (ed *emptyDir) TearDown() error {

// TearDownAt simply discards everything in the directory.
func (ed *emptyDir) TearDownAt(dir string) error {
if pathExists, pathErr := volumeutil.PathExists(dir); pathErr != nil {
return fmt.Errorf("Error checking if path exists: %v", pathErr)
} else if !pathExists {
glog.Warningf("Warning: Unmount skipped because path does not exist: %v", dir)
return nil
}

// Figure out the medium.
medium, isMnt, err := ed.mountDetector.GetMountMedium(dir)
if err != nil {
Expand Down
8 changes: 1 addition & 7 deletions pkg/volume/git_repo/git_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,7 @@ func (c *gitRepoVolumeUnmounter) TearDown() error {

// TearDownAt simply deletes everything in the directory.
func (c *gitRepoVolumeUnmounter) TearDownAt(dir string) error {

// Wrap EmptyDir, let it do the teardown.
wrapped, err := c.plugin.host.NewWrapperUnmounter(c.volName, wrappedVolumeSpec(), c.podUID)
if err != nil {
return err
}
return wrapped.TearDownAt(dir)
return volume.UnmountViaEmptyDir(dir, c.plugin.host, c.volName, wrappedVolumeSpec(), c.podUID)
}

func getVolumeSource(spec *volume.Spec) (*api.GitRepoVolumeSource, bool) {
Expand Down
9 changes: 1 addition & 8 deletions pkg/volume/secret/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,7 @@ func (c *secretVolumeUnmounter) TearDown() error {
}

func (c *secretVolumeUnmounter) TearDownAt(dir string) error {
glog.V(3).Infof("Tearing down volume %v for pod %v at %v", c.volName, c.podUID, dir)

// Wrap EmptyDir, let it do the teardown.
wrapped, err := c.plugin.host.NewWrapperUnmounter(c.volName, wrappedVolumeSpec(), c.podUID)
if err != nil {
return err
}
return wrapped.TearDownAt(dir)
return volume.UnmountViaEmptyDir(dir, c.plugin.host, c.volName, wrappedVolumeSpec(), c.podUID)
}

func getVolumeSource(spec *volume.Spec) (*api.SecretVolumeSource, bool) {
Expand Down
22 changes: 22 additions & 0 deletions pkg/volume/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ import (
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util/sets"
volutil "k8s.io/kubernetes/pkg/volume/util"
)

type RecycleEventRecorder func(eventtype, message string)
Expand Down Expand Up @@ -331,3 +333,23 @@ func ChooseZoneForVolume(zones sets.String, pvcName string) string {
glog.V(2).Infof("Creating volume for PVC %q; chose zone=%q from zones=%q", pvcName, zone, zoneSlice)
return zone
}

// UnmountViaEmptyDir delegates the tear down operation for secret, configmap, git_repo and downwardapi
// to empty_dir
func UnmountViaEmptyDir(dir string, host VolumeHost, volName string, volSpec Spec, podUID types.UID) error {
glog.V(3).Infof("Tearing down volume %v for pod %v at %v", volName, podUID, dir)

if pathExists, pathErr := volutil.PathExists(dir); pathErr != nil {
return fmt.Errorf("Error checking if path exists: %v", pathErr)
} else if !pathExists {
glog.Warningf("Warning: Unmount skipped because path does not exist: %v", dir)
return nil
}

// Wrap EmptyDir, let it do the teardown.
wrapped, err := host.NewWrapperUnmounter(volName, volSpec, podUID)
if err != nil {
return err
}
return wrapped.TearDownAt(dir)
}
2 changes: 1 addition & 1 deletion test/test_owners.csv
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ Garbage collector should orphan pods created by rc if deleteOptions.OrphanDepend
"Generated release_1_5 clientset should create pods, delete pods, watch pods",ghodss,1
"Generated release_1_5 clientset should create v2alpha1 cronJobs, delete cronJobs, watch cronJobs",soltysh,1
HA-master survive addition/removal replicas different zones,derekwaynecarr,0
HA-master survive addition/removal replicas multizone workers,rkouj,0
HA-master survive addition/removal replicas same zone,derekwaynecarr,0
Hazelcast should create and scale hazelcast,mikedanese,1
Horizontal pod autoscaling (scale resource: CPU) Deployment Should scale from 1 pod to 3 pods and from 3 to 5,jszczepkowski,0
Expand Down Expand Up @@ -686,7 +687,6 @@ k8s.io/kubernetes/pkg/kubelet/kuberuntime,yifan-gu,1
k8s.io/kubernetes/pkg/kubelet/lifecycle,yujuhong,1
k8s.io/kubernetes/pkg/kubelet/network,freehan,0
k8s.io/kubernetes/pkg/kubelet/network/cni,freehan,0
k8s.io/kubernetes/pkg/kubelet/network/exec,freehan,0
k8s.io/kubernetes/pkg/kubelet/network/hairpin,freehan,0
k8s.io/kubernetes/pkg/kubelet/network/hostport,erictune,1
k8s.io/kubernetes/pkg/kubelet/network/kubenet,freehan,0
Expand Down

0 comments on commit efd2eb7

Please sign in to comment.