Skip to content

Commit 3620b2d

Browse files
denikIsaac
andcommitted
bundle: keep recording deployment history when the setting is removed
A deployment that records history now keeps recording when experimental.deployment_history is left out; only an explicit false conflicts with the state. The state pull also starts the deployment lookup when the local state records history, not only when the config enables it. Co-authored-by: Isaac <no-reply@databricks.com>
1 parent 2be277b commit 3620b2d

8 files changed

Lines changed: 92 additions & 3 deletions

File tree

‎.nextchanges/bundles/7088.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Keep recording deployment history for a deployment when `experimental.deployment_history` is removed from the configuration; only an explicit `false` is rejected. ([#7088](https://github.com/databricks/cli/pull/7088))
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
bundle:
2+
name: dms-sticky-$UNIQUE_NAME
3+
experimental:
4+
deployment_history: true
5+
6+
resources:
7+
jobs:
8+
foo:
9+
name: sticky
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Cloud = true
2+
EnvMatrix.DMS = [""]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
=== Deploy with recording on
3+
>>> [CLI] bundle deploy
4+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/dms-sticky-[UNIQUE_NAME]/default/files...
5+
Created jobs.foo
6+
Files: 2 uploaded, 0 deleted
7+
Resources: 1 created, 0 changed, 0 deleted, 0 unchanged
8+
9+
=== Drop the setting: the deployment keeps recording, so the next deploy creates version 2
10+
>>> [CLI] bundle deploy
11+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/dms-sticky-[UNIQUE_NAME]/default/files...
12+
Updated jobs.foo
13+
Files: 1 uploaded, 0 deleted
14+
Resources: 0 created, 1 changed, 0 deleted, 0 unchanged
15+
16+
>>> print_requests.py --dms //api/2.0/bundle/deployments --oneline --del-body state,resource_id
17+
{"method": "POST", "path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions", "q": {"version_id": "2"}, "body": {"cli_version": "[CLI_VERSION]", "operations": [{"action_type": "OPERATION_ACTION_TYPE_UPDATE", "resource_key": "jobs.foo"}], "previous_version_id": "1", "version_type": "VERSION_TYPE_DEPLOY"}}
18+
{"method": "PATCH", "path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions/2/operations/jobs.foo", "q": {"update_mask": "state,error_message,resource_id,status"}, "body": {"error_message": "", "sequence_id": 0, "status": "OPERATION_STATUS_SUCCEEDED"}}
19+
{"method": "POST", "path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions/2/complete", "body": {"completion_reason": "VERSION_COMPLETE_SUCCESS"}}
20+
21+
=== Wiping the local cache does not change that: the recording state is pulled from the workspace
22+
>>> [CLI] bundle plan
23+
Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged
24+
25+
=== An explicit false still conflicts with the state
26+
>>> musterr [CLI] bundle deploy
27+
Error: deployment history setting (false) does not match the existing state (true)
28+
29+
Update experimental.deployment_history to match the existing deployment, or run "databricks bundle destroy" to start over
30+
31+
32+
>>> [CLI] bundle destroy --auto-approve
33+
The following resources will be deleted:
34+
delete resources.jobs.foo
35+
36+
All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/dms-sticky-[UNIQUE_NAME]/default
37+
38+
Destroy: 1 deleted
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
envsubst < databricks.yml.tmpl > databricks.yml
2+
3+
title "Deploy with recording on"
4+
trace $CLI bundle deploy
5+
rm -f "$OUT_REQUESTS"
6+
7+
title "Drop the setting: the deployment keeps recording, so the next deploy creates version 2"
8+
update_file.py databricks.yml 'experimental:
9+
deployment_history: true
10+
' ''
11+
update_file.py databricks.yml 'name: sticky' 'name: sticky-renamed'
12+
trace $CLI bundle deploy
13+
trace print_requests.py --dms //api/2.0/bundle/deployments --oneline --del-body state,resource_id
14+
15+
title "Wiping the local cache does not change that: the recording state is pulled from the workspace"
16+
rm -rf .databricks
17+
trace $CLI bundle plan
18+
rm -f "$OUT_REQUESTS"
19+
20+
title "An explicit false still conflicts with the state"
21+
update_file.py databricks.yml 'bundle:' 'experimental:
22+
deployment_history: false
23+
24+
bundle:'
25+
trace musterr $CLI bundle deploy
26+
update_file.py databricks.yml 'experimental:
27+
deployment_history: false
28+
29+
' ''
30+
31+
trace $CLI bundle destroy --auto-approve
32+
rm -f "$OUT_REQUESTS"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# The setting is driven from databricks.yml alone, so the env var must not turn it back on.
2+
EnvMatrix.DMS = [""]

‎bundle/statemgmt/state_pull.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,9 @@ func readStates(ctx context.Context, b *bundle.Bundle, alwaysPull AlwaysPull) ([
252252
})
253253

254254
// Whether the state records deployment history is only known once it is read, but the
255-
// lookup is needed right after; going by the config overlaps it with the reads. A state
256-
// that disagrees with the config is either rejected or looked up again by the caller.
257-
if ConfiguresDeploymentHistory(ctx, b) {
255+
// lookup is needed right after; going by the config and the local state overlaps it with
256+
// the reads. Without either, a recording state is looked up again by the caller.
257+
if ConfiguresDeploymentHistory(ctx, b) || (directLocalState != nil && directLocalState.IsDMS()) {
258258
wg.Go(func() {
259259
id, err := dms.LookupDeploymentID(ctx, b.WorkspaceClient(ctx), b.Config.Workspace.StatePath)
260260
deployment = &DeploymentLookup{ID: id, Err: err}

‎cmd/bundle/utils/process.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,11 @@ func enforceDeploymentHistorySetting(ctx context.Context, b *bundle.Bundle, stat
677677
if configured == recorded {
678678
return nil
679679
}
680+
// Recording sticks to a deployment that has it: leaving the setting out keeps it on, and only
681+
// an explicit false conflicts with the state.
682+
if recorded && (b.Config.Experimental == nil || b.Config.Experimental.DeploymentHistory == nil) {
683+
return nil
684+
}
680685
if requireMatch {
681686
return fmt.Errorf(`deployment history setting (%t) does not match the existing state (%t)
682687

0 commit comments

Comments
 (0)