Skip to content

Fixing PV cleanup #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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