From a5cfa22fddcb3fbf072006d480a7b947b94359e9 Mon Sep 17 00:00:00 2001 From: Jian He Date: Sat, 3 Nov 2018 15:31:34 +0800 Subject: [PATCH] Add a DeletionGuard interface for custom provisioner to implement custom shouldDelete logic --- controller/controller.go | 6 ++++++ controller/volume.go | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/controller/controller.go b/controller/controller.go index 0878c51..269ea02 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -848,6 +848,12 @@ func (ctrl *ProvisionController) shouldProvision(claim *v1.PersistentVolumeClaim // shouldDelete returns whether a volume should have its backing volume // deleted, i.e. whether a Delete is "desired" func (ctrl *ProvisionController) shouldDelete(volume *v1.PersistentVolume) bool { + if deletionGuard, ok := ctrl.provisioner.(DeletionGuard); ok { + if !deletionGuard.ShouldDelete(volume) { + return false + } + } + // In 1.9+ PV protection means the object will exist briefly with a // deletion timestamp even after our successful Delete. Ignore it. if ctrl.kubeVersion.AtLeast(utilversion.MustParseSemantic("v1.9.0")) { diff --git a/controller/volume.go b/controller/volume.go index 92db410..f1d42b7 100644 --- a/controller/volume.go +++ b/controller/volume.go @@ -47,6 +47,13 @@ type Qualifier interface { ShouldProvision(*v1.PersistentVolumeClaim) bool } +// DeletionGuard is an optional interface implemented by provisioners to determine +// whether a PV should be deleted. +type DeletionGuard interface { + // ShouldDelete returns whether deleting the PV should be attempted. + ShouldDelete(volume *v1.PersistentVolume) bool +} + // BlockProvisioner is an optional interface implemented by provisioners to determine // whether it supports block volume. type BlockProvisioner interface {