Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nextchanges/bundles/remote-sync-cluster-policies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Fix `bundle config-remote-sync` copying cluster policy values into shared configuration and breaking deployment to another target. ([#7170](https://github.com/databricks/cli/pull/7170))
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
bundle:
name: test-bundle-$UNIQUE_NAME

workspace:
root_path: ~/.bundle/$UNIQUE_NAME/${bundle.target}

variables:
environment:
default: dev

resources:
cluster_policies:
policy:
name: test-policy-$UNIQUE_NAME-${bundle.target}
definition:
custom_tags.workspace:
type: fixed
value: ${var.environment}
spark_env_vars.ENVIRONMENT:
type: fixed
value: ${var.environment}
workload_type.clients.jobs:
type: fixed
value: true
workload_type.clients.notebooks:
type: fixed
value: false
jobs:
policy_sync:
name: test-job-$UNIQUE_NAME-${bundle.target}
description: Before UI edit
job_clusters:
- job_cluster_key: main
new_cluster:
policy_id: ${resources.cluster_policies.policy.id}
spark_version: $DEFAULT_SPARK_VERSION
node_type_id: $NODE_TYPE_ID
num_workers: 1
custom_tags:
owner: bundle-author
tasks:
- task_key: main
job_cluster_key: main
spark_python_task:
python_file: ./hello.py

targets:
dev:
default: true
prod:
variables:
environment: prod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("hello")
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Cloud = true
GOOS.windows = false
EnvMatrix.DMS = ["", "true"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

=== Deploy with the dev policy
>>> [CLI] bundle deploy -t dev
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/dev/files...
Created cluster_policies.policy
Created jobs.policy_sync
Files: 3 uploaded, 0 deleted
Resources: 2 created, 0 changed, 0 deleted, 0 unchanged

=== Sync the UI edit into shared YAML
>>> [CLI] bundle config-remote-sync -t dev --save
Detected changes in 1 resource(s):

Resource: resources.jobs.policy_sync
description: replace



>>> diff.py databricks.yml.backup databricks.yml
--- databricks.yml.backup
+++ databricks.yml
@@ -29,5 +29,5 @@
policy_sync:
name: test-job-[UNIQUE_NAME]-${bundle.target}
- description: Before UI edit
+ description: Edited in the UI
job_clusters:
- job_cluster_key: main

=== Deploy shared YAML with the prod policy
>>> errcode [CLI] bundle deploy -t prod
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/prod/files...
Created cluster_policies.policy
Created jobs.policy_sync
Files: 4 uploaded, 0 deleted
Resources: 2 created, 0 changed, 0 deleted, 0 unchanged

>>> [CLI] bundle destroy -t prod --auto-approve
The following resources will be deleted:
delete resources.cluster_policies.policy
delete resources.jobs.policy_sync

All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/prod

Destroy: 2 deleted

>>> [CLI] bundle destroy -t dev --auto-approve
The following resources will be deleted:
delete resources.cluster_policies.policy
delete resources.jobs.policy_sync

All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/dev

Destroy: 2 deleted
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
envsubst < databricks.yml.tmpl > databricks.yml

cleanup() {
trace $CLI bundle destroy -t prod --auto-approve
trace $CLI bundle destroy -t dev --auto-approve
}
trap cleanup EXIT

title "Deploy with the dev policy"
trace $CLI bundle deploy -t dev
job_id=$(read_id.py -t dev policy_sync)

edit_resource.py jobs "$job_id" <<'EOF'
r["description"] = "Edited in the UI"
EOF

title "Sync the UI edit into shared YAML"
cp databricks.yml databricks.yml.backup
trace $CLI bundle config-remote-sync -t dev --save
trace diff.py databricks.yml.backup databricks.yml

title "Deploy shared YAML with the prod policy"
trace errcode $CLI bundle deploy -t prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Cloud = true
RecordRequests = false
Ignore = [".databricks", "databricks.yml", "databricks.yml.backup"]
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ Resources: 2 created, 0 changed, 0 deleted, 0 unchanged
Detected changes in 1 resource(s):

Resource: resources.jobs.test_job
tasks[task_key='test'].new_cluster.custom_tags: add
tasks[task_key='test'].new_cluster.spark_conf: add



>>> diff.py databricks.yml.backup databricks.yml
--- databricks.yml.backup
+++ databricks.yml
@@ -24,4 +24,6 @@
@@ -24,4 +24,8 @@
node_type_id: [NODE_TYPE_ID]
num_workers: 1
+ custom_tags:
+ UserTag: edited-in-ui
+ spark_conf:
+ spark.sql.shuffle.partitions: "7"
spark_python_task:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ job_id=$(read_id.py test_job)

edit_resource.py jobs "$job_id" <<'EOF'
r["tasks"][0]["new_cluster"]["spark_conf"] = {"spark.sql.shuffle.partitions": "7"}
r["tasks"][0]["new_cluster"]["custom_tags"]["UserTag"] = "edited-in-ui"
EOF

cp databricks.yml databricks.yml.backup
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
bundle:
name: test-bundle-$UNIQUE_NAME

workspace:
root_path: ~/.bundle/$UNIQUE_NAME/${bundle.target}

variables:
policy_id:
description: Policy managed outside this bundle

resources:
jobs:
policy_sync:
name: test-job-$UNIQUE_NAME-${bundle.target}
description: Before UI edit
job_clusters:
- job_cluster_key: main
new_cluster:
policy_id: ${var.policy_id}
spark_version: $DEFAULT_SPARK_VERSION
node_type_id: $NODE_TYPE_ID
num_workers: 1
custom_tags:
owner: bundle-author
tasks:
- task_key: main
job_cluster_key: main
spark_python_task:
python_file: ./hello.py

targets:
dev:
default: true
variables:
policy_id: $DEV_POLICY_ID
prod:
variables:
policy_id: $PROD_POLICY_ID
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("hello")
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Cloud = true
GOOS.windows = false
EnvMatrix.DMS = ["", "true"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

=== Create policies outside the bundle
=== Deploy with the dev policy
>>> [CLI] bundle deploy -t dev
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/dev/files...
Created jobs.policy_sync
Files: 4 uploaded, 0 deleted
Resources: 1 created, 0 changed, 0 deleted, 0 unchanged

=== Sync the UI edit into shared YAML
>>> [CLI] bundle config-remote-sync -t dev --save
Detected changes in 1 resource(s):

Resource: resources.jobs.policy_sync
description: replace



>>> diff.py databricks.yml.backup databricks.yml
--- databricks.yml.backup
+++ databricks.yml
@@ -13,5 +13,5 @@
policy_sync:
name: test-job-[UNIQUE_NAME]-${bundle.target}
- description: Before UI edit
+ description: Edited in the UI
job_clusters:
- job_cluster_key: main

=== Deploy shared YAML with the prod policy
>>> errcode [CLI] bundle deploy -t prod
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/prod/files...
Created jobs.policy_sync
Files: 5 uploaded, 0 deleted
Resources: 1 created, 0 changed, 0 deleted, 0 unchanged

>>> [CLI] bundle destroy -t prod --auto-approve
The following resources will be deleted:
delete resources.jobs.policy_sync

All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/prod

Destroy: 1 deleted

>>> [CLI] bundle destroy -t dev --auto-approve
The following resources will be deleted:
delete resources.jobs.policy_sync

All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/dev

Destroy: 1 deleted

>>> [CLI] cluster-policies delete [DEV_POLICY_ID]

>>> [CLI] cluster-policies delete [PROD_POLICY_ID]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "test-external-policy-$UNIQUE_NAME-$POLICY_ENVIRONMENT",
"definition": "{\"custom_tags.workspace\":{\"type\":\"fixed\",\"value\":\"$POLICY_ENVIRONMENT\"},\"spark_env_vars.ENVIRONMENT\":{\"type\":\"fixed\",\"value\":\"$POLICY_ENVIRONMENT\"}}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
title "Create policies outside the bundle"
export POLICY_ENVIRONMENT=dev
export DEV_POLICY_ID
DEV_POLICY_ID=$($CLI cluster-policies create --json "$(envsubst < policy.json.tmpl)" -o json | jq -r .policy_id)
add_repl "$DEV_POLICY_ID" DEV_POLICY_ID
export POLICY_ENVIRONMENT=prod
export PROD_POLICY_ID
PROD_POLICY_ID=$($CLI cluster-policies create --json "$(envsubst < policy.json.tmpl)" -o json | jq -r .policy_id)
add_repl "$PROD_POLICY_ID" PROD_POLICY_ID

envsubst < databricks.yml.tmpl > databricks.yml

cleanup() {
trace $CLI bundle destroy -t prod --auto-approve
trace $CLI bundle destroy -t dev --auto-approve
trace $CLI cluster-policies delete "$DEV_POLICY_ID"
trace $CLI cluster-policies delete "$PROD_POLICY_ID"
}
trap cleanup EXIT

title "Deploy with the dev policy"
trace $CLI bundle deploy -t dev
job_id=$(read_id.py -t dev policy_sync)

edit_resource.py jobs "$job_id" <<'EOF'
r["description"] = "Edited in the UI"
EOF

title "Sync the UI edit into shared YAML"
cp databricks.yml databricks.yml.backup
trace $CLI bundle config-remote-sync -t dev --save
trace diff.py databricks.yml.backup databricks.yml

title "Deploy shared YAML with the prod policy"
trace errcode $CLI bundle deploy -t prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Cloud = true
RecordRequests = false
Ignore = [".databricks", "databricks.yml", "databricks.yml.backup"]
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,29 @@ targets:
mode: development

resources:
cluster_policies:
policy:
name: test-policy-$UNIQUE_NAME
definition:
custom_tags.CostCenter:
type: fixed
value: dev-1234
custom_tags.Team:
type: fixed
value: finops
cluster_log_conf.type:
type: fixed
value: DBFS
cluster_log_conf.path:
type: fixed
value: dbfs:/cluster-logs/dev
jobs:
job1:
max_concurrent_runs: 1
job_clusters:
- job_cluster_key: shared
new_cluster:
policy_id: ${resources.cluster_policies.policy.id}
spark_version: $DEFAULT_SPARK_VERSION
node_type_id: $NODE_TYPE_ID
num_workers: 1
Expand All @@ -24,6 +41,7 @@ resources:
notebook_task:
notebook_path: /Users/{{workspace_user_name}}/notebook
new_cluster:
policy_id: ${resources.cluster_policies.policy.id}
spark_version: $DEFAULT_SPARK_VERSION
node_type_id: $NODE_TYPE_ID
num_workers: 1
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files...
Created cluster_policies.policy
Created jobs.job1
Files: 2 uploaded, 0 deleted
Resources: 1 created, 0 changed, 0 deleted, 0 unchanged
Resources: 2 created, 0 changed, 0 deleted, 0 unchanged

=== Simulate a cluster policy injecting custom_tags and cluster_log_conf
These fields exist only remotely (the user never set them in config).
Expand All @@ -20,7 +21,7 @@ Resource: resources.jobs.job1
>>> diff.py databricks.yml.backup databricks.yml
--- databricks.yml.backup
+++ databricks.yml
@@ -9,5 +9,5 @@
@@ -25,5 +25,5 @@
jobs:
job1:
- max_concurrent_runs: 1
Expand All @@ -30,8 +31,9 @@ Resource: resources.jobs.job1

>>> [CLI] bundle destroy --auto-approve
The following resources will be deleted:
delete resources.cluster_policies.policy
delete resources.jobs.job1

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

Destroy: 1 deleted
Destroy: 2 deleted
Loading
Loading