Repository navigation
Add hidden bundle deployment auto-deploy group with create - #8185
atreyadbrx wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Automated review at 31284b0. Each finding was verified against the code.
No blocking issues found. 4 non-blocking comment(s) below.
This PR adds a hidden bundle deployment auto-deploy create command that upserts a git-webhooks trigger for a bundle target, along with a small libs/gitwebhooks client and a fake server handler. The main flow and the branch, origin and override checks look right. I'd like three things fixed before this becomes public. Provider inference duplicates repos.DetectProvider and covers fewer hosts. The variable-overrides check rejects file entries for lookup variables, even though the deploy ignores them. A production target can fail validation under the caller's identity even when --deploy-as names a service principal that the same target accepts. There is also one small test-input rule violation.
|
|
||
| // Auto-deploy infers only these providers. Any other host takes --git-provider, since | ||
| // a host name does not tell, for example, GitHub Enterprise from GitLab self-managed. | ||
| var providersByHost = map[string]gitwebhooks.GitProvider{ |
There was a problem hiding this comment.
[nice to have] repos.DetectProvider in cmd/workspace/repos/provider.go already infers the provider from the origin URL. It covers github.com and dev.azure.com, and also gitlab.com, bitbucket.org and git-codecommit.<region>.amazonaws.com. Its result uses the same names that gitProviderNames maps. With this map, an origin of https://gitlab.com/acme/repo fails with "cannot infer the Git provider ... Pass it with --git-provider", but databricks repos create detects the same URL. These public hosts aren't ambiguous the way a self-managed host is. Can we call repos.DetectProvider and feed its result through parseGitProvider? The --git-provider help text and the Long text in create.go would then need updating to match.
| return "" | ||
| } | ||
| for name := range b.Config.Variables { | ||
| if value, ok := values[name]; ok && string(value) != "null" { |
There was a problem hiding this comment.
[nice to have] The comment says this works "Like SetVariables", but setVariable returns at variable.Lookup != nil before it reads the file value. So the overrides file never sets a lookup variable. Take a bundle with cluster_id: {lookup: {cluster: ...}} and {"cluster_id": "abc"} in .databricks/bundle/<target>/variable-overrides.json: create refuses, even though the local deploy and the runner's deploy both ignore that entry. Can this loop skip variables whose Lookup is set? Only skip them for the file check, since BUNDLE_VAR_<name> does take priority over a lookup. Another option is to check what SetVariables actually applied instead of parsing the file a second time.
There was a problem hiding this comment.
🤖 Should fix: +1, reproduced with a scratch acceptance test. With policy_id: {lookup: {cluster_policy: shared}} and {"policy_id": "old"} in .databricks/bundle/dev/variable-overrides.json, bundle validate still resolves policy_id to the lookup's ID, but create fails with ... variable-overrides.json overrides them here. This is the case left over from the overrides-file point raised on #7940. The fix there skips null values, but not lookup variables, which setVariable returns for before it reads the file.
There was a problem hiding this comment.
Fixed in 6568c9d. The overrides-file check now skips lookup variables, which SetVariables also skips. --var and BUNDLE_VAR_<name> still count, since they do override a lookup. The create test's overrides file now has an entry for a lookup variable (policy_id), and create succeeds. #7940 has the same fix.
|
|
||
| // Whether the configuration sets the branch, before Initialize fills in the current one. | ||
| var branchConfigured bool | ||
| b, err := utils.ProcessBundle(cmd, utils.ProcessOptions{ |
There was a problem hiding this comment.
[nice to have] ProcessBundle runs the full phases.Initialize, which includes resourcemutator.ValidateTargetMode with the caller's identity. Suppose a human runs create -t prod --deploy-as <sp-id> on a mode: production target that has a job without run_as and no target-level workspace.root_path. The command fails with "target with 'mode: production' must set 'workspace.root_path'" before the upsert. The service principal's own deploys of that target only get a recommendation, because validateProductionMode makes this check non-fatal for principals. Should create skip caller-dependent validation, or run it as the --deploy-as identity?
There was a problem hiding this comment.
🤖 Should fix: +1, reproduced with a scratch acceptance test (mode: production, a job without run_as, no root_path). create -t prod --deploy-as 692bc6d0-ffa3-11ed-be56-0242ac120002 fails with target with 'mode: production' must set 'workspace.root_path', and the suggested root_path has the caller's user name in it, not the principal's. Other checks that Initialize runs as the caller hit the same problem:
SetRunAscomparesrun_aswithworkspace.current_user, sorun_as: {service_principal_name: <sp>}with a resource type that doesn't support a differentrun_asfails for the human, while the principal's own deploy passes.- Lookup variables resolve with the caller's access.
create sends only the origin, the bundle path, the target and the branch. So one way to fix all of these: resolve only what those need (Git details, the target, and the variables git.branch uses), instead of the full Initialize.
There was a problem hiding this comment.
Fixed in 6568c9d, as you suggested. The commands now skip Initialize (SkipInitialize) and run only what they need:
- the sync root
LoadGitDetailsSetVariables- a new
ResolveVariableReferencesInGit, which resolves references underbundle.gitonly
So the target-mode checks, the run_as checks and lookups no longer run as the caller. get, list, delete and attempts load the bundle the same way (#8186).
The create test now has a mode: production target without root_path, with a job that has no run_as, and create -t prod --deploy-as <sp> succeeds. The test bundle also has a lookup variable, which create no longer resolves. #7940 and #7941 have the same fix.
| musterr trace BUNDLE_VAR_release_branch=hotfix $CLI bundle deployment auto-deploy create -t staging | ||
| mkdir -p .databricks/bundle/staging | ||
| echo '{"undefined_variable": "x"}' > .databricks/bundle/staging/variable-overrides.json | ||
| trace $CLI bundle deployment auto-deploy create -t staging |
There was a problem hiding this comment.
[nit] .agents/rules/testing.md asks for static test inputs to be committed to the test directory instead of created in script. Both variable-overrides.json contents, here and on line 61, are fixed. Can we commit them next to the test (for example overrides-undefined.json and overrides-defined.json) and copy them into .databricks/bundle/staging/ when needed, like sub/databricks.yml?
Regression test report ✅Commit: Selected 1 changed tests (limit=20, 0 not selected) 1 tests: regression=1 unreleased=0 coverage=0 failing=0
TestAccept/bundle/deployment/auto-deploy/create: branch ✅ | main (9a14ad6) ❌ | latest (v1.28.0) ❌main (9a14ad6): latest (v1.28.0): same output as main (9a14ad6) |
✅ Integration test reportCommit: 6568c9d
Top 3 slowest tests (at least 2 minutes):
|
denik
left a comment
There was a problem hiding this comment.
🤖 Automated review of 31284b0a3 by Opus and Astra (two independent passes); each finding verified against the code.
The move under bundle deployment is clean: the code is #7940's 30d20e72e with only the command path, the package path and the test paths changed. It builds and its tests pass when merged with current main. Of the three Should-fix points from the #7940 review, the empty git.branch lockout and the --git-provider spelling are fixed. The overrides-file check still has a lookup-variable case (reply inline). review-oss-bot's --deploy-as point also reproduces, and the same problem affects more checks than the one it names (reply inline).
| return "" | ||
| } | ||
| for name := range b.Config.Variables { | ||
| if value, ok := values[name]; ok && string(value) != "null" { |
There was a problem hiding this comment.
🤖 Should fix: +1, reproduced with a scratch acceptance test. With policy_id: {lookup: {cluster_policy: shared}} and {"policy_id": "old"} in .databricks/bundle/dev/variable-overrides.json, bundle validate still resolves policy_id to the lookup's ID, but create fails with ... variable-overrides.json overrides them here. This is the case left over from the overrides-file point raised on #7940. The fix there skips null values, but not lookup variables, which setVariable returns for before it reads the file.
|
|
||
| // Whether the configuration sets the branch, before Initialize fills in the current one. | ||
| var branchConfigured bool | ||
| b, err := utils.ProcessBundle(cmd, utils.ProcessOptions{ |
There was a problem hiding this comment.
🤖 Should fix: +1, reproduced with a scratch acceptance test (mode: production, a job without run_as, no root_path). create -t prod --deploy-as 692bc6d0-ffa3-11ed-be56-0242ac120002 fails with target with 'mode: production' must set 'workspace.root_path', and the suggested root_path has the caller's user name in it, not the principal's. Other checks that Initialize runs as the caller hit the same problem:
SetRunAscomparesrun_aswithworkspace.current_user, sorun_as: {service_principal_name: <sp>}with a resource type that doesn't support a differentrun_asfails for the human, while the principal's own deploy passes.- Lookup variables resolve with the caller's access.
create sends only the origin, the bundle path, the target and the branch. So one way to fix all of these: resolve only what those need (Git details, the target, and the variables git.branch uses), instead of the full Initialize.
`bundle deployment auto-deploy create` sets up the trigger that deploys a bundle target on every push to a branch, over the git-webhooks API. The trigger is identified by the bundle's origin URL, its path in the repository and the target. The Git provider is inferred for github.com and dev.azure.com, and --git-provider covers any other host. --branch defaults to bundle.git.branch, and --deploy-as takes a user email or a service principal application ID. The group sits under `bundle deployment` rather than at the top of `bundle`: users run it once, at setup time, so the extra level of nesting is fine. The commands load the bundle's Git details and variables, not the rest of Initialize. Its checks and lookups run as the caller, while the deploys run as --deploy-as. The git-webhooks API is not in the Go SDK yet, so libs/gitwebhooks calls it with local types. The group stays hidden until the API is public. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: atreyadbrx <atreya.misra@databricks.com>
31284b0 to
6568c9d
Compare
This is #7940 with the group under
bundle deployment, as suggested in review: users run it once, at setup time, so the extra level of nesting is fine. Only the command path, the package path (cmd/bundle/deployment/autodeploy) and the test paths differ.Changes
bundle deployment auto-deploycommand group, hidden for now, withcreate.createsets up the trigger that deploys a bundle target on every push to a branch. It is identified bybundle.git.origin_url, the bundle's path in the repo (bundle.git.bundle_root_pathplus the config file name), and the target.--git-provideris needed only for hosts other than github.com and dev.azure.com. It takes the same case-insensitive values asappsandrepos(gitHub,gitLab, ...).--branchdefaults tobundle.git.branch, or to the current branch whengit.branchresolves to"".--deploy-astakes a service principal application ID or your own email, which is all the service accepts. It defaults to you.createfails early in three cases, each with a fix in the error message:--branchdiffers from the target's configuredgit.branch, since that deploy would fail the branch check.--var,BUNDLE_VAR_<name>or the target's variable-overrides file (only an entry that sets a defined, non-lookup variable counts). The runner deploys from a clone that has none of them. This makesVariableEnvPrefixandVariableOverridesPathinbundle/config/mutatorexported.ResolveVariableReferencesInGitforbundle.git), not the fullInitialize. Its target-mode checks,run_aschecks and lookups run as the caller, but the deploys run as--deploy-as.libs/gitwebhooks: a client for the git-webhooks API (PUT /api/2.0/git-webhooks). The fake handlers are inlibs/testserver/gitwebhooks.go.Why
Auto-deploy needs a CLI way to set up a trigger for a bundle target. The git-webhooks API isn't in the public spec or the Go SDK yet, so
libs/gitwebhookscalls it throughclient.Dowith local types that mirror the service, likelibs/dms/enrollments.godoes. The group stays hidden until the API is public.Tests
acceptance/bundle/deployment/auto-deploy/createcovers:--deploy-aswith a service principal, with your own email (-o json) and with another user's email (rejected)mode: productiontarget withoutroot_path, with--deploy-asa service principalcreatedoes not resolve, also set in the overrides file--branchthat conflicts withgit.branch, agit.branchset from a variable, one that resolves to"", and a detached HEAD--git-provider, and an unsupported--git-provider--var,BUNDLE_VAR_<name>, an overrides file that sets a defined variable and one that doesn't, and a repo with no origin--git-providerparsing.create's request: the enum strings,deployment_modecarrying the target, the response fields, and the 403 for another user's email. The fake follows the service's implemented behavior. A staging workspace that serves the API returned triggers in the shape these types expect (see Addbundle deployment auto-deploy getandlist#8186), butcreatewas not run there.This pull request and its description were written by Isaac.