Skip to content

Commit ca4acf0

Browse files
authored
Add name, target and mode to deployment metadata (#4180)
## Changes Adding new fields to the metadata to use for Workspace deployments ## Why We need these fields to run Job->YAML sync ## Tests Added unit test and updated job acceptance test <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent de47c12 commit ca4acf0

File tree

8 files changed

+41
-3
lines changed

8 files changed

+41
-3
lines changed

acceptance/bundle/resources/jobs/check-metadata/databricks.yml.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
bundle:
22
name: deploy-jobs-check-metadata-$UNIQUE_NAME
33

4+
targets:
5+
default:
6+
mode: development
7+
48
workspace:
59
root_path: ~/.bundle/$UNIQUE_NAME
610

acceptance/bundle/resources/jobs/check-metadata/output.txt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ Deployment complete!
2323

2424
=== Assert job 1 is created
2525
{
26-
"name": "test-job-metadata-1-[UNIQUE_NAME]"
26+
"name": "[dev [USERNAME]] test-job-metadata-1-[UNIQUE_NAME]"
2727
}
2828

2929
=== Assert job 2 is created
3030
{
31-
"name": "test-job-metadata-2-[UNIQUE_NAME]"
31+
"name": "[dev [USERNAME]] test-job-metadata-2-[UNIQUE_NAME]"
3232
}
3333

3434
=== Read metadata object from the workspace
@@ -39,6 +39,9 @@ Deployment complete!
3939
"version": 1,
4040
"config": {
4141
"bundle": {
42+
"name": "deploy-jobs-check-metadata-[UNIQUE_NAME]",
43+
"target": "default",
44+
"mode": "development",
4245
"git": {
4346
"bundle_root_path": "."
4447
}
@@ -71,6 +74,16 @@ Deployment complete!
7174
>>> cat metadata.json
7275
"id": "[JOB_2_ID]",
7376

77+
=== Check that metadata contains bundle name, target, and mode
78+
>>> cat metadata.json
79+
"deploy-jobs-check-metadata-[UNIQUE_NAME]"
80+
81+
>>> cat metadata.json
82+
"default"
83+
84+
>>> cat metadata.json
85+
"development"
86+
7487
>>> [CLI] bundle destroy --auto-approve
7588
The following resources will be deleted:
7689
delete resources.jobs.bar

acceptance/bundle/resources/jobs/check-metadata/script

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,8 @@ trace cat metadata.json
3131
title "Check that metadata contains created job ids"
3232
trace cat metadata.json | grep "${JOB_1_ID}"
3333
trace cat metadata.json | grep "${JOB_2_ID}"
34+
35+
title "Check that metadata contains bundle name, target, and mode"
36+
trace cat metadata.json | jq '.config.bundle.name'
37+
trace cat metadata.json | jq '.config.bundle.target'
38+
trace cat metadata.json | jq '.config.bundle.mode'

acceptance/bundle/user_agent/simple/out.requests.deploy.direct.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@
193193
"version": 1,
194194
"config": {
195195
"bundle": {
196+
"name": "test-bundle",
197+
"target": "default",
196198
"git": {
197199
"bundle_root_path": "."
198200
}

acceptance/bundle/user_agent/simple/out.requests.deploy.terraform.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@
193193
"version": 1,
194194
"config": {
195195
"bundle": {
196+
"name": "test-bundle",
197+
"target": "default",
196198
"git": {
197199
"bundle_root_path": "."
198200
}

bundle/deploy/metadata/compute.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ func (m *compute) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics
3636
BundleRootPath: b.Config.Bundle.Git.BundleRootPath,
3737
}
3838

39+
// Set bundle name, target, and mode
40+
b.Metadata.Config.Bundle.Name = b.Config.Bundle.Name
41+
b.Metadata.Config.Bundle.Target = b.Config.Bundle.Target
42+
b.Metadata.Config.Bundle.Mode = string(b.Config.Bundle.Mode)
43+
3944
// Set job config paths in metadata
4045
jobsMetadata := make(map[string]*metadata.Resource)
4146
for name, job := range b.Config.Resources.Jobs {

bundle/deploy/metadata/compute_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func TestComputeMetadataMutator(t *testing.T) {
2929
Bundle: config.Bundle{
3030
Name: "my-bundle",
3131
Target: "development",
32+
Mode: config.Development,
3233
Git: config.Git{
3334
Branch: "my-branch",
3435
OriginURL: "www.host.com",
@@ -81,6 +82,9 @@ func TestComputeMetadataMutator(t *testing.T) {
8182
FilePath: "/Users/[email protected]/files",
8283
},
8384
Bundle: metadata.Bundle{
85+
Name: "my-bundle",
86+
Target: "development",
87+
Mode: "development",
8488
Git: config.Git{
8589
Branch: "my-branch",
8690
OriginURL: "www.host.com",

bundle/metadata/metadata.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import (
77
const Version = 1
88

99
type Bundle struct {
10-
Git config.Git `json:"git,omitempty"`
10+
Name string `json:"name,omitempty"`
11+
Target string `json:"target,omitempty"`
12+
Mode string `json:"mode,omitempty"`
13+
Git config.Git `json:"git,omitempty"`
1114
}
1215

1316
type Workspace struct {

0 commit comments

Comments
 (0)