Skip to content

Commit ea380fd

Browse files
committed
fix
1 parent d9ef8eb commit ea380fd

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

controller/node_controller.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,10 +1390,9 @@ func (nc *NodeController) getNewAndMissingOrphanedReplicaDataStores(diskName, di
13901390
if !ok {
13911391
if reused {
13921392
nc.logger.Infof("Orphan %v is reused by replica. Tring to mark DeleteCustomResourceOnly.", orphan.Name)
1393-
orphan = orphan.DeepCopy()
1394-
orphan.Labels[types.DeleteCustomResourceOnly] = string(longhorn.ConditionStatusTrue)
1395-
if _, err := nc.ds.UpdateOrphan(orphan); err != nil {
1396-
nc.logger.WithError(err).Warnf("Failed to update orphan %v after setting DeleteCustomResourceOnly label", orphan.Name)
1393+
if err := datastore.AddOrphanDeleteCustomResourceOnlyLabel(nc.ds, orphan.Name); err != nil {
1394+
nc.logger.Infof("failed to add label delete-custom-resource-only to orphan %v ", orphan.Name)
1395+
return map[string]string{}, map[string]string{}
13971396
}
13981397
}
13991398
nc.logger.Infof("Adding Orphan %v to missingOrphan", orphan.Name)

controller/orphan_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,8 @@ func (oc *OrphanController) checkOrphanedReplicaDataCleanable(node *longhorn.Nod
646646
return longhorn.OrphanConditionTypeDataCleanableReasonDiskEvicted
647647
}
648648

649-
value, _ := datastore.GetLonghornDeleteCustomResourceOnlyValue(orphan)
650-
if value == string(longhorn.ConditionStatusTrue) {
649+
exists, _ := datastore.IsLabelLonghornDeleteCustomResourceOnlyExisting(orphan)
650+
if exists {
651651
return longhorn.OrphanConditionTypeDataCleanableReasonSkipped
652652
}
653653

datastore/longhorn.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3359,11 +3359,8 @@ func GetLonghornDeleteCustomResourceOnlyValue(obj k8sruntime.Object) (string, er
33593359
if labels == nil {
33603360
return "", nil
33613361
}
3362-
value, ok := labels[types.GetLonghornLabelKey(types.DeleteCustomResourceOnly)]
3363-
if !ok {
3364-
return "", fmt.Errorf("label %q not found", types.GetLonghornLabelKey(types.DeleteCustomResourceOnly))
3365-
}
3366-
return value, nil
3362+
3363+
return labels[types.GetLonghornLabelKey(types.DeleteCustomResourceOnly)], nil
33673364
}
33683365

33693366
// labelLonghornDeleteCustomResourceOnly labels the object with the label `longhorn.io/delete-custom-resource-only: true`
@@ -3481,6 +3478,28 @@ func AddSystemBackupDeleteCustomResourceOnlyLabel(ds *DataStore, systemBackupNam
34813478
return nil
34823479
}
34833480

3481+
// AddOrphanDeleteCustomResourceOnlyLabel adds the label `longhorn.io/delete-custom-resource-only: true` to the Orphan
3482+
func AddOrphanDeleteCustomResourceOnlyLabel(ds *DataStore, OrphanName string) error {
3483+
logrus.Info("adding delete CR resource only label")
3484+
orphan, err := ds.GetOrphan(OrphanName)
3485+
if err != nil {
3486+
return err
3487+
}
3488+
if exists, err := IsLabelLonghornDeleteCustomResourceOnlyExisting(orphan); err != nil {
3489+
return err
3490+
} else if exists {
3491+
return nil
3492+
}
3493+
if err := labelLonghornDeleteCustomResourceOnly(orphan); err != nil {
3494+
return err
3495+
}
3496+
if _, err = ds.UpdateOrphan(orphan); err != nil {
3497+
return err
3498+
}
3499+
3500+
return nil
3501+
}
3502+
34843503
func FixupRecurringJob(v *longhorn.Volume) error {
34853504
if err := labelRecurringJobDefault(v); err != nil {
34863505
return err

types/types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,6 @@ func GetOrphanLabelsForOrphanedDirectory(nodeID, diskUUID string) map[string]str
667667
labels[GetLonghornLabelComponentKey()] = LonghornLabelOrphan
668668
labels[LonghornNodeKey] = nodeID
669669
labels[GetLonghornLabelKey(LonghornLabelOrphanType)] = string(longhorn.OrphanTypeReplicaData)
670-
labels[GetLonghornLabelKey(DeleteCustomResourceOnly)] = string(longhorn.ConditionStatusFalse)
671670
return labels
672671
}
673672

0 commit comments

Comments
 (0)