Skip to content

Commit

Permalink
Ensure deletion of snapshot CR when it is gone from engine
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Weber <eric.weber@suse.com>
  • Loading branch information
ejweber committed Jul 11, 2023
1 parent 75d2e77 commit 27caba8
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions controller/snapshot_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ func (sc *SnapshotController) reconcile(snapshotName string) (err error) {
return sc.ds.RemoveFinalizerForSnapshot(snapshot)
}

// Wait to get engine until now. If isVolDeletedOrBeingDeleted, the engine may not exist.
engine, err := sc.getTheOnlyEngineCRforSnapshot(snapshot)
if err != nil {
return err
Expand All @@ -335,6 +336,14 @@ func (sc *SnapshotController) reconcile(snapshotName string) (err error) {
}
}()

// If the snapshot no longer exists in the engine, allow its CR to be deleted.
if _, ok := engine.Status.Snapshots[snapshot.Name]; !ok {
if err = sc.handleAttachmentTicketDeletion(snapshot); err != nil {
return err
}
return sc.ds.RemoveFinalizerForSnapshot(snapshot)
}

if _, ok := snapshot.Status.Children["volume-head"]; ok && snapshot.Status.MarkRemoved {
// This snapshot is the parent of volume-head, so it cannot be purged immediately.
// We do not want to keep the volume stuck in attached state.
Expand All @@ -353,18 +362,6 @@ func (sc *SnapshotController) reconcile(snapshotName string) (err error) {
return err
}

// Wait for the snapshot to be removed from engine.Status.Snapshots
engine, err = sc.ds.GetEngineRO(engine.Name)
if err != nil {
return err
}
if _, ok := engine.Status.Snapshots[snapshot.Name]; !ok {
if err = sc.handleAttachmentTicketDeletion(snapshot); err != nil {
return err
}
return sc.ds.RemoveFinalizerForSnapshot(snapshot)
}

return nil
}

Expand Down

0 comments on commit 27caba8

Please sign in to comment.