Skip to content

Commit 8ea7fbe

Browse files
committed
fix:ensure orphan CR retention when orphan-auto-deletion is false
ref:7795 Signed-off-by: Nina Zhan <[email protected]>
1 parent 73d4a9f commit 8ea7fbe

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

controller/node_controller.go

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

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

controller/orphan_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ 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)
599+
isUnavailable, err := oc.ds.IsNodeDownOrMissingManager(orphan.Spec.NodeID)
600600
if err != nil {
601601
return errors.Wrapf(err, "failed to check node down or missing manager for node %v", orphan.Spec.NodeID)
602602
}
@@ -610,7 +610,7 @@ func (oc *OrphanController) updateDataCleanableCondition(orphan *longhorn.Orphan
610610
if !datastore.ErrorIsNotFound(err) {
611611
return fmt.Errorf("failed to get node %v", orphan.Spec.NodeID)
612612
}
613-
reason = longhorn.OrphanConditionTypeDataCleanableReasonNodeUnavailable
613+
reason = longhorn.OrphanConditionTypeDataCleanableReasonNodeDeleted
614614
return nil
615615
}
616616

datastore/longhorn.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3050,6 +3050,24 @@ func (s *DataStore) RemoveFinalizerForNode(obj *longhorn.Node) error {
30503050
return nil
30513051
}
30523052

3053+
func (s *DataStore) IsNodeDownOrMissingManager(name string) (bool, error) {
3054+
if name == "" {
3055+
return false, errors.New("no node name provided to IsNodeDownOrDeletedOrMissingManager")
3056+
}
3057+
node, err := s.GetNodeRO(name)
3058+
if err != nil {
3059+
return false, err
3060+
}
3061+
cond := types.GetCondition(node.Status.Conditions, longhorn.NodeConditionTypeReady)
3062+
if cond.Status == longhorn.ConditionStatusFalse &&
3063+
(cond.Reason == string(longhorn.NodeConditionReasonKubernetesNodeGone) ||
3064+
cond.Reason == string(longhorn.NodeConditionReasonKubernetesNodeNotReady) ||
3065+
cond.Reason == string(longhorn.NodeConditionReasonManagerPodMissing)) {
3066+
return true, nil
3067+
}
3068+
return false, nil
3069+
}
3070+
30533071
func (s *DataStore) IsNodeDownOrDeletedOrMissingManager(name string) (bool, error) {
30543072
if name == "" {
30553073
return false, errors.New("no node name provided to IsNodeDownOrDeletedOrMissingManager")

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)