Repository navigation
Wait for grants to provision as part of depends on #7142
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
Open
andrewnester
wants to merge
1
commit into
main
Choose a base branch
from
fix/4573
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 @@ | ||
| * Resources that reference another resource are now deployed after that resource's `grants`, fixing intermittent `User does not have CREATE TABLE on Schema` errors when a pipeline's `run_as` principal is granted access to its schema in the same bundle. |
34 changes: 34 additions & 0 deletions
34
acceptance/bundle/resources/grants/schemas/pipeline_run_as/databricks.yml.tmpl
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,34 @@ | ||
| bundle: | ||
| name: schema-grants-pipeline-$UNIQUE_NAME | ||
|
|
||
| resources: | ||
| catalogs: | ||
| pipeline_catalog: | ||
| name: catalog_grants_pipeline_$UNIQUE_NAME | ||
| grants: | ||
| - principal: $RUN_AS_SP | ||
| privileges: | ||
| - USE_CATALOG | ||
|
|
||
| schemas: | ||
| src: | ||
| catalog_name: ${resources.catalogs.pipeline_catalog.name} | ||
| name: src | ||
| grants: | ||
| - principal: $RUN_AS_SP | ||
| privileges: | ||
| - USE_SCHEMA | ||
| - CREATE_TABLE | ||
| - CREATE_MATERIALIZED_VIEW | ||
|
|
||
| pipelines: | ||
| load: | ||
| name: schema-grants-pipeline-$UNIQUE_NAME | ||
| catalog: ${resources.schemas.src.catalog_name} | ||
| schema: ${resources.schemas.src.name} | ||
| serverless: true | ||
| libraries: | ||
| - file: | ||
| path: ./transformation.py | ||
| run_as: | ||
| service_principal_name: $RUN_AS_SP |
2 changes: 2 additions & 0 deletions
2
acceptance/bundle/resources/grants/schemas/pipeline_run_as/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"] |
78 changes: 78 additions & 0 deletions
78
acceptance/bundle/resources/grants/schemas/pipeline_run_as/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,78 @@ | ||
|
|
||
| >>> [CLI] bundle plan -o json | ||
| { | ||
| "resources.catalogs.pipeline_catalog": null, | ||
| "resources.catalogs.pipeline_catalog.grants": [ | ||
| { | ||
| "node": "resources.catalogs.pipeline_catalog", | ||
| "label": "${resources.catalogs.pipeline_catalog.id}" | ||
| } | ||
| ], | ||
| "resources.pipelines.load": [ | ||
| { | ||
| "node": "resources.schemas.src", | ||
| "label": "${resources.schemas.src.catalog_name}" | ||
| }, | ||
| { | ||
| "node": "resources.schemas.src", | ||
| "label": "${resources.schemas.src.name}" | ||
| }, | ||
| { | ||
| "node": "resources.schemas.src.grants", | ||
| "label": "${resources.schemas.src.catalog_name}" | ||
| } | ||
| ], | ||
| "resources.schemas.src": [ | ||
| { | ||
| "node": "resources.catalogs.pipeline_catalog", | ||
| "label": "${resources.catalogs.pipeline_catalog.name}" | ||
| }, | ||
| { | ||
| "node": "resources.catalogs.pipeline_catalog.grants", | ||
| "label": "${resources.catalogs.pipeline_catalog.name}" | ||
| } | ||
| ], | ||
| "resources.schemas.src.grants": [ | ||
| { | ||
| "node": "resources.schemas.src", | ||
| "label": "${resources.schemas.src.id}" | ||
| } | ||
| ] | ||
| } | ||
|
|
||
| >>> [CLI] bundle deploy | ||
| Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/schema-grants-pipeline-[UNIQUE_NAME]/default/files... | ||
| Created catalogs.pipeline_catalog | ||
| Created catalogs.pipeline_catalog.grants | ||
| Created pipelines.load | ||
| Created schemas.src | ||
| Created schemas.src.grants | ||
| Files: 3 uploaded, 0 deleted | ||
| Resources: 5 created, 0 changed, 0 deleted, 0 unchanged | ||
|
|
||
| >>> print_requests.py --summary //unity-catalog/catalogs //unity-catalog/schemas //unity-catalog/permissions //pipelines | ||
| POST /api/2.1/unity-catalog/catalogs | ||
| PATCH /api/2.1/unity-catalog/permissions/catalog/catalog_grants_pipeline_[UNIQUE_NAME] | ||
| POST /api/2.1/unity-catalog/schemas | ||
| PATCH /api/2.1/unity-catalog/permissions/schema/catalog_grants_pipeline_[UNIQUE_NAME].src | ||
| POST /api/2.0/pipelines | ||
|
|
||
| >>> [CLI] bundle plan | ||
| Plan: 0 to add, 0 to change, 0 to delete, 5 unchanged | ||
|
|
||
| >>> [CLI] bundle destroy --auto-approve | ||
| The following resources will be deleted: | ||
| delete resources.catalogs.pipeline_catalog | ||
| delete resources.pipelines.load | ||
| delete resources.schemas.src | ||
|
|
||
| This action will result in the deletion of the following UC schemas. Any underlying data may be lost: | ||
| delete resources.schemas.src | ||
|
|
||
| This action will result in the deletion of the following Lakeflow Spark Declarative Pipelines along with the | ||
| Streaming Tables (STs) and Materialized Views (MVs) managed by them. Set 'cascade_on_destroy: false' on a pipeline to retain datasets on pipeline deletion: | ||
| delete resources.pipelines.load | ||
|
|
||
| All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/schema-grants-pipeline-[UNIQUE_NAME]/default | ||
|
|
||
| Destroy: 3 deleted |
18 changes: 18 additions & 0 deletions
18
acceptance/bundle/resources/grants/schemas/pipeline_run_as/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,18 @@ | ||
| # Creating the pipeline fails unless its run_as principal can already create tables in the | ||
| # schema, so the pipeline must be deployed after the grants it relies on. | ||
| # See https://github.com/databricks/cli/issues/4573 | ||
| export RUN_AS_SP="${TEST_SP_APPLICATION_ID:-6f1c2b3a-4d5e-4f60-8a7b-9c0d1e2f3a4b}" | ||
|
|
||
| envsubst < databricks.yml.tmpl > databricks.yml | ||
|
|
||
| cleanup() { | ||
| trace $CLI bundle destroy --auto-approve | ||
| } | ||
| trap cleanup EXIT | ||
|
|
||
| trace $CLI bundle plan -o json | jq '.plan | map_values(.depends_on)' | ||
|
|
||
| trace $CLI bundle deploy | ||
| trace print_requests.py --summary //unity-catalog/catalogs //unity-catalog/schemas //unity-catalog/permissions //pipelines | ||
|
|
||
| trace $CLI bundle plan |
3 changes: 3 additions & 0 deletions
3
acceptance/bundle/resources/grants/schemas/pipeline_run_as/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,3 @@ | ||
| # Local only: on cloud the deploying identity lacks the servicePrincipal.user role on | ||
| # TEST_SP_APPLICATION_ID, so it cannot set that service principal as the pipeline's run_as. | ||
| Cloud = false |
1 change: 1 addition & 0 deletions
1
acceptance/bundle/resources/grants/schemas/pipeline_run_as/transformation.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 @@ | ||
| print("Hello, World!") |
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.
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.
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.
FYI, I'm also adding lifecycle.depends_on #7120
Worth evaluating if it changes anything there.
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.
This would require manually configuring that schemas depends on the grants, right? I think it's less preferred and it makes more sense to always wait for grants being provisioned