Skip to content

Commit

Permalink
fix: attempt to delete unknown replica instances on cleanup
Browse files Browse the repository at this point in the history
Longhorn 6552

Signed-off-by: Eric Weber <eric.weber@suse.com>
(cherry picked from commit 1a1ab36)
  • Loading branch information
ejweber committed Sep 11, 2024
1 parent bab8861 commit ba835c5
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions controller/replica_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,11 +547,22 @@ func (rc *ReplicaController) DeleteInstance(obj interface{}) error {
}
}

if im.Status.CurrentState != longhorn.InstanceManagerStateRunning {
if shouldSkip, skipReason := shouldSkipReplicaDeletion(im.Status.CurrentState); shouldSkip {
log.Infof("Skipping deleting replica %v since %s", r.Name, skipReason)
return nil
}

c, err := engineapi.NewInstanceManagerClient(im, false)
defer func() {
if err != nil {
log.WithError(err).Warnf("Failed to delete replica process %v", r.Name)
if canIgnore, ignoreReason := canIgnoreReplicaDeletionFailure(im.Status.CurrentState); canIgnore {
log.Warnf("Ignored the failure to delete replica process %v because %s", r.Name, ignoreReason)
err = nil
}
}
}()

c, err := engineapi.NewInstanceManagerClient(im, true)
if err != nil {
return err
}
Expand Down Expand Up @@ -914,3 +925,21 @@ func hasMatchingReplica(replica *longhorn.Replica, replicas map[string]*longhorn
}
return false
}

func shouldSkipReplicaDeletion(imState longhorn.InstanceManagerState) (canSkip bool, reason string) {
// If the instance manager is in an unknown state, we should at least attempt instance deletion.
if imState == longhorn.InstanceManagerStateRunning || imState == longhorn.InstanceManagerStateUnknown {
return false, ""
}

return true, fmt.Sprintf("instance manager is in %v state", imState)
}

func canIgnoreReplicaDeletionFailure(imState longhorn.InstanceManagerState) (canIgnore bool, reason string) {
// Instance deletion is always best effort for an unknown instance manager.
if imState == longhorn.InstanceManagerStateUnknown {
return true, fmt.Sprintf("instance manager is in %v state", imState)
}

return false, ""
}

0 comments on commit ba835c5

Please sign in to comment.