Add a check to see if PVC has a finalizer
This commit is contained in:
@@ -167,9 +167,10 @@ func (ctrl *csiSnapshotCommonController) syncSnapshot(snapshot *crdv1.VolumeSnap
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Proceed with snapshot deletion only if snapshot is not in the middled of being
|
// Proceed with snapshot deletion only if snapshot is not in the middled of being
|
||||||
// created from a PVC. This is to ensure that the PVC finalizer can be removed even
|
// created from a PVC with a finalizer. This is to ensure that the PVC finalizer
|
||||||
// if a delete snapshot request is received before create snapshot has completed.
|
// can be removed even if a delete snapshot request is received before create
|
||||||
if snapshot.ObjectMeta.DeletionTimestamp != nil && !ctrl.isPVCInUseByCurrentSnapshot(snapshot) {
|
// snapshot has completed.
|
||||||
|
if snapshot.ObjectMeta.DeletionTimestamp != nil && !ctrl.isPVCwithFinalizerInUseByCurrentSnapshot(snapshot) {
|
||||||
err := ctrl.processSnapshotWithDeletionTimestamp(snapshot)
|
err := ctrl.processSnapshotWithDeletionTimestamp(snapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -193,15 +194,21 @@ func (ctrl *csiSnapshotCommonController) syncSnapshot(snapshot *crdv1.VolumeSnap
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if PVC is being used by the current snapshot as source
|
// Check if PVC has a finalizer and if it is being used by the current snapshot as source.
|
||||||
func (ctrl *csiSnapshotCommonController) isPVCInUseByCurrentSnapshot(snapshot *crdv1.VolumeSnapshot) bool {
|
func (ctrl *csiSnapshotCommonController) isPVCwithFinalizerInUseByCurrentSnapshot(snapshot *crdv1.VolumeSnapshot) bool {
|
||||||
// Get snapshot source which is a PVC
|
// Get snapshot source which is a PVC
|
||||||
pvc, err := ctrl.getClaimFromVolumeSnapshot(snapshot)
|
pvc, err := ctrl.getClaimFromVolumeSnapshot(snapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Infof("cannot get claim from snapshot [%s]: [%v] Claim may be deleted already.", snapshot.Name, err)
|
klog.Infof("cannot get claim from snapshot [%s]: [%v] Claim may be deleted already.", snapshot.Name, err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if snapshot.Spec.Source.PersistentVolumeClaimName != nil && pvc.Name == *snapshot.Spec.Source.PersistentVolumeClaimName && !utils.IsSnapshotReady(snapshot) {
|
|
||||||
|
// Check if there is a Finalizer on PVC. If not, return false
|
||||||
|
if !slice.ContainsString(pvc.ObjectMeta.Finalizers, utils.PVCFinalizer, nil) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if !utils.IsSnapshotReady(snapshot) {
|
||||||
klog.V(2).Infof("PVC %s/%s is being used by snapshot %s/%s as source", pvc.Namespace, pvc.Name, snapshot.Namespace, snapshot.Name)
|
klog.V(2).Infof("PVC %s/%s is being used by snapshot %s/%s as source", pvc.Namespace, pvc.Name, snapshot.Namespace, snapshot.Name)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user