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

@ -233,10 +233,6 @@ func UpdateZvolInfo(vol *apis.ZFSVolume, status string) error {
finalizers := []string{}
labels := map[string]string{ZFSNodeKey: NodeID}
if vol.Finalizers != nil {
return nil
}
switch status {
case ZFSStatusReady:
finalizers = append(finalizers, ZFSFinalizer)
@ -255,8 +251,8 @@ func UpdateZvolInfo(vol *apis.ZFSVolume, status string) error {
return err
}
// RemoveZvolFinalizer adds finalizer to ZFSVolume CR
func RemoveZvolFinalizer(vol *apis.ZFSVolume) error {
// RemoveVolumeFinalizer removes finalizer from ZFSVolume CR
func RemoveVolumeFinalizer(vol *apis.ZFSVolume) error {
vol.Finalizers = nil
_, err := volbuilder.NewKubeclient().WithNamespace(OpenEBSNamespace).Update(vol)
@ -290,10 +286,6 @@ func UpdateSnapInfo(snap *apis.ZFSSnapshot) error {
finalizers := []string{ZFSFinalizer}
labels := map[string]string{ZFSNodeKey: NodeID}
if snap.Finalizers != nil {
return nil
}
newSnap, err := snapbuilder.BuildFrom(snap).
WithFinalizer(finalizers).
WithLabels(labels).Build()
@ -310,7 +302,7 @@ func UpdateSnapInfo(snap *apis.ZFSSnapshot) error {
return err
}
// RemoveSnapFinalizer adds finalizer to ZFSSnapshot CR
// RemoveSnapFinalizer removes finalizer from ZFSSnapshot CR
func RemoveSnapFinalizer(snap *apis.ZFSSnapshot) error {
snap.Finalizers = nil
@ -358,3 +350,34 @@ func UpdateRestoreInfo(rstr *apis.ZFSRestore, status apis.ZFSRestoreStatus) erro
_, err = restorebuilder.NewKubeclient().WithNamespace(OpenEBSNamespace).Update(newRstr)
return err
}
// GetUserFinalizers returns all the finalizers present on the ZFSVolume object
// execpt the one owned by ZFS node daemonset. We also need to ignore the foregroundDeletion
// finalizer as this will be present becasue of the foreground cascading deletion
func GetUserFinalizers(finalizers []string) []string {
var userFin []string
for _, fin := range finalizers {
if fin != ZFSFinalizer &&
fin != "foregroundDeletion" {
userFin = append(userFin, fin)
}
}
return userFin
}
// IsVolumeReady returns true if volume is Ready
func IsVolumeReady(vol *apis.ZFSVolume) bool {
if vol.Status.State == ZFSStatusReady {
return true
}
// For older volumes, there was no Status field
// so checking the node finalizer to make sure volume is Ready
for _, fin := range vol.Finalizers {
if fin == ZFSFinalizer {
return true
}
}
return false
}