Skip to content

Commit 8d1ad0b

Browse files
denikIsaac
andcommitted
direct: inline the WaitAfterDelete NotFound handling at the call sites
Drop the waitDeleted helper; the recreate and destroy call sites now call Adapter.WaitAfterDelete directly and treat a NotFound as success inline. This also keeps deleteConfirmedGone's doc comment with its own function. Co-authored-by: Isaac <[email protected]>
1 parent fafffa8 commit 8d1ad0b

1 file changed

Lines changed: 6 additions & 14 deletions

File tree

‎bundle/direct/apply.go‎

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,9 @@ func (d *DeploymentUnit) Recreate(ctx context.Context, db *dstate.DeploymentStat
140140
// times out — the resource is no longer tracked in state, retry on next plan.
141141
// The general delete-wait stays uncapped; we only pass the already-resolved
142142
// RESOURCE_MAX_WAIT so a resource that opts in can bound its own poll by it.
143-
err = d.waitDeleted(dresources.WithResourceMaxWait(ctx, d.MaxWait), oldID)
144-
if err != nil {
143+
// A NotFound means the resource is gone, which is the success the wait polls for.
144+
err = d.Adapter.WaitAfterDelete(dresources.WithResourceMaxWait(ctx, d.MaxWait), oldID)
145+
if err != nil && !apierr.IsMissing(err) {
145146
return fmt.Errorf("waiting after deleting id=%s: %w", oldID, err)
146147
}
147148

@@ -280,9 +281,10 @@ func (d *DeploymentUnit) Delete(ctx context.Context, db *dstate.DeploymentState,
280281
// The two diverge once MaxWait is set: this wait is capped, Recreate's is not,
281282
// because only Recreate needs the name released for the create that follows.
282283
_, err = waitCapped(ctx, d.MaxWait, "deletion of "+d.ResourceKey, func(ctx context.Context) (struct{}, error) {
283-
return struct{}{}, d.waitDeleted(ctx, oldID)
284+
return struct{}{}, d.Adapter.WaitAfterDelete(ctx, oldID)
284285
})
285-
if err != nil {
286+
// A NotFound means the resource is gone, which is the success the wait polls for.
287+
if err != nil && !apierr.IsMissing(err) {
286288
return fmt.Errorf("waiting after deleting id=%s: %w", oldID, err)
287289
}
288290

@@ -297,16 +299,6 @@ func (d *DeploymentUnit) Delete(ctx context.Context, db *dstate.DeploymentState,
297299
// may enter that state only after the plan is saved. We re-read rather than match
298300
// the delete error because the backend returns a generic 400 BAD_REQUEST (see
299301
// apps/src/utils/AppsStatusUtils.scala) that carries no distinct SDK sentinel.
300-
// waitDeleted runs the resource's post-delete wait, treating a NotFound as the
301-
// success it is polling for — the resource is gone.
302-
func (d *DeploymentUnit) waitDeleted(ctx context.Context, id string) error {
303-
err := d.Adapter.WaitAfterDelete(ctx, id)
304-
if apierr.IsMissing(err) {
305-
return nil
306-
}
307-
return err
308-
}
309-
310302
func (d *DeploymentUnit) deleteConfirmedGone(ctx context.Context, id string) bool {
311303
remote, err := d.Adapter.DoRead(ctx, id)
312304
if apierr.IsMissing(err) {

0 commit comments

Comments
 (0)