Skip to content

Commit 9b53ecf

Browse files
authored
handle external recreations during deletions better (#236)
* handle external recreations during deletions better * correct typo
1 parent bddb9a4 commit 9b53ecf

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

pkg/component/reconciler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import (
5959
// TODO: finalizer should have the standard format prefix/finalizer
6060
// TODO: currently, the reconciler always claims/owns dependent objects entirely; but due to server-side-apply it can happen that
6161
// only parts of an object are managed: other parts/fiels might be managed by other actors (or even other components); how to handle such cases?
62+
// TODO: we maybe should incorporate metadata.uid into the inventory to better detect (foreign) recreations of objects that were already managed by us
6263

6364
const (
6465
readyConditionReasonNew = "FirstSeen"

pkg/reconciler/reconciler.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,8 @@ func (r *Reconciler) Apply(ctx context.Context, inventory *[]*InventoryItem, obj
594594
item.Phase = PhaseCompleted
595595
item.Status = ""
596596
} else {
597+
// TODO: should we (similar to the delete cases) check deletion timestamp and ownership to void deadlocks if object
598+
// was recreated by someone else
597599
numToBeCompleted++
598600
}
599601
}
@@ -793,11 +795,20 @@ func (r *Reconciler) Apply(ctx context.Context, inventory *[]*InventoryItem, obj
793795
numToBeDeleted++
794796
}
795797
case PhaseDeleting:
796-
// if object is gone, we can remove it from inventory
797798
if existingObject == nil {
799+
// if object is gone, we can remove it from inventory
798800
item.Phase = ""
799-
} else {
801+
} else if !existingObject.GetDeletionTimestamp().IsZero() {
802+
// object is still there and deleting, waiting until it goes away
800803
numToBeDeleted++
804+
} else if existingObject.GetLabels()[r.labelKeyOwnerId] != hashedOwnerId {
805+
// object is there but not deleting; if we are not owning it that means that somebody else has
806+
// recreated it in the meantime; so we consider this as not our problem and remove it from inventory
807+
log.V(1).Info("orphaning resurrected object (probably it was recreated by someone else)", "key", types.ObjectKeyToString(item))
808+
item.Phase = ""
809+
} else {
810+
// object is there, not deleting, but we own it; that is really strange and should actually not happen
811+
return false, fmt.Errorf("object %s was already deleted but has no deletion timestamp", types.ObjectKeyToString(item))
801812
}
802813
default:
803814
// note: any other phase value would indicate a severe code problem, so we want to see the panic in that case
@@ -872,11 +883,20 @@ func (r *Reconciler) Delete(ctx context.Context, inventory *[]*InventoryItem, ow
872883

873884
switch item.Phase {
874885
case PhaseDeleting:
875-
// if object is gone, we can remove it from inventory
876886
if existingObject == nil {
887+
// if object is gone, we can remove it from inventory
877888
item.Phase = ""
878-
} else {
889+
} else if !existingObject.GetDeletionTimestamp().IsZero() {
890+
// object is still there and deleting, waiting until it goes away
879891
numToBeDeleted++
892+
} else if existingObject.GetLabels()[r.labelKeyOwnerId] != hashedOwnerId {
893+
// object is there but not deleting; if we are not owning it that means that somebody else has
894+
// recreated it in the meantime; so we consider this as not our problem and remove it from inventory
895+
log.V(1).Info("orphaning resurrected object (probably it was recreated by someone else)", "key", types.ObjectKeyToString(item))
896+
item.Phase = ""
897+
} else {
898+
// object is there, not deleting, but we own it; that is really strange and should actually not happen
899+
return false, fmt.Errorf("object %s was already deleted but has no deletion timestamp", types.ObjectKeyToString(item))
880900
}
881901
default:
882902
// delete namespaces after all contained inventory items

0 commit comments

Comments
 (0)