Skip to content

Commit

Permalink
CleanupHostPathVolumes(): remove also directories from the filesystem.
Browse files Browse the repository at this point in the history
  • Loading branch information
php-coder committed Oct 21, 2016
1 parent 2dccff1 commit 3beaf98
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
2 changes: 0 additions & 2 deletions test/extended/image_ecosystem/mongodb_replica_petset.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ var _ = g.Describe("[image_ecosystem][mongodb][Slow] openshift mongodb replicati
defer func() {
// We're removing only PVs because all other things will be removed
// together with namespace.
// TODO: unfortunately it doesn't remove the directories on the filesystem.
// Need to figure out how to fix it.
err := exutil.CleanupHostPathVolumes(oc.AdminKubeREST().PersistentVolumes(), oc.Namespace())
if err != nil {
fmt.Fprintf(g.GinkgoWriter, "WARNING: couldn't cleanup persistent volumes: %v", err)
Expand Down
31 changes: 29 additions & 2 deletions test/extended/util/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -1095,8 +1095,35 @@ func CleanupHostPathVolumes(c kclient.PersistentVolumeInterface, prefix string)
}
prefix = fmt.Sprintf("%s%s-", pvPrefix, prefix)
for _, pv := range pvs.Items {
if strings.HasPrefix(pv.Name, prefix) {
c.Delete(pv.Name)
if !strings.HasPrefix(pv.Name, prefix) {
continue
}

if err = c.Delete(pv.Name); err != nil {
fmt.Fprintf(g.GinkgoWriter, "WARNING: couldn't remove PV %s: %v\n", pv.Name, err)
continue
}

pvInfo, err := c.Get(pv.Name)
if err != nil {
fmt.Fprintf(g.GinkgoWriter, "WARNING: couldn't get meta info for PV %s: %v\n", pv.Name, err)
continue
}

volumeDir := pvInfo.Spec.HostPath.Path
if err = os.RemoveAll(volumeDir); err != nil {
fmt.Fprintf(g.GinkgoWriter, "WARNING: couldn't remove directory %q: %v\n", volumeDir, err)
continue
}

parentDir := filepath.Dir(volumeDir)
if parentDir == "." || parentDir == "/" {
continue
}

if err = os.Remove(parentDir); err != nil {
fmt.Fprintf(g.GinkgoWriter, "WARNING: couldn't remove directory %q: %v\n", parentDir, err)
continue
}
}
return nil
Expand Down

0 comments on commit 3beaf98

Please sign in to comment.