mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 07:27:21 +00:00
PV Controller: fix recycling
In the situation when a PVC is deleted and a new one with the same name bound to a different PV the "old" PV may fail to recycle since it's associaded with a PVC that is detected as being in use. This may cause the recycler processes to hang.
This commit is contained in:
@@ -1127,7 +1127,19 @@ func (ctrl *PersistentVolumeController) recycleVolumeOperation(volume *v1.Persis
|
||||
klog.V(3).Infof("can't recycle volume %q: %v", volume.Name, err)
|
||||
return
|
||||
}
|
||||
if used {
|
||||
|
||||
// Verify the claim is in cache: if so, then it is a different PVC with the same name
|
||||
// since the volume is known to be released at this moment. Ths new (cached) PVC must use
|
||||
// a different PV -- we checked that the PV is unused in isVolumeReleased.
|
||||
// So the old PV is safe to be recycled.
|
||||
claimName := claimrefToClaimKey(volume.Spec.ClaimRef)
|
||||
_, claimCached, err := ctrl.claims.GetByKey(claimName)
|
||||
if err != nil {
|
||||
klog.V(3).Infof("error getting the claim %s from cache", claimName)
|
||||
return
|
||||
}
|
||||
|
||||
if used && !claimCached {
|
||||
msg := fmt.Sprintf("Volume is used by pods: %s", strings.Join(pods, ","))
|
||||
klog.V(3).Infof("can't recycle volume %q: %s", volume.Name, msg)
|
||||
ctrl.eventRecorder.Event(volume, v1.EventTypeNormal, events.VolumeFailedRecycle, msg)
|
||||
|
||||
Reference in New Issue
Block a user