Skip to content

Commit

Permalink
Add a shouldDelete method in the provisioner Qualifer interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jian-he committed Nov 2, 2018
1 parent 5cc6f1a commit 19e481d
Show file tree
Hide file tree
Showing 3 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 qualifier, ok := ctrl.provisioner.(Qualifier); ok {
if !qualifier.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
4 changes: 4 additions & 0 deletions controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,10 @@ func (p *testQualifiedProvisioner) ShouldProvision(claim *v1.PersistentVolumeCla
return p.answer
}

func (p *testQualifiedProvisioner) ShouldDelete(claim *v1.PersistentVolume) bool {
return p.answer
}

func newTestBlockProvisioner(answer bool) *testBlockProvisioner {
return &testBlockProvisioner{newTestProvisioner(), answer}
}
Expand Down
3 changes: 3 additions & 0 deletions controller/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ type Qualifier interface {
// ShouldProvision returns whether provisioning for the claim should
// be attempted.
ShouldProvision(*v1.PersistentVolumeClaim) bool

// ShouldDelete returns whether deleting the PV should be attempted.
ShouldDelete(volume *v1.PersistentVolume) bool
}

// BlockProvisioner is an optional interface implemented by provisioners to determine
Expand Down

0 comments on commit 19e481d

Please sign in to comment.