@@ -368,6 +368,7 @@ func (h *InstanceHandler) ReconcileInstanceState(obj interface{}, spec *longhorn
368368
369369 if i , exists := instances [instanceName ]; exists && i .Status .State == longhorn .InstanceStateRunning {
370370 status .Started = true
371+ status .Starting = false
371372 break
372373 }
373374
@@ -388,18 +389,24 @@ func (h *InstanceHandler) ReconcileInstanceState(obj interface{}, spec *longhorn
388389 }
389390
390391 case longhorn .InstanceStateStopped :
392+ shouldDelete := false
391393 if im != nil && im .DeletionTimestamp == nil {
394+ if _ , exists := instances [instanceName ]; exists {
395+ shouldDelete = true
396+ }
397+ }
398+ if status .Starting {
399+ shouldDelete = true
400+ }
401+ if shouldDelete {
392402 // there is a delay between deleteInstance() invocation and state/InstanceManager update,
393403 // deleteInstance() may be called multiple times.
394- if instance , exists := instances [instanceName ]; exists {
395- if shouldDeleteInstance (& instance ) {
396- if err := h .deleteInstance (instanceName , runtimeObj ); err != nil {
397- return err
398- }
399- }
404+ if err := h .deleteInstance (instanceName , runtimeObj ); err != nil {
405+ return err
400406 }
401407 }
402408 status .Started = false
409+ status .Starting = false
403410 default :
404411 return fmt .Errorf ("unknown instance desire state: desire %v" , spec .DesireState )
405412 }
@@ -445,17 +452,6 @@ func (h *InstanceHandler) ReconcileInstanceState(obj interface{}, spec *longhorn
445452 return nil
446453}
447454
448- func shouldDeleteInstance (instance * longhorn.InstanceProcess ) bool {
449- // For a replica of a SPDK volume, a stopped replica means the lvol is not exposed,
450- // but the lvol is still there. We don't need to delete it.
451- if types .IsDataEngineV2 (instance .Spec .DataEngine ) {
452- if instance .Status .State == longhorn .InstanceStateStopped {
453- return false
454- }
455- }
456- return true
457- }
458-
459455func (h * InstanceHandler ) getInstancesFromInstanceManager (obj runtime.Object , instanceManager * longhorn.InstanceManager ) (map [string ]longhorn.InstanceProcess , error ) {
460456 switch obj .(type ) {
461457 case * longhorn.Engine :
0 commit comments