Repository navigation
Fix app resource drift on config field #7326
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| * Fix `bundle plan` reporting an update to an app's `config.env` values on every run, which also redeployed the app on every `bundle deploy`. The Apps API returns environment variable names only, so `value` and `value_from` are no longer compared against the remote deployment. ([#7326](https://github.com/databricks/cli/pull/7326)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
acceptance/bundle/resources/apps/config-env-no-drift/app/app.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import http.server, os | ||
|
|
||
| http.server.HTTPServer( | ||
| ("", int(os.environ["DATABRICKS_APP_PORT"])), http.server.SimpleHTTPRequestHandler | ||
| ).serve_forever() |
25 changes: 25 additions & 0 deletions
25
acceptance/bundle/resources/apps/config-env-no-drift/databricks.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| bundle: | ||
| name: apps-config-env-no-drift | ||
|
|
||
| resources: | ||
| apps: | ||
| myapp: | ||
| name: myapp | ||
| source_code_path: ./app | ||
| resources: | ||
| - name: my-secret | ||
| secret: | ||
| scope: my-scope | ||
| key: my-key | ||
| permission: READ | ||
| config: | ||
| command: | ||
| - python | ||
| - app.py | ||
| env: | ||
| - name: GREETING | ||
| value: hello | ||
| - name: API_TOKEN | ||
| value_from: my-secret | ||
| lifecycle: | ||
| started: true |
2 changes: 2 additions & 0 deletions
2
acceptance/bundle/resources/apps/config-env-no-drift/out.test.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Cloud = false | ||
| EnvMatrix.DMS = ["", "true"] |
81 changes: 81 additions & 0 deletions
81
acceptance/bundle/resources/apps/config-env-no-drift/output.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
|
|
||
| === Deploy a started app with config.env entries set via value and value_from | ||
| >>> [CLI] bundle deploy | ||
| Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/apps-config-env-no-drift/default/files... | ||
| ✓ Deployment succeeded | ||
| Created apps.myapp | ||
| Files: 2 uploaded, 0 deleted | ||
| Resources: 1 created, 0 changed, 0 deleted, 0 unchanged | ||
|
|
||
| === The Apps API returns deployment env vars with their name only | ||
| >>> [CLI] bundle plan -o json | ||
| [ | ||
| { | ||
| "name": "GREETING" | ||
| }, | ||
| { | ||
| "name": "API_TOKEN" | ||
| } | ||
| ] | ||
|
|
||
| === Re-plan is clean: value and value_from are input-only and must not drift | ||
| >>> [CLI] bundle plan | ||
| Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged | ||
|
|
||
| >>> [CLI] bundle plan -o json | ||
| { | ||
| "config.env[0].value": { | ||
| "action": "skip", | ||
| "reason": "input_only", | ||
| "old": "hello", | ||
| "new": "hello" | ||
| }, | ||
| "config.env[1].value_from": { | ||
| "action": "skip", | ||
| "reason": "input_only", | ||
| "old": "my-secret", | ||
| "new": "my-secret" | ||
| } | ||
| } | ||
|
|
||
| === A local change to an env value still plans an update | ||
| >>> update_file.py databricks.yml value: hello value: goodbye | ||
|
|
||
| >>> [CLI] bundle plan | ||
| update apps.myapp | ||
|
|
||
| Plan: 0 to add, 1 to change, 0 to delete, 0 unchanged | ||
|
|
||
| >>> [CLI] bundle plan -o json | ||
| { | ||
| "config.env[0].value": { | ||
| "action": "update", | ||
| "old": "hello", | ||
| "new": "goodbye" | ||
| }, | ||
| "config.env[1].value_from": { | ||
| "action": "skip", | ||
| "reason": "input_only", | ||
| "old": "my-secret", | ||
| "new": "my-secret" | ||
| } | ||
| } | ||
|
|
||
| === Deploy applies the change and the plan is clean again | ||
| >>> [CLI] bundle deploy | ||
| Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/apps-config-env-no-drift/default/files... | ||
| ✓ Deployment succeeded | ||
| Updated apps.myapp | ||
| Files: 1 uploaded, 0 deleted | ||
| Resources: 0 created, 1 changed, 0 deleted, 0 unchanged | ||
|
|
||
| >>> [CLI] bundle plan | ||
| Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged | ||
|
|
||
| >>> [CLI] bundle destroy --auto-approve | ||
| The following resources will be deleted: | ||
| delete resources.apps.myapp | ||
|
|
||
| All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/apps-config-env-no-drift/default | ||
|
|
||
| Destroy: 1 deleted |
23 changes: 23 additions & 0 deletions
23
acceptance/bundle/resources/apps/config-env-no-drift/script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| cleanup() { | ||
| trace $CLI bundle destroy --auto-approve | ||
| } | ||
| trap cleanup EXIT | ||
|
|
||
| title "Deploy a started app with config.env entries set via value and value_from" | ||
| trace $CLI bundle deploy | ||
|
|
||
| title "The Apps API returns deployment env vars with their name only" | ||
| trace $CLI bundle plan -o json | nostamp | jq '.plan."resources.apps.myapp".remote_state.config.env' | ||
|
|
||
| title "Re-plan is clean: value and value_from are input-only and must not drift" | ||
| trace $CLI bundle plan | contains.py "Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged" | ||
| trace $CLI bundle plan -o json | nostamp | jq '.plan."resources.apps.myapp".changes // {} | with_entries(select(.key | startswith("config.env")))' | ||
|
|
||
| title "A local change to an env value still plans an update" | ||
| trace update_file.py databricks.yml "value: hello" "value: goodbye" | ||
| trace $CLI bundle plan | contains.py "Plan: 0 to add, 1 to change, 0 to delete, 0 unchanged" | ||
| trace $CLI bundle plan -o json | nostamp | jq '.plan."resources.apps.myapp".changes // {} | with_entries(select(.key | startswith("config.env")))' | ||
|
|
||
| title "Deploy applies the change and the plan is clean again" | ||
| trace $CLI bundle deploy | ||
| trace $CLI bundle plan | contains.py "Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged" |
5 changes: 5 additions & 0 deletions
5
acceptance/bundle/resources/apps/config-env-no-drift/test.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # The Apps API returns deployment env vars with their name only, so config.env value and | ||
| # value_from are classified input-only (ignore_remote_changes) and the fake server models | ||
| # that masking. A real workspace would need the referenced secret to exist, so this runs | ||
| # locally only. See https://github.com/databricks/cli/issues/7301 | ||
| RecordRequests = false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
can we fix this upstream in protos? (i.e. mark as
input_only)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.
I believe we can, this is to fix it until addressed upstream
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.
Is this new?