-
Notifications
You must be signed in to change notification settings - Fork 184
bundle/direct: add a feature-flag list to the direct deployment state #5403
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
Closed
Closed
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
10 changes: 10 additions & 0 deletions
10
acceptance/bundle/deploy/record-deployment-history/state-upgrade/databricks.dms.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,10 @@ | ||
| bundle: | ||
| name: test-rdh-state-upgrade | ||
|
|
||
| experimental: | ||
| record_deployment_history: true | ||
|
|
||
| resources: | ||
| jobs: | ||
| foo: | ||
| name: foo-job-renamed |
7 changes: 7 additions & 0 deletions
7
acceptance/bundle/deploy/record-deployment-history/state-upgrade/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,7 @@ | ||
| bundle: | ||
| name: test-rdh-state-upgrade | ||
|
|
||
| resources: | ||
| jobs: | ||
| foo: | ||
| name: foo-job |
3 changes: 3 additions & 0 deletions
3
acceptance/bundle/deploy/record-deployment-history/state-upgrade/out.test.toml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
acceptance/bundle/deploy/record-deployment-history/state-upgrade/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,39 @@ | ||
|
|
||
| === without the flag: no features recorded | ||
| >>> [CLI] bundle deploy | ||
| Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-rdh-state-upgrade/default/files... | ||
| Deploying resources... | ||
| Updating deployment state... | ||
| Deployment complete! | ||
|
|
||
| >>> print_state.py | ||
| { | ||
| "state_version": 3, | ||
| "features": null | ||
| } | ||
|
|
||
| === with experimental.record_deployment_history: the feature is recorded | ||
| >>> [CLI] bundle deploy | ||
| Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-rdh-state-upgrade/default/files... | ||
| Deploying resources... | ||
| Updating deployment state... | ||
| Deployment complete! | ||
|
|
||
| >>> print_state.py | ||
| { | ||
| "state_version": 3, | ||
| "features": { | ||
| "record_deployment_history": "1.2.0" | ||
| } | ||
| } | ||
|
|
||
| === an older CLI (v1.0.0, max state version 2) rejects the upgraded state | ||
| >>> errcode [CLI_V1] bundle plan | ||
| Warning: unknown field: record_deployment_history | ||
| at experimental | ||
| in databricks.yml:5:3 | ||
|
|
||
| Error: migrating state [TEST_TMP_DIR]/.databricks/bundle/default/resources.json: state version 3 is newer than supported version 2; upgrade the CLI | ||
|
|
||
|
|
||
| Exit code: 1 |
19 changes: 19 additions & 0 deletions
19
acceptance/bundle/deploy/record-deployment-history/state-upgrade/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,19 @@ | ||
| # Feature-flag lifecycle for the direct state: | ||
| # 1. A normal deploy writes the baseline state version with no features. | ||
| # 2. Opting into experimental.record_deployment_history records a feature flag, | ||
| # stamped with the CLI version that wrote it. | ||
| # 3. An older CLI that predates this state version refuses to operate on it. | ||
|
|
||
| title "without the flag: no features recorded" | ||
| trace $CLI bundle deploy | ||
| trace print_state.py | jq '{state_version, features}' | ||
|
|
||
| title "with experimental.record_deployment_history: the feature is recorded" | ||
| # Also renames the job so the deploy writes state (a no-op deploy would not | ||
| # rewrite the state file and the change would not be observable yet). | ||
| cp databricks.dms.yml databricks.yml | ||
| trace $CLI bundle deploy | ||
| trace print_state.py | jq '{state_version, features}' | ||
|
|
||
| title "an older CLI (v1.0.0, max state version 2) rejects the upgraded state" | ||
| trace errcode $CLI_V1 bundle plan 2>&1 | contains.py "state version 3 is newer than supported version 2; upgrade the CLI" |
10 changes: 10 additions & 0 deletions
10
acceptance/bundle/deploy/record-deployment-history/state-upgrade/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,10 @@ | ||
| Local = true | ||
| Cloud = false | ||
|
|
||
| # databricks.yml is rewritten in-place by the script (flag added in the second step). | ||
| Ignore = [".databricks", "databricks.yml"] | ||
|
|
||
| # The state-version upgrade only applies to the direct engine; terraform stores | ||
| # state differently and would diverge. | ||
| [EnvMatrix] | ||
| DATABRICKS_BUNDLE_ENGINE = ["direct"] | ||
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
2 changes: 1 addition & 1 deletion
2
acceptance/bundle/deployment/bind/dashboard/recreation/out.state_after_bind.direct.json
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "state_version": 2, | ||
| "state_version": 3, | ||
| "cli_version": "[DEV_VERSION]", | ||
| "lineage": "[UUID]", | ||
| "serial": 2, | ||
|
|
||
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "state_version": 2, | ||
| "state_version": 3, | ||
| "cli_version": "[DEV_VERSION]", | ||
| "lineage": "[UUID]", | ||
| "serial": 6, | ||
|
|
||
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "state_version": 2, | ||
| "state_version": 3, | ||
| "cli_version": "[DEV_VERSION]", | ||
| "lineage": "[UUID]", | ||
| "serial": 3, | ||
|
|
||
2 changes: 1 addition & 1 deletion
2
acceptance/bundle/migrate/default-python/out.state_after_migration.json
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "state_version": 2, | ||
| "state_version": 3, | ||
| "cli_version": "[DEV_VERSION]", | ||
| "lineage": "[UUID]", | ||
| "serial": 5, | ||
|
|
||
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "state_version": 2, | ||
| "state_version": 3, | ||
| "cli_version": "[DEV_VERSION]", | ||
| "lineage": "[UUID]", | ||
| "serial": 9, | ||
|
|
||
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "state_version": 2, | ||
| "state_version": 3, | ||
| "cli_version": "[DEV_VERSION]", | ||
| "lineage": "[UUID]", | ||
| "serial": 7, | ||
|
|
||
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "state_version": 2, | ||
| "state_version": 3, | ||
| "cli_version": "[DEV_VERSION]", | ||
| "lineage": "[UUID]", | ||
| "serial": 5, | ||
|
|
||
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "state_version": 2, | ||
| "state_version": 3, | ||
| "cli_version": "[DEV_VERSION]", | ||
| "lineage": "[UUID]", | ||
| "serial": 1, | ||
|
|
||
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "state_version": 2, | ||
| "state_version": 3, | ||
| "cli_version": "[DEV_VERSION]", | ||
| "lineage": "[UUID]", | ||
| "serial": 1, | ||
|
|
||
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 |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| state version 999 is newer than supported version 2; upgrade the CLI | ||
| state version 999 is newer than supported version 3; upgrade the CLI | ||
|
|
||
| Exit code: 1 |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| bundle: | ||
| name: test-bundle | ||
|
|
||
| resources: | ||
| jobs: | ||
| my_job: | ||
| name: "my job" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
| the deployment state requires feature "future_feature" which this CLI ([DEV_VERSION]) does not support; upgrade to 9.9.9 or newer | ||
|
|
||
| Exit code: 1 |
10 changes: 10 additions & 0 deletions
10
acceptance/bundle/state/unknown_feature/resources.future.json
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,10 @@ | ||
| { | ||
| "state_version": 3, | ||
| "features": { | ||
| "future_feature": "9.9.9" | ||
| }, | ||
| "cli_version": "0.0.0-dev", | ||
| "lineage": "test-lineage", | ||
| "serial": 1, | ||
| "state": {} | ||
| } |
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,6 @@ | ||
| mkdir -p .databricks/bundle/default | ||
| cp resources.future.json .databricks/bundle/default/resources.json | ||
|
|
||
| # The state records a feature this CLI does not know; it must refuse and point the | ||
| # user at the minimum CLI version recorded in the state. | ||
| trace $CLI bundle plan 2>&1 | grep -o 'the deployment state requires feature.*' |
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,4 @@ | ||
| Ignore = [".databricks"] | ||
|
|
||
| [EnvMatrix] | ||
| DATABRICKS_BUNDLE_ENGINE = ["direct"] |
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
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,75 @@ | ||
| package dstate | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestMigrateStateLeavesCurrentUntouched(t *testing.T) { | ||
| db := &Database{Header: Header{StateVersion: currentStateVersion}} | ||
| require.NoError(t, migrateState(db)) | ||
| assert.Equal(t, currentStateVersion, db.StateVersion) | ||
| } | ||
|
|
||
| func TestMigrateStateUpgradesLegacyToCurrent(t *testing.T) { | ||
| // A legacy state migrates forward to the current version (the v2->v3 step adds | ||
| // the feature list, which is absent by default). | ||
| db := &Database{Header: Header{StateVersion: 2}} | ||
| require.NoError(t, migrateState(db)) | ||
| assert.Equal(t, currentStateVersion, db.StateVersion) | ||
| } | ||
|
|
||
| func TestMigrateStateRejectsNewerThanSupported(t *testing.T) { | ||
| db := &Database{Header: Header{StateVersion: currentStateVersion + 1}} | ||
| err := migrateState(db) | ||
| require.Error(t, err) | ||
| assert.Contains(t, err.Error(), "upgrade the CLI") | ||
| } | ||
|
|
||
| // TestStateSchemaVersion pins currentStateVersion. It is part of the on-disk | ||
| // format and a contract with older CLIs, so changing it must be deliberate. | ||
| // | ||
| // Bump it only for a structural schema change that older CLIs cannot read: add a | ||
| // migration to the migrations map (TestMigrationsCoverBaseline enforces full | ||
| // coverage) and update the assertion below. For an additive capability that does | ||
| // not change the structure, record a feature flag instead (see knownFeatures and | ||
| // RecordFeature) — that lets older CLIs fail with an actionable "upgrade to X" | ||
| // message without a version bump. | ||
| // | ||
| // RELATED COVERAGE | ||
| // - acceptance/bundle/state/permission_level_migration: golden v1->v2 migration. | ||
| // - acceptance/bundle/state/unknown_feature: a state requiring an unknown feature | ||
| // is rejected with the recorded minimum CLI version. | ||
| // - bundle/invariant/continue_293: the current CLI reads state written by an | ||
| // older released CLI. | ||
| func TestStateSchemaVersion(t *testing.T) { | ||
| assert.Equal(t, 3, currentStateVersion) | ||
| } | ||
|
|
||
| // TestMigrationsCoverBaseline guards a baseline bump: every state version below | ||
| // currentStateVersion must have a migration to the next version, so migrateState | ||
| // can always climb a legacy state up to the baseline. A bump that forgets a | ||
| // migration fails here instead of at a user's deploy. | ||
| func TestMigrationsCoverBaseline(t *testing.T) { | ||
| for v := range currentStateVersion { | ||
| assert.Containsf(t, migrations, v, "missing migration for state version %d", v) | ||
| } | ||
| } | ||
|
|
||
| func TestCheckSupportedFeatures(t *testing.T) { | ||
| // Known features (and none at all) are accepted; an unknown feature is rejected | ||
| // with its name and the recorded minimum CLI version. | ||
| require.NoError(t, checkSupportedFeatures(&Database{})) | ||
| require.NoError(t, checkSupportedFeatures(&Database{Header: Header{ | ||
| Features: map[string]string{FeatureRecordDeploymentHistory: "0.0.0-dev"}, | ||
| }})) | ||
|
|
||
| err := checkSupportedFeatures(&Database{Header: Header{ | ||
| Features: map[string]string{"future_feature": "9.9.9"}, | ||
| }}) | ||
| require.Error(t, err) | ||
| assert.Contains(t, err.Error(), `feature "future_feature"`) | ||
| assert.Contains(t, err.Error(), "upgrade to 9.9.9 or newer") | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.