Skip to content

Commit 1e80693

Browse files
nzhan126derekbit
authored andcommitted
fix: ensure orphan CR retention when orphan-auto-deletion is false
ref:7795 Signed-off-by: Nina Zhan <[email protected]>
1 parent c441c6f commit 1e80693

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

controller/node_controller.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,9 @@ func (nc *NodeController) canDeleteOrphan(orphan *longhorn.Orphan, autoDeleteEna
14451445

14461446
// When dataCleanableCondition is false, it means the associated node is not ready, missing or evicted (check updateDataCleanableCondition()).
14471447
// In this case, we can delete the orphan directly because the data is not reachable and no need to keep the orphan resource.
1448-
canDelete := autoDeleteAllowed || dataCleanableCondition.Status == longhorn.ConditionStatusFalse
1448+
canDelete := autoDeleteAllowed || ((dataCleanableCondition.Status == longhorn.ConditionStatusFalse) &&
1449+
(dataCleanableCondition.Reason == longhorn.OrphanConditionTypeDataCleanableReasonNodeDeleted ||
1450+
dataCleanableCondition.Reason == longhorn.OrphanConditionTypeDataCleanableReasonNodeEvicted))
14491451
if !canDelete {
14501452
nc.logger.Debugf("Orphan %v is not ready to be deleted, autoDeleteAllowed: %v, dataCleanableCondition: %v", orphan.Name, autoDeleteAllowed, dataCleanableCondition.Status)
14511453
}

controller/orphan_controller.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -596,20 +596,20 @@ func (oc *OrphanController) updateDataCleanableCondition(orphan *longhorn.Orphan
596596
orphan.Status.Conditions = types.SetCondition(orphan.Status.Conditions, longhorn.OrphanConditionTypeDataCleanable, status, reason, "")
597597
}()
598598

599-
isUnavailable, err := oc.ds.IsNodeDownOrDeletedOrMissingManager(orphan.Spec.NodeID)
600-
if err != nil {
601-
return errors.Wrapf(err, "failed to check node down or missing manager for node %v", orphan.Spec.NodeID)
602-
}
603-
if isUnavailable {
604-
reason = longhorn.OrphanConditionTypeDataCleanableReasonNodeUnavailable
605-
return nil
606-
}
607-
608599
node, err := oc.ds.GetNode(orphan.Spec.NodeID)
609600
if err != nil {
610601
if !datastore.ErrorIsNotFound(err) {
611602
return fmt.Errorf("failed to get node %v", orphan.Spec.NodeID)
612603
}
604+
reason = longhorn.OrphanConditionTypeDataCleanableReasonNodeDeleted
605+
return nil
606+
}
607+
608+
isUnavailable, err := oc.ds.IsNodeDownOrDeletedOrMissingManager(orphan.Spec.NodeID)
609+
if err != nil {
610+
return errors.Wrapf(err, "failed to check node down or missing manager for node %v", orphan.Spec.NodeID)
611+
}
612+
if isUnavailable {
613613
reason = longhorn.OrphanConditionTypeDataCleanableReasonNodeUnavailable
614614
return nil
615615
}

k8s/pkg/apis/longhorn/v1beta2/orphan.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const (
1616
OrphanConditionTypeInstanceExist = "InstanceExist"
1717

1818
OrphanConditionTypeDataCleanableReasonNodeUnavailable = "NodeUnavailable"
19+
OrphanConditionTypeDataCleanableReasonNodeDeleted = "NodeDeleted"
1920
OrphanConditionTypeDataCleanableReasonNodeEvicted = "NodeEvicted"
2021
OrphanConditionTypeDataCleanableReasonDiskInvalid = "DiskInvalid"
2122
OrphanConditionTypeDataCleanableReasonDiskEvicted = "DiskEvicted"

0 commit comments

Comments
 (0)