Repository navigation
Distinguish resources removed from state in bundle summaries #7496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| * Report resources removed from bundle state after ignored deletion errors separately from deleted resources in bundle `deploy` and `destroy` output. ([#7496](https://github.com/databricks/cli/pull/7496)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| bundle: | ||
| name: test-deploy-summary-on-error |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| # fault.py registers its rule on the fake server, which a real workspace does not have. | ||
| Cloud = false | ||
|
|
||
| # A failed resource delete only surfaces as a destroy error with deployment | ||
| # history enabled, so pin that variant to exercise the error path deterministically. | ||
| # Start with history enabled to surface a delete error; the script also exercises | ||
| # ignored delete errors after disabling history for a fresh deployment. | ||
| EnvMatrix.DMS = ["true"] | ||
|
|
||
| Ignore = [".databricks"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ func (d *DeploymentUnit) withResourceKey(ctx context.Context) context.Context { | |
| return dresources.WithResourceKey(ctx, strings.TrimPrefix(d.ResourceKey, "resources.")) | ||
| } | ||
|
|
||
| func (d *DeploymentUnit) Destroy(ctx context.Context, db *dstate.DeploymentState) error { | ||
| func (d *DeploymentUnit) Destroy(ctx context.Context, db *dstate.DeploymentState, entry *deployplan.PlanEntry) error { | ||
| ctx = log.WithPrefix(ctx, "destroying "+d.ResourceKey) | ||
| ctx = d.withResourceKey(ctx) | ||
| id := db.GetResourceID(d.ResourceKey) | ||
|
|
@@ -30,7 +30,7 @@ func (d *DeploymentUnit) Destroy(ctx context.Context, db *dstate.DeploymentState | |
| return nil | ||
| } | ||
|
|
||
| return d.Delete(ctx, db, id) | ||
| return d.Delete(ctx, db, id, entry) | ||
| } | ||
|
|
||
| func (d *DeploymentUnit) Deploy(ctx context.Context, db *dstate.DeploymentState, newState any, actionType deployplan.ActionType, planEntry *deployplan.PlanEntry) error { | ||
|
|
@@ -261,19 +261,22 @@ func (d *DeploymentUnit) UpdateWithID(ctx context.Context, db *dstate.Deployment | |
| return nil | ||
| } | ||
|
|
||
| func (d *DeploymentUnit) Delete(ctx context.Context, db *dstate.DeploymentState, oldID string) error { | ||
| func (d *DeploymentUnit) Delete(ctx context.Context, db *dstate.DeploymentState, oldID string, entry *deployplan.PlanEntry) error { | ||
| oldState, err := d.loadPersistedState(db) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| err = d.Adapter.DoDelete(ctx, oldID, oldState) | ||
| // A parent-managed resource may remain if its parent is kept or fails to delete. | ||
| unbound := isManagedByParent(err) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. major: Parent-managed deletes are reported as "removed from state" although the parent's delete cascade-cleans them, with no name or reason
The output also contradicts itself. In Unlike the other two unbound branches (permission denied, no history), this branch logs nothing, and destroy prints no per-resource lines ( The case the PR description gives as justification (the parent is kept, or the parent's delete fails) is real, but no test covers it: the only parent-managed scenarios in the suite are destroys where the parent is deleted. Suggested changes (either one):
If the current behaviour stays, at least Evidence:
Agreed by 3 reviewer model(s). |
||
| if err != nil && !apierr.IsMissing(err) && !isManagedByParent(err) { | ||
| // Rather than failing delete and requiring user to unbind, we perform unbind automatically there. | ||
| // Some services, e.g. jobs, return 403 for missing resources if caller did not have permissions to it when job existed. | ||
| // In those cases 403 hides 404. In other cases, user not having permissions to resource but having in the bundle might | ||
| // mean configuration error that user is trying to fix by removing resource from their bundle. | ||
| if errors.Is(err, apierr.ErrPermissionDenied) { | ||
| unbound = true | ||
| log.Warnf(ctx, "Ignoring permission error when deleting %s id=%s: %s", d.ResourceKey, oldID, err) | ||
| } else if d.deleteConfirmedGone(ctx, oldID) { | ||
| log.Warnf(ctx, "Treating %s id=%s as already deleted despite delete error: %s", d.ResourceKey, oldID, err) | ||
|
|
@@ -282,13 +285,17 @@ func (d *DeploymentUnit) Delete(ctx context.Context, db *dstate.DeploymentState, | |
| err = fmt.Errorf("deleting id=%s: %w", oldID, err) | ||
| db.RecordFailure(d.ResourceKey, oldID, err) | ||
| return err | ||
| } else { | ||
| unbound = true | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without deployment history this branch ignores the delete error silently, so the new "Destroy: 2 deleted, 1 removed from state" (destroy/summary-on-error, settled_failure) names no resource and gives no reason. Can it |
||
| log.Warnf(ctx, "Ignoring error when deleting %s id=%s: %s", d.ResourceKey, oldID, err) | ||
| } | ||
| } | ||
|
|
||
| err = db.DeleteState(ctx, d.ResourceKey, false) | ||
| if err != nil { | ||
| return fmt.Errorf("deleting state id=%s: %w", oldID, err) | ||
| } | ||
| entry.Unbound = unbound | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor: Unbound deletes still run the delete-wait, and a wait failure counts one resource as both failed and removed from state
Polling after an ignored error is not new, but this PR newly ties it to the summary counts. Returning right after Evidence:
Agreed by 3 reviewer model(s). |
||
|
|
||
| // Wait for asynchronous teardown after dropping state. Mirrors Recreate so | ||
| // the contract is the same regardless of whether the user triggered | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isManagedByParentsetsunbound, so a destroy of a Lakebase branch plus its primary endpoint now prints "Destroy: 2 deleted, 1 removed from state" (postgres_endpoints/replace_existing) even though the parent delete cascade-removes the endpoint, as util.go:9 and that test's script say. Should parent-managed deletes keep counting as deleted rather than reading as left behind?