Skip to content

Commit

Permalink
chore: fix nodeclaim going unknown during instance termination (#1835)
Browse files Browse the repository at this point in the history
  • Loading branch information
rschalo authored Nov 22, 2024
1 parent 2ab4871 commit af17c94
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/utils/termination/termination.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func EnsureTerminated(ctx context.Context, c client.Client, nodeClaim *v1.NodeCl
if err = cloudProvider.Delete(ctx, nodeClaim); err != nil {
if cloudprovider.IsNodeClaimNotFoundError(err) {
stored := nodeClaim.DeepCopy()
nodeClaim.StatusConditions().SetTrue(v1.ConditionTypeInstanceTerminating)
updateStatusConditionsForDeleting(nodeClaim)
// We use client.MergeFromWithOptimisticLock because patching a list with a JSON merge patch
// can cause races due to the fact that it fully replaces the list on a change
// Here, we are updating the status condition list
Expand All @@ -51,7 +51,7 @@ func EnsureTerminated(ctx context.Context, c client.Client, nodeClaim *v1.NodeCl
}

stored := nodeClaim.DeepCopy()
nodeClaim.StatusConditions().SetTrue(v1.ConditionTypeInstanceTerminating)
updateStatusConditionsForDeleting(nodeClaim)
// We use client.MergeFromWithOptimisticLock because patching a list with a JSON merge patch
// can cause races due to the fact that it fully replaces the list on a change
// Here, we are updating the status condition list
Expand All @@ -69,3 +69,13 @@ func EnsureTerminated(ctx context.Context, c client.Client, nodeClaim *v1.NodeCl
}
return false, nil
}

func updateStatusConditionsForDeleting(nc *v1.NodeClaim) {
// perform a no-op for whatever the status condition is currently set to
// so that we bump the observed generation to the latest and prevent the nodeclaim
// root status from entering an `Unknown` state
for _, condition := range nc.Status.Conditions {
nc.StatusConditions().Set(condition)
}
nc.StatusConditions().SetTrue(v1.ConditionTypeInstanceTerminating)
}

0 comments on commit af17c94

Please sign in to comment.