Skip to content

Commit

Permalink
Add a DeletionGuard interface for custom provisioner to implement cus…
Browse files Browse the repository at this point in the history
…tom shouldDelete logic
  • Loading branch information
jian-he committed Nov 3, 2018
1 parent 5cc6f1a commit a5cfa22
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
7 changes: 7 additions & 0 deletions controller/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a5cfa22

Please sign in to comment.