feat(zfspv): remove finalizer that is owned by ZFS-LocalPV (#303)

We set the Finalizer to nil while handling the delete event, instead,
we should try to destroy the volume when there are no user finalizers
set. User might have added his own finalizers and we should not try to destroy
the volumes until those user finalizers are removed.

Signed-off-by: Pawan <pawan@mayadata.io>
This commit is contained in:
Pawan Prakash Sharma 2021-04-06 20:03:00 +05:30 committed by GitHub
parent 9888968fd7
commit 68d79d0e0b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 24 deletions

View file

@ -78,15 +78,20 @@ func (c *ZVController) syncZV(zv *apis.ZFSVolume) error {
var err error
// ZFS Volume should be deleted. Check if deletion timestamp is set
if c.isDeletionCandidate(zv) {
err = zfs.DestroyVolume(zv)
if err == nil {
zfs.RemoveZvolFinalizer(zv)
userFin := zfs.GetUserFinalizers(zv.Finalizers)
if len(userFin) == 0 {
// destroy only if other finalizers have been removed
err = zfs.DestroyVolume(zv)
if err == nil {
err = zfs.RemoveVolumeFinalizer(zv)
}
} else {
return fmt.Errorf("volume: can not destroy, waiting for finalizers to be removed %v", userFin)
}
} else {
// if finalizer is not set then it means we are creating
// the volume. And if it is set then volume has already been
// created and this event is for property change only.
if zv.Finalizers != nil {
// if volume has already been created and its state is Ready
// then this event is for property change only.
if zfs.IsVolumeReady(zv) {
err = zfs.SetVolumeProp(zv)
} else {
if len(zv.Spec.SnapName) > 0 {