feat: Add Databricks Workspace conditions to dev mode setting. Add warning if conditions not met when preset is enabled by user

This commit is contained in:
Ilya Kuznetsov 2024-11-18 11:58:56 +01:00
parent 80ea3a05e3
commit e7165ec17a
No known key found for this signature in database
GPG Key ID: 91F3DDCF5D21CDDF
3 changed files with 18 additions and 2 deletions

View File

@ -230,6 +230,7 @@ func (m *applyPresets) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnos
} else { } else {
disabled := false disabled := false
b.Config.Presets.InPlaceDeployment = &disabled b.Config.Presets.InPlaceDeployment = &disabled
diags = diags.Extend(diag.Warningf("in-place deployment is available only in the Databricks Workspace"))
} }
} }

View File

@ -387,6 +387,7 @@ func TestApplyPresetsInPlaceDeployment(t *testing.T) {
initialValue *bool initialValue *bool
expectedValue *bool expectedValue *bool
expectedFilePath string expectedFilePath string
expectedWarning string
}{ }{
{ {
name: "preset enabled, bundle in Workspace, databricks runtime", name: "preset enabled, bundle in Workspace, databricks runtime",
@ -395,6 +396,7 @@ func TestApplyPresetsInPlaceDeployment(t *testing.T) {
initialValue: &enabled, initialValue: &enabled,
expectedValue: &enabled, expectedValue: &enabled,
expectedFilePath: workspacePath, expectedFilePath: workspacePath,
expectedWarning: "",
}, },
{ {
name: "preset enabled, bundle not in Workspace, databricks runtime", name: "preset enabled, bundle not in Workspace, databricks runtime",
@ -403,6 +405,7 @@ func TestApplyPresetsInPlaceDeployment(t *testing.T) {
initialValue: &enabled, initialValue: &enabled,
expectedValue: &disabled, expectedValue: &disabled,
expectedFilePath: remotePath, expectedFilePath: remotePath,
expectedWarning: "in-place deployment is available only in the Databricks Workspace",
}, },
{ {
name: "preset enabled, bundle in Workspace, not databricks runtime", name: "preset enabled, bundle in Workspace, not databricks runtime",
@ -411,6 +414,7 @@ func TestApplyPresetsInPlaceDeployment(t *testing.T) {
initialValue: &enabled, initialValue: &enabled,
expectedValue: &disabled, expectedValue: &disabled,
expectedFilePath: remotePath, expectedFilePath: remotePath,
expectedWarning: "in-place deployment is available only in the Databricks Workspace",
}, },
{ {
name: "preset disabled, bundle in Workspace, databricks runtime", name: "preset disabled, bundle in Workspace, databricks runtime",
@ -450,8 +454,13 @@ func TestApplyPresetsInPlaceDeployment(t *testing.T) {
t.Fatalf("unexpected error: %v", diags) 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.expectedFilePath, b.Config.Workspace.FilePath)
require.Equal(t, tt.expectedValue, b.Config.Presets.InPlaceDeployment) require.Equal(t, tt.expectedValue, b.Config.Presets.InPlaceDeployment)
}) })
} }
} }

View File

@ -6,6 +6,7 @@ import (
"github.com/databricks/cli/bundle" "github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config" "github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/libs/dbr"
"github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/diag"
"github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/dyn"
"github.com/databricks/cli/libs/iamutil" "github.com/databricks/cli/libs/iamutil"
@ -63,8 +64,13 @@ func transformDevelopmentMode(ctx context.Context, b *bundle.Bundle) {
} }
if !config.IsExplicitlyDisabled(t.PipelinesDevelopment) { if !config.IsExplicitlyDisabled(t.PipelinesDevelopment) {
enabled := true root := b.SyncRootPath
t.PipelinesDevelopment = &enabled isInWorkspace := strings.HasPrefix(root, "/Workspace/")
if isInWorkspace && dbr.RunsOnRuntime(ctx) {
enabled := true
t.PipelinesDevelopment = &enabled
}
} }
} }