Skip to content

Commit d91d668

Browse files
denikIsaac
andcommitted
direct: separate advice for deploy and delete when another object is at the recorded ID
- Deploy suggests pointing the config at the renamed object, or unbind and bind; delete says no delete is sent and suggests deleting it outside the bundle. - The Gone comments mention another object at the recorded ID. - foreign_at_recorded_name and recreated_at_recorded_name show the failed deploy's requests; the plan step uses plan_filter.py. aws: TestAccept/bundle/resources/schemas/foreign_at_recorded_name TestAccept/bundle/resources/schemas/destroy_after_rename_out_of_band TestAccept/bundle/resources/schemas/recreated_at_recorded_name TestAccept/bundle/resources/volumes/foreign_at_recorded_name Co-authored-by: Isaac <no-reply@databricks.com>
1 parent 30938bb commit d91d668

8 files changed

Lines changed: 76 additions & 45 deletions

File tree

‎acceptance/bundle/resources/schemas/foreign_at_recorded_name/output.txt‎

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,29 @@ Resources: 1 created, 0 changed, 0 deleted, 0 unchanged
1818
=== The other schema has another schema_id, so the plan does not take it for the bundle's: it plans a create
1919

2020
>>> [CLI] bundle plan --output json
21-
Warning: resources.schemas.schema1: id="main.test-schema-[UNIQUE_NAME]" holds another object: its schema_id is "[FOREIGN_SCHEMA_ID]", not "[SCHEMA_ID]" as recorded, so this bundle leaves it in place. If it is the bundle's (deleted and created again outside the bundle), delete it outside the bundle, or manage it again with 'bundle deployment bind' while it is in the config ('bundle deployment unbind' first if the state still has it).
21+
Warning: resources.schemas.schema1: id="main.test-schema-[UNIQUE_NAME]" holds another object: its schema_id is "[FOREIGN_SCHEMA_ID]", not "[SCHEMA_ID]" as recorded, so this bundle does not take it for its own. If the bundle's was renamed outside the bundle, set its name in the config to the new one. If this object is the bundle's (deleted and created again outside the bundle), run 'bundle deployment unbind' and then 'bundle deployment bind' to manage it again.
2222

