Skip to content

Commit

Permalink
Merge pull request #93 from arangodb/pv-cleanup-fixes
Browse files Browse the repository at this point in the history
Fixing PV cleanup
  • Loading branch information
ewoutp authored Apr 3, 2018
2 parents 1173d8e + 6ce6197 commit eafc2ab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/storage/pv_cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"k8s.io/client-go/kubernetes"

"github.com/arangodb/kube-arangodb/pkg/storage/provisioner"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
"github.com/arangodb/kube-arangodb/pkg/util/trigger"
)

Expand Down Expand Up @@ -159,7 +160,7 @@ func (c *pvCleaner) clean(pv v1.PersistentVolume) error {
}

// Remove persistent volume
if err := c.cli.CoreV1().PersistentVolumes().Delete(pv.GetName(), &metav1.DeleteOptions{}); err != nil {
if err := c.cli.CoreV1().PersistentVolumes().Delete(pv.GetName(), &metav1.DeleteOptions{}); err != nil && !k8sutil.IsNotFound(err) {
log.Debug().Err(err).
Str("name", pv.GetName()).
Msg("Failed to remove PersistentVolume")
Expand Down
18 changes: 17 additions & 1 deletion pkg/storage/pv_inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
package storage

import (
"time"

"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -38,14 +40,28 @@ func (ls *LocalStorage) inspectPVs() (int, error) {
}
spec := ls.apiObject.Spec
availableVolumes := 0
cleanupBeforeTimestamp := time.Now().Add(time.Hour * -24)
for _, pv := range list.Items {
if pv.Spec.StorageClassName != spec.StorageClass.Name {
// Not our storage class
continue
}
switch pv.Status.Phase {
case v1.VolumeAvailable:
availableVolumes++
// Is this an old volume?
if pv.GetObjectMeta().GetCreationTimestamp().Time.Before(cleanupBeforeTimestamp) {
// Let's clean it up
if ls.isOwnerOf(&pv) {
// Cleanup this volume
log.Debug().Str("name", pv.GetName()).Msg("Added PersistentVolume to cleaner")
ls.pvCleaner.Add(pv)
} else {
log.Debug().Str("name", pv.GetName()).Msg("PersistentVolume is not owned by us")
availableVolumes++
}
} else {
availableVolumes++
}
case v1.VolumeReleased:
if ls.isOwnerOf(&pv) {
// Cleanup this volume
Expand Down

0 comments on commit eafc2ab

Please sign in to comment.