@@ -1360,25 +1360,21 @@ func (nc *NodeController) getNewAndMissingOrphanedReplicaDataStores(diskName, di
13601360 }
13611361
13621362 dataStore := orphan .Spec .Parameters [longhorn .OrphanDataName ]
1363- reused := false
13641363 for _ , r := range replicas {
13651364 if r .Spec .DataDirectoryName == dataStore {
1366- reused = true
1365+ if err := datastore .AddOrphanDeleteCustomResourceOnlyLabel (nc .ds , orphan .Name ); err != nil {
1366+ nc .logger .Infof ("failed to add label delete-custom-resource-only to orphan %v " , orphan .Name )
1367+ return map [string ]string {}, map [string ]string {}
1368+ }
1369+
13671370 break
13681371 }
13691372 }
13701373 _ , ok := orphanedReplicaDataStores [dataStore ]
13711374
13721375 if ! ok {
1373- if reused {
1374- if err := datastore .AddOrphanDeleteCustomResourceOnlyLabel (nc .ds , orphan .Name ); err != nil {
1375- nc .logger .Infof ("failed to add label delete-custom-resource-only to orphan %v " , orphan .Name )
1376- return map [string ]string {}, map [string ]string {}
1377- }
1378- }
13791376 missingOrphanedReplicaDataStores [dataStore ] = ""
13801377 }
1381-
13821378 }
13831379
13841380 return newOrphanedReplicaDataStores , missingOrphanedReplicaDataStores
@@ -1459,12 +1455,7 @@ func (nc *NodeController) canDeleteOrphan(orphan *longhorn.Orphan, autoDeleteEna
14591455
14601456 // When dataCleanableCondition is false, it means the associated node is not ready, missing or evicted (check updateDataCleanableCondition()).
14611457 // In this case, we can delete the orphan directly because the data is not reachable and no need to keep the orphan resource.
1462- isReasonNodeOrDisk := (dataCleanableCondition .Reason == longhorn .OrphanConditionTypeDataCleanableReasonNodeUnavailable ) ||
1463- (dataCleanableCondition .Reason == longhorn .OrphanConditionTypeDataCleanableReasonNodeEvicted ) ||
1464- (dataCleanableCondition .Reason == longhorn .OrphanConditionTypeDataCleanableReasonDiskInvalid ) ||
1465- (dataCleanableCondition .Reason == longhorn .OrphanConditionTypeDataCleanableReasonDiskEvicted ) ||
1466- (dataCleanableCondition .Reason == longhorn .OrphanConditionTypeDataCleanableReasonDiskChanged )
1467- canDelete := autoDeleteAllowed || ((dataCleanableCondition .Status == longhorn .ConditionStatusFalse ) && isReasonNodeOrDisk )
1458+ canDelete := autoDeleteAllowed || dataCleanableCondition .Status == longhorn .ConditionStatusFalse
14681459 if ! canDelete {
14691460 nc .logger .Debugf ("Orphan %v is not ready to be deleted, autoDeleteAllowed: %v, dataCleanableCondition: %v" , orphan .Name , autoDeleteAllowed , dataCleanableCondition .Status )
14701461 }
0 commit comments