2323
{
24-
"resources.schemas.schema1": {
25-
"action": "create",
26-
"new_state": {
27-
"value": {
28-
"catalog_name": "main",
29-
"comment": "c1",
30-
"name": "test-schema-[UNIQUE_NAME]"
31-
}
32-
},
33-
"changes": {
34-
"schema_id": {
35-
"action": "skip",
36-
"reason": "internal_id",
37-
"old": "[SCHEMA_ID]"
24+
"plan_version": [PLAN_VERSION],
25+
"cli_version": "[CLI_VERSION]",
26+
"lineage": "[UUID]",
27+
"serial": 1,
28+
"plan": {
29+
"resources.schemas.schema1": {
30+
"action": "create",
31+
"new_state": {
32+
"value": {
33+
"catalog_name": "main",
34+
"comment": "c1",
35+
"name": "test-schema-[UNIQUE_NAME]"
36+
}
37+
},
38+
"changes": {
39+
"schema_id": {
40+
"action": "skip",
41+
"reason": "internal_id",
42+
"old": "[SCHEMA_ID]"
43+
}
3844
}
3945
}
4046
}
@@ -44,7 +50,7 @@ Warning: resources.schemas.schema1: id="main.test-schema-[UNIQUE_NAME]" holds an
4450

4551
>>> musterr [CLI] bundle deploy
4652
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files...
47-
Warning: resources.schemas.schema1: id="main.test-schema-[UNIQUE_NAME]" holds another object: its schema_id is "[FOREIGN_SCHEMA_ID]", not "[SCHEMA_ID]" as recorded, so this bundle leaves it in place. If it is the bundle's (deleted and created again outside the bundle), delete it outside the bundle, or manage it again with 'bundle deployment bind' while it is in the config ('bundle deployment unbind' first if the state still has it).
53+
Warning: resources.schemas.schema1: id="main.test-schema-[UNIQUE_NAME]" holds another object: its schema_id is "[FOREIGN_SCHEMA_ID]", not "[SCHEMA_ID]" as recorded, so this bundle does not take it for its own. If the bundle's was renamed outside the bundle, set its name in the config to the new one. If this object is the bundle's (deleted and created again outside the bundle), run 'bundle deployment unbind' and then 'bundle deployment bind' to manage it again.
4854

4955
Error: cannot create resources.schemas.schema1: Schema 'test-schema-[UNIQUE_NAME]' already exists (400 SCHEMA_ALREADY_EXISTS)
5056

@@ -55,10 +61,21 @@ API message: Schema 'test-schema-[UNIQUE_NAME]' already exists
5561

5662
Files: 2 uploaded, 0 deleted
5763

64+
>>> print_requests.py //unity-catalog
65+
{
66+
"method": "POST",
67+
"path": "/api/2.1/unity-catalog/schemas",
68+
"body": {
69+
"catalog_name": "main",
70+
"comment": "c1",
71+
"name": "test-schema-[UNIQUE_NAME]"
72+
}
73+
}
74+
5875
=== Destroy does not delete the other schema: it only drops the bundle's from the state
5976

6077
>>> [CLI] bundle destroy --auto-approve
61-
Warning: resources.schemas.schema1: id="main.test-schema-[UNIQUE_NAME]" holds another object: its schema_id is "[FOREIGN_SCHEMA_ID]", not "[SCHEMA_ID]" as recorded, so this bundle leaves it in place, and drops resources.schemas.schema1 from the deployment state. If it is the bundle's (deleted and created again outside the bundle), delete it outside the bundle, or manage it again with 'bundle deployment bind' while it is in the config ('bundle deployment unbind' first if the state still has it).
78+
Warning: resources.schemas.schema1: id="main.test-schema-[UNIQUE_NAME]" holds another object: its schema_id is "[FOREIGN_SCHEMA_ID]", not "[SCHEMA_ID]" as recorded, so no delete is sent for it, and resources.schemas.schema1 is dropped from the deployment state. If it is the bundle's (deleted and created again outside the bundle), delete it outside the bundle.
6279

6380
All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default
6481

‎acceptance/bundle/resources/schemas/foreign_at_recorded_name/script‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ cleanup() {
1313
}
1414
trap cleanup EXIT
1515

16-
# Drop the remote_state fields that differ between clouds or from the test server.
17-
plan() {
18-
trace $CLI bundle plan --output json | jq .plan | normalize_uc_payload.py created_at updated_at updated_by metastore_id effective_predictive_optimization_flag storage_location
19-
}
2016

2117
title "Deploy a schema"
2218
trace $CLI bundle deploy
@@ -29,11 +25,11 @@ add_repl "$($CLI schemas create "test-schema-${UNIQUE_NAME}" main | jq -r .schem
2925
print_requests.py //unity-catalog &> LOG.oob_requests
3026

3127
title "The other schema has another schema_id, so the plan does not take it for the bundle's: it plans a create"
32-
plan
28+
trace $CLI bundle plan --output json | plan_filter.py
3329

3430
title "Deploy leaves the other schema alone: the create fails on its name"
3531
trace musterr $CLI bundle deploy
36-
print_requests.py //unity-catalog &> LOG.failed_deploy_requests
32+
trace print_requests.py //unity-catalog
3733

3834
title "Destroy does not delete the other schema: it only drops the bundle's from the state"
3935
trace $CLI bundle destroy --auto-approve

‎acceptance/bundle/resources/schemas/recreated_at_recorded_name/output.txt‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ Resources: 1 created, 0 changed, 0 deleted, 0 unchanged
1414
=== The new schema has another schema_id: the bundle does not take it for its own, and deploy fails on its name
1515

1616
>>> [CLI] bundle plan
17-
Warning: resources.schemas.schema1: id="main.test-schema-[UNIQUE_NAME]" holds another object: its schema_id is "[NEW_SCHEMA_ID]", not "[SCHEMA_ID]" as recorded, so this bundle leaves it in place. If it is the bundle's (deleted and created again outside the bundle), delete it outside the bundle, or manage it again with 'bundle deployment bind' while it is in the config ('bundle deployment unbind' first if the state still has it).
17+
Warning: resources.schemas.schema1: id="main.test-schema-[UNIQUE_NAME]" holds another object: its schema_id is "[NEW_SCHEMA_ID]", not "[SCHEMA_ID]" as recorded, so this bundle does not take it for its own. If the bundle's was renamed outside the bundle, set its name in the config to the new one. If this object is the bundle's (deleted and created again outside the bundle), run 'bundle deployment unbind' and then 'bundle deployment bind' to manage it again.
1818

1919
create schemas.schema1
2020

2121
Plan: 1 to add, 0 to change, 0 to delete, 0 unchanged
2222

2323
>>> musterr [CLI] bundle deploy
2424
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files...
25-
Warning: resources.schemas.schema1: id="main.test-schema-[UNIQUE_NAME]" holds another object: its schema_id is "[NEW_SCHEMA_ID]", not "[SCHEMA_ID]" as recorded, so this bundle leaves it in place. If it is the bundle's (deleted and created again outside the bundle), delete it outside the bundle, or manage it again with 'bundle deployment bind' while it is in the config ('bundle deployment unbind' first if the state still has it).
25+
Warning: resources.schemas.schema1: id="main.test-schema-[UNIQUE_NAME]" holds another object: its schema_id is "[NEW_SCHEMA_ID]", not "[SCHEMA_ID]" as recorded, so this bundle does not take it for its own. If the bundle's was renamed outside the bundle, set its name in the config to the new one. If this object is the bundle's (deleted and created again outside the bundle), run 'bundle deployment unbind' and then 'bundle deployment bind' to manage it again.
2626

2727
Error: cannot create resources.schemas.schema1: Schema 'test-schema-[UNIQUE_NAME]' already exists (400 SCHEMA_ALREADY_EXISTS)
2828

@@ -33,6 +33,17 @@ API message: Schema 'test-schema-[UNIQUE_NAME]' already exists
3333

3434
Files: 2 uploaded, 0 deleted
3535

36+
>>> print_requests.py //unity-catalog
37+
{
38+
"method": "POST",
39+
"path": "/api/2.1/unity-catalog/schemas",
40+
"body": {
41+
"catalog_name": "main",
42+
"comment": "c1",
43+
"name": "test-schema-[UNIQUE_NAME]"
44+
}
45+
}
46+
3647
=== Binding it again makes it the bundle's
3748

3849
>>> [CLI] bundle deployment unbind schema1
@@ -44,7 +55,7 @@ Run 'bundle deploy' to deploy changes to your workspace
4455
>>> [CLI] bundle deploy
4556
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files...
4657
Updated schemas.schema1
47-
Files: 1 uploaded, 0 deleted
58+
Files: 0 uploaded, 0 deleted
4859
Resources: 0 created, 1 changed, 0 deleted, 0 unchanged
4960

5061
>>> [CLI] bundle plan

‎acceptance/bundle/resources/schemas/recreated_at_recorded_name/script‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ print_requests.py //unity-catalog &> LOG.oob_requests
2424
title "The new schema has another schema_id: the bundle does not take it for its own, and deploy fails on its name"
2525
trace $CLI bundle plan
2626
trace musterr $CLI bundle deploy
27-
print_requests.py //unity-catalog &> LOG.failed_deploy_requests
27+
trace print_requests.py //unity-catalog
2828

2929
title "Binding it again makes it the bundle's"
3030
trace $CLI bundle deployment unbind schema1

‎acceptance/bundle/resources/volumes/foreign_at_recorded_name/output.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Resources: 1 created, 0 changed, 0 deleted, 0 unchanged
1818
=== The other volume has another volume_id, so the plan does not take it for the bundle's: it plans a create
1919

2020
>>> [CLI] bundle plan
21-
Warning: resources.volumes.volume1: id="main.test-schema-[UNIQUE_NAME].myvolume" holds another object: its volume_id is "[FOREIGN_VOLUME_ID]", not "[VOLUME_ID]" as recorded, so this bundle leaves it in place. If it is the bundle's (deleted and created again outside the bundle), delete it outside the bundle, or manage it again with 'bundle deployment bind' while it is in the config ('bundle deployment unbind' first if the state still has it).
21+
Warning: resources.volumes.volume1: id="main.test-schema-[UNIQUE_NAME].myvolume" holds another object: its volume_id is "[FOREIGN_VOLUME_ID]", not "[VOLUME_ID]" as recorded, so this bundle does not take it for its own. If the bundle's was renamed outside the bundle, set its name in the config to the new one. If this object is the bundle's (deleted and created again outside the bundle), run 'bundle deployment unbind' and then 'bundle deployment bind' to manage it again.
2222

2323
create volumes.volume1
2424

@@ -27,7 +27,7 @@ Plan: 1 to add, 0 to change, 0 to delete, 0 unchanged
2727
=== Destroy does not delete the other volume: it only drops the bundle's from the state
2828

2929
>>> [CLI] bundle destroy --auto-approve
30-
Warning: resources.volumes.volume1: id="main.test-schema-[UNIQUE_NAME].myvolume" holds another object: its volume_id is "[FOREIGN_VOLUME_ID]", not "[VOLUME_ID]" as recorded, so this bundle leaves it in place, and drops resources.volumes.volume1 from the deployment state. If it is the bundle's (deleted and created again outside the bundle), delete it outside the bundle, or manage it again with 'bundle deployment bind' while it is in the config ('bundle deployment unbind' first if the state still has it).
30+
Warning: resources.volumes.volume1: id="main.test-schema-[UNIQUE_NAME].myvolume" holds another object: its volume_id is "[FOREIGN_VOLUME_ID]", not "[VOLUME_ID]" as recorded, so no delete is sent for it, and resources.volumes.volume1 is dropped from the deployment state. If it is the bundle's (deleted and created again outside the bundle), delete it outside the bundle.
3131

3232
All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default
3333

‎bundle/deployplan/action.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ type Action struct {
1010
ResourceKey string
1111
ActionType ActionType
1212
// Gone mirrors PlanEntry.Gone: the delete is a state-only cleanup because the
13-
// resource no longer exists remotely (confirmed by a read, or an empty-ID state entry).
13+
// resource no longer exists remotely (confirmed by a read, another object at its ID,
14+
// or an empty-ID state entry).
1415
Gone bool
1516
// StateOnly mirrors PlanEntry.StateOnly: applying the action only changes the state
1617
// (a delete of a resource without DoDelete, or a re-key).

‎bundle/deployplan/plan.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ type PlanEntry struct {
131131
DependsOn []DependsOnEntry `json:"depends_on,omitempty"`
132132
Action ActionType `json:"action,omitempty"`
133133
// Gone is set on Delete entries when the resource no longer exists remotely: planning
134-
// confirmed it with a read, or the state entry has an empty ID (left by a recreate in
135-
// an older CLI whose create step failed after the delete). Applying such an entry only
134+
// confirmed it with a read, or found another object at its ID (an internal ID that is
135+
// not the recorded one), or the state entry has an empty ID (left by a recreate in an
136+
// older CLI whose create step failed after the delete). Applying such an entry only
136137
// removes it from the state, without calling the delete API, and approval prompts do
137138
// not list it as a deletion.
138139
Gone bool `json:"gone,omitempty"`

‎bundle/direct/bundle_plan.go‎

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -262,16 +262,16 @@ func (b *DeploymentBundle) CalculatePlan(ctx context.Context, client *databricks
262262
// Treat it as gone: apply cleans up state without re-issuing the delete.
263263
entry.Gone = true
264264
} else {
265-
// Someone else's resource under the name ours had is never deleted: it is left in
266-
// place, and only the state entry is dropped.
265+
// Someone else's resource under the name ours had is never deleted: no delete is
266+
// sent for it, and only the state entry is dropped.
267267
message, err := b.otherObjectAtRecordedID(resourceKey, adapter, id, remoteState)
268268
if err != nil {
269269
logdiag.LogError(ctx, fmt.Errorf("%s: %w", errorPrefix, err))
270270
return false
271271
}
272272
if message != "" {
273-
logdiag.LogDiag(ctx, diag.Warningf("%s: %s, and drops %s from the deployment state. %s",
274-
resourceKey, message, resourceKey, otherObjectAdvice)[0])
273+
logdiag.LogDiag(ctx, diag.Warningf("%s: %s, so no delete is sent for it, and %s is dropped from the deployment state. %s",
274+
resourceKey, message, resourceKey, otherObjectDeleteAdvice)[0])
275275
entry.Gone = true
276276
remoteState = nil
277277
}
@@ -382,8 +382,8 @@ func (b *DeploymentBundle) CalculatePlan(ctx context.Context, client *databricks
382382
}
383383
}
384384
if otherID != "" && remoteState == nil {
385-
logdiag.LogDiag(ctx, diag.Warningf("%s: %s. %s",
386-
resourceKey, otherObjectMessage(adapter, dbentry.ID, savedState, otherID), otherObjectAdvice)[0])
385+
logdiag.LogDiag(ctx, diag.Warningf("%s: %s, so this bundle does not take it for its own. %s",
386+
resourceKey, otherObjectMessage(adapter, dbentry.ID, savedState, otherID), otherObjectDeployAdvice)[0])
387387
}
388388

389389
// We have a choice whether to include remoteState or remoteStateComparable from below.
@@ -921,18 +921,23 @@ func otherInternalID(adapter *dresources.Adapter, savedState, remote any) (strin
921921
return found, nil
922922
}
923923

924-
// otherObjectMessage says that what is at the recorded ID id is not the bundle's: the plan leaves it
925-
// alone. It is told when the bundle's own is not found elsewhere either; a resource deleted and
926-
// created again out of band looks the same, hence otherObjectAdvice.
924+
// otherObjectMessage says that what is at the recorded ID id is not the bundle's. It is told when
925+
// the bundle's own is not found elsewhere either; a resource deleted and created again out of band
926+
// looks the same, hence the advice the callers add.
927927
func otherObjectMessage(adapter *dresources.Adapter, id string, savedState any, otherID string) string {
928928
saved, _ := adapter.InternalID(savedState)
929-
return fmt.Sprintf("id=%q holds another object: its %s is %q, not %q as recorded, so this bundle leaves it in place",
929+
return fmt.Sprintf("id=%q holds another object: its %s is %q, not %q as recorded",
930930
id, adapter.ResourceConfig().InternalIDField, otherID, saved)
931931
}
932932

933-
// otherObjectAdvice follows otherObjectMessage, for a resource still in the config (deploy) as well as
934-
// one removed from it (a Delete): bind needs the resource in the config, and a free state entry.
935-
const otherObjectAdvice = "If it is the bundle's (deleted and created again outside the bundle), delete it outside the bundle, or manage it again with 'bundle deployment bind' while it is in the config ('bundle deployment unbind' first if the state still has it)."
933+
// otherObjectDeployAdvice follows otherObjectMessage for a resource in the config. The bundle's own
934+
// may still exist under another name (renamed out of band), which findMoved takes once the config
935+
// names it. Bind needs a free state entry, hence unbind first.
936+
const otherObjectDeployAdvice = "If the bundle's was renamed outside the bundle, set its name in the config to the new one. If this object is the bundle's (deleted and created again outside the bundle), run 'bundle deployment unbind' and then 'bundle deployment bind' to manage it again."
937+
938+
// otherObjectDeleteAdvice follows otherObjectMessage for a resource being deleted: its state entry
939+
// is dropped, and it may no longer be in the config, so binding it is not an option.
940+
const otherObjectDeleteAdvice = "If it is the bundle's (deleted and created again outside the bundle), delete it outside the bundle."
936941

937942
// otherObjectAtRecordedID returns, for a resource to be deleted, what otherObjectMessage says when
938943
// remote, read at its recorded ID id, is another object than the one the state records; "" when it

0 commit comments

Comments
 (0)