Skip to content

Commit 2c10d7c

Browse files
committed
fix: Do not clean PV's with a deletion timestamp
After the volume has been successfully cleaned, the deleter sends a Delete request to the API server. It should not continue attempting to clean the PV at this point if the object still exists, as the PV may disappear at any time, and we don't want cleanup to be in progress when that happens.
1 parent 76b1c86 commit 2c10d7c

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

pkg/deleter/deleter.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ func (d *Deleter) DeletePVs() {
7272
if pv.Status.Phase != v1.VolumeReleased {
7373
continue
7474
}
75+
// Do not clean PV's that were already deleted,
76+
// they may disappear at any time.
77+
if !pv.DeletionTimestamp.IsZero() {
78+
continue
79+
}
7580
name := pv.Name
7681
switch pv.Spec.PersistentVolumeReclaimPolicy {
7782
case v1.PersistentVolumeReclaimRetain:

pkg/deleter/deleter_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,14 @@ type testConfig struct {
7070
}
7171

7272
type testVol struct {
73-
pvPhase v1.PersistentVolumePhase
74-
VolumeMode string
75-
reclaimPolicy v1.PersistentVolumeReclaimPolicy
73+
pvPhase v1.PersistentVolumePhase
74+
VolumeMode string
75+
reclaimPolicy v1.PersistentVolumeReclaimPolicy
76+
deletionTimestamp *meta_v1.Time
7677
}
7778

7879
func TestDeleteVolumes_Basic(t *testing.T) {
80+
deletionTimestamp := meta_v1.Now()
7981
vols := map[string]*testVol{
8082
"pv1": {
8183
pvPhase: v1.VolumePending,
@@ -96,6 +98,10 @@ func TestDeleteVolumes_Basic(t *testing.T) {
9698
pvPhase: v1.VolumeReleased,
9799
reclaimPolicy: v1.PersistentVolumeReclaimRetain,
98100
},
101+
"pv7": {
102+
pvPhase: v1.VolumeReleased,
103+
deletionTimestamp: &deletionTimestamp,
104+
},
99105
}
100106
expectedDeletedPVs := map[string]string{"pv4": ""}
101107
test := &testConfig{
@@ -580,6 +586,7 @@ func testSetup(t *testing.T, config *testConfig, cleanupCmd []string, useJobForC
580586
}
581587
pv := common.CreateLocalPVSpec(&lpvConfig)
582588
pv.Status.Phase = vol.pvPhase
589+
pv.DeletionTimestamp = vol.deletionTimestamp
583590

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

0 commit comments

Comments
 (0)