From e7165ec17a7855adf12aafb581dbf7ea5288886f Mon Sep 17 00:00:00 2001 From: Ilya Kuznetsov Date: Mon, 18 Nov 2024 11:58:56 +0100 Subject: [PATCH] feat: Add Databricks Workspace conditions to dev mode setting. Add warning if conditions not met when preset is enabled by user --- bundle/config/mutator/apply_presets.go | 1 + bundle/config/mutator/apply_presets_test.go | 9 +++++++++ bundle/config/mutator/process_target_mode.go | 10 ++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/bundle/config/mutator/apply_presets.go b/bundle/config/mutator/apply_presets.go index c9491b1a5..1e86da0a0 100644 --- a/bundle/config/mutator/apply_presets.go +++ b/bundle/config/mutator/apply_presets.go @@ -230,6 +230,7 @@ func (m *applyPresets) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnos } else { disabled := false b.Config.Presets.InPlaceDeployment = &disabled + diags = diags.Extend(diag.Warningf("in-place deployment is available only in the Databricks Workspace")) } } diff --git a/bundle/config/mutator/apply_presets_test.go b/bundle/config/mutator/apply_presets_test.go index 662b18a11..eaf4a56c2 100644 --- a/bundle/config/mutator/apply_presets_test.go +++ b/bundle/config/mutator/apply_presets_test.go @@ -387,6 +387,7 @@ func TestApplyPresetsInPlaceDeployment(t *testing.T) { initialValue *bool expectedValue *bool expectedFilePath string + expectedWarning string }{ { name: "preset enabled, bundle in Workspace, databricks runtime", @@ -395,6 +396,7 @@ func TestApplyPresetsInPlaceDeployment(t *testing.T) { initialValue: &enabled, expectedValue: &enabled, expectedFilePath: workspacePath, + expectedWarning: "", }, { name: "preset enabled, bundle not in Workspace, databricks runtime", @@ -403,6 +405,7 @@ func TestApplyPresetsInPlaceDeployment(t *testing.T) { initialValue: &enabled, expectedValue: &disabled, expectedFilePath: remotePath, + expectedWarning: "in-place deployment is available only in the Databricks Workspace", }, { name: "preset enabled, bundle in Workspace, not databricks runtime", @@ -411,6 +414,7 @@ func TestApplyPresetsInPlaceDeployment(t *testing.T) { initialValue: &enabled, expectedValue: &disabled, expectedFilePath: remotePath, + expectedWarning: "in-place deployment is available only in the Databricks Workspace", }, { name: "preset disabled, bundle in Workspace, databricks runtime", @@ -450,8 +454,13 @@ func TestApplyPresetsInPlaceDeployment(t *testing.T) { t.Fatalf("unexpected error: %v", diags) } + if tt.expectedWarning != "" { + require.Equal(t, tt.expectedWarning, diags[0].Summary) + } + require.Equal(t, tt.expectedFilePath, b.Config.Workspace.FilePath) require.Equal(t, tt.expectedValue, b.Config.Presets.InPlaceDeployment) }) } + } diff --git a/bundle/config/mutator/process_target_mode.go b/bundle/config/mutator/process_target_mode.go index 6ea0e7efd..81330d87e 100644 --- a/bundle/config/mutator/process_target_mode.go +++ b/bundle/config/mutator/process_target_mode.go @@ -6,6 +6,7 @@ import ( "github.com/databricks/cli/bundle" "github.com/databricks/cli/bundle/config" + "github.com/databricks/cli/libs/dbr" "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/iamutil" @@ -63,8 +64,13 @@ func transformDevelopmentMode(ctx context.Context, b *bundle.Bundle) { } if !config.IsExplicitlyDisabled(t.PipelinesDevelopment) { - enabled := true - t.PipelinesDevelopment = &enabled + root := b.SyncRootPath + isInWorkspace := strings.HasPrefix(root, "/Workspace/") + + if isInWorkspace && dbr.RunsOnRuntime(ctx) { + enabled := true + t.PipelinesDevelopment = &enabled + } } }