-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Source-linked deployments for bundles in the workspace (#1884)
## Changes This change adds a preset for source-linked deployments. It is enabled by default for targets in `development` mode **if** the Databricks CLI is running from the `/Workspace` directory on DBR. It does not have an effect when running the CLI anywhere else. Key highlights: 1. Files in this mode won't be uploaded to workspace 2. Created resources will use references to source files instead of their workspace copies ## Tests 1. Apply preset unit test covering conditional logic 2. High-level process target mode unit test for testing integration between mutators --------- Co-authored-by: Pieter Noordhuis <[email protected]>
- Loading branch information
1 parent
886e149
commit 756e55f
Showing
9 changed files
with
321 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -2,12 +2,14 @@ package mutator_test | |
|
||
import ( | ||
"context" | ||
"runtime" | ||
"testing" | ||
|
||
"github.com/databricks/cli/bundle" | ||
"github.com/databricks/cli/bundle/config" | ||
"github.com/databricks/cli/bundle/config/mutator" | ||
"github.com/databricks/cli/bundle/config/resources" | ||
"github.com/databricks/cli/libs/dbr" | ||
"github.com/databricks/databricks-sdk-go/service/catalog" | ||
"github.com/databricks/databricks-sdk-go/service/jobs" | ||
"github.com/stretchr/testify/require" | ||
|
@@ -364,3 +366,86 @@ func TestApplyPresetsResourceNotDefined(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func TestApplyPresetsSourceLinkedDeployment(t *testing.T) { | ||
if runtime.GOOS == "windows" { | ||
t.Skip("this test is not applicable on Windows because source-linked mode works only in the Databricks Workspace") | ||
} | ||
|
||
testContext := context.Background() | ||
enabled := true | ||
disabled := false | ||
workspacePath := "/Workspace/[email protected]" | ||
|
||
tests := []struct { | ||
bundlePath string | ||
ctx context.Context | ||
name string | ||
initialValue *bool | ||
expectedValue *bool | ||
expectedWarning string | ||
}{ | ||
{ | ||
name: "preset enabled, bundle in Workspace, databricks runtime", | ||
bundlePath: workspacePath, | ||
ctx: dbr.MockRuntime(testContext, true), | ||
initialValue: &enabled, | ||
expectedValue: &enabled, | ||
}, | ||
{ | ||
name: "preset enabled, bundle not in Workspace, databricks runtime", | ||
bundlePath: "/Users/[email protected]", | ||
ctx: dbr.MockRuntime(testContext, true), | ||
initialValue: &enabled, | ||
expectedValue: &disabled, | ||
expectedWarning: "source-linked deployment is available only in the Databricks Workspace", | ||
}, | ||
{ | ||
name: "preset enabled, bundle in Workspace, not databricks runtime", | ||
bundlePath: workspacePath, | ||
ctx: dbr.MockRuntime(testContext, false), | ||
initialValue: &enabled, | ||
expectedValue: &disabled, | ||
expectedWarning: "source-linked deployment is available only in the Databricks Workspace", | ||
}, | ||
{ | ||
name: "preset disabled, bundle in Workspace, databricks runtime", | ||
bundlePath: workspacePath, | ||
ctx: dbr.MockRuntime(testContext, true), | ||
initialValue: &disabled, | ||
expectedValue: &disabled, | ||
}, | ||
{ | ||
name: "preset nil, bundle in Workspace, databricks runtime", | ||
bundlePath: workspacePath, | ||
ctx: dbr.MockRuntime(testContext, true), | ||
initialValue: nil, | ||
expectedValue: nil, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
b := &bundle.Bundle{ | ||
SyncRootPath: tt.bundlePath, | ||
Config: config.Root{ | ||
Presets: config.Presets{ | ||
SourceLinkedDeployment: tt.initialValue, | ||
}, | ||
}, | ||
} | ||
|
||
diags := bundle.Apply(tt.ctx, b, mutator.ApplyPresets()) | ||
if diags.HasError() { | ||
t.Fatalf("unexpected error: %v", diags) | ||
} | ||
|
||
if tt.expectedWarning != "" { | ||
require.Equal(t, tt.expectedWarning, diags[0].Summary) | ||
} | ||
|
||
require.Equal(t, tt.expectedValue, b.Config.Presets.SourceLinkedDeployment) | ||
}) | ||
} | ||
|
||
} |
This file contains 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 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 |
---|---|---|
|
@@ -3,14 +3,17 @@ package mutator | |
import ( | ||
"context" | ||
"reflect" | ||
"runtime" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/databricks/cli/bundle" | ||
"github.com/databricks/cli/bundle/config" | ||
"github.com/databricks/cli/bundle/config/resources" | ||
"github.com/databricks/cli/libs/dbr" | ||
"github.com/databricks/cli/libs/diag" | ||
"github.com/databricks/cli/libs/tags" | ||
"github.com/databricks/cli/libs/vfs" | ||
sdkconfig "github.com/databricks/databricks-sdk-go/config" | ||
"github.com/databricks/databricks-sdk-go/service/catalog" | ||
"github.com/databricks/databricks-sdk-go/service/compute" | ||
|
@@ -140,6 +143,7 @@ func mockBundle(mode config.Mode) *bundle.Bundle { | |
}, | ||
}, | ||
}, | ||
SyncRoot: vfs.MustNew("/Users/[email protected]"), | ||
// Use AWS implementation for testing. | ||
Tagging: tags.ForCloud(&sdkconfig.Config{ | ||
Host: "https://company.cloud.databricks.com", | ||
|
@@ -522,3 +526,32 @@ func TestPipelinesDevelopmentDisabled(t *testing.T) { | |
|
||
assert.False(t, b.Config.Resources.Pipelines["pipeline1"].PipelineSpec.Development) | ||
} | ||
|
||
func TestSourceLinkedDeploymentEnabled(t *testing.T) { | ||
b, diags := processSourceLinkedBundle(t, true) | ||
require.NoError(t, diags.Error()) | ||
assert.True(t, *b.Config.Presets.SourceLinkedDeployment) | ||
} | ||
|
||
func TestSourceLinkedDeploymentDisabled(t *testing.T) { | ||
b, diags := processSourceLinkedBundle(t, false) | ||
require.NoError(t, diags.Error()) | ||
assert.False(t, *b.Config.Presets.SourceLinkedDeployment) | ||
} | ||
|
||
func processSourceLinkedBundle(t *testing.T, presetEnabled bool) (*bundle.Bundle, diag.Diagnostics) { | ||
if runtime.GOOS == "windows" { | ||
t.Skip("this test is not applicable on Windows because source-linked mode works only in the Databricks Workspace") | ||
} | ||
|
||
b := mockBundle(config.Development) | ||
|
||
workspacePath := "/Workspace/[email protected]/" | ||
b.SyncRootPath = workspacePath | ||
b.Config.Presets.SourceLinkedDeployment = &presetEnabled | ||
|
||
ctx := dbr.MockRuntime(context.Background(), true) | ||
m := bundle.Seq(ProcessTargetMode(), ApplyPresets()) | ||
diags := bundle.Apply(ctx, b, m) | ||
return b, diags | ||
} |
This file contains 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.