Skip to content

Commit

Permalink
Merge pull request #465 from dobsonj/deletion-timestamp-check
Browse files Browse the repository at this point in the history
fix: Do not clean PV's with a deletion timestamp
  • Loading branch information
k8s-ci-robot authored Nov 19, 2024
2 parents 194037a + 2c10d7c commit a379044
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions pkg/deleter/deleter.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ func (d *Deleter) DeletePVs() {
if pv.Status.Phase != v1.VolumeReleased {
continue
}
// Do not clean PV's that were already deleted,
// they may disappear at any time.
if !pv.DeletionTimestamp.IsZero() {
continue
}
name := pv.Name
switch pv.Spec.PersistentVolumeReclaimPolicy {
case v1.PersistentVolumeReclaimRetain:
Expand Down
13 changes: 10 additions & 3 deletions pkg/deleter/deleter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ type testConfig struct {
}

type testVol struct {
pvPhase v1.PersistentVolumePhase
VolumeMode string
reclaimPolicy v1.PersistentVolumeReclaimPolicy
pvPhase v1.PersistentVolumePhase
VolumeMode string
reclaimPolicy v1.PersistentVolumeReclaimPolicy
deletionTimestamp *meta_v1.Time
}

func TestDeleteVolumes_Basic(t *testing.T) {
deletionTimestamp := meta_v1.Now()
vols := map[string]*testVol{
"pv1": {
pvPhase: v1.VolumePending,
Expand All @@ -96,6 +98,10 @@ func TestDeleteVolumes_Basic(t *testing.T) {
pvPhase: v1.VolumeReleased,
reclaimPolicy: v1.PersistentVolumeReclaimRetain,
},
"pv7": {
pvPhase: v1.VolumeReleased,
deletionTimestamp: &deletionTimestamp,
},
}
expectedDeletedPVs := map[string]string{"pv4": ""}
test := &testConfig{
Expand Down Expand Up @@ -580,6 +586,7 @@ func testSetup(t *testing.T, config *testConfig, cleanupCmd []string, useJobForC
}
pv := common.CreateLocalPVSpec(&lpvConfig)
pv.Status.Phase = vol.pvPhase
pv.DeletionTimestamp = vol.deletionTimestamp

_, err := config.apiUtil.CreatePV(pv)
if err != nil {
Expand Down

0 comments on commit a379044

Please sign in to comment.