From b361844ffd9447d63dd5e38f898a4d71ca9fc19c Mon Sep 17 00:00:00 2001 From: Ilya Kuznetsov Date: Fri, 22 Nov 2024 13:46:30 +0100 Subject: [PATCH 1/3] feat: Extended message for warning when source-linked is used outside of Workspace --- bundle/config/mutator/apply_presets.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/bundle/config/mutator/apply_presets.go b/bundle/config/mutator/apply_presets.go index 9cec704e62..f1c1acd961 100644 --- a/bundle/config/mutator/apply_presets.go +++ b/bundle/config/mutator/apply_presets.go @@ -225,9 +225,22 @@ func (m *applyPresets) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnos if config.IsExplicitlyEnabled((b.Config.Presets.SourceLinkedDeployment)) { isDatabricksWorkspace := dbr.RunsOnRuntime(ctx) && strings.HasPrefix(b.SyncRootPath, "/Workspace/") if !isDatabricksWorkspace { + target := b.Config.Bundle.Target + path := dyn.NewPath(dyn.Key("targets"), dyn.Key(target), dyn.Key("presets"), dyn.Key("source_linked_deployment")) + diags = diags.Extend( + diag.Diagnostics{ + { + Severity: diag.Warning, + Summary: "Source-linked deployment is available only in the Databricks Workspace", + Paths: []dyn.Path{ + path, + }, + Locations: b.Config.GetLocations(dyn.NewPath(dyn.Key("presets"), dyn.Key("source_linked_deployment")).String()), + }, + }) + disabled := false b.Config.Presets.SourceLinkedDeployment = &disabled - diags = diags.Extend(diag.Warningf("source-linked deployment is available only in the Databricks Workspace")) } } From f836c00ea3317acb4425feef4f06a453adad28ae Mon Sep 17 00:00:00 2001 From: Ilya Kuznetsov Date: Fri, 22 Nov 2024 13:49:34 +0100 Subject: [PATCH 2/3] fix: Update to lowercase --- bundle/config/mutator/apply_presets.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/config/mutator/apply_presets.go b/bundle/config/mutator/apply_presets.go index f1c1acd961..6345115f06 100644 --- a/bundle/config/mutator/apply_presets.go +++ b/bundle/config/mutator/apply_presets.go @@ -231,7 +231,7 @@ func (m *applyPresets) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnos diag.Diagnostics{ { Severity: diag.Warning, - Summary: "Source-linked deployment is available only in the Databricks Workspace", + Summary: "source-linked deployment is available only in the Databricks Workspace", Paths: []dyn.Path{ path, }, From 7de51dc6dfdabdf5cc7c626dae0270e05de3d90f Mon Sep 17 00:00:00 2001 From: Ilya Kuznetsov Date: Fri, 22 Nov 2024 14:36:24 +0100 Subject: [PATCH 3/3] fix: Reuse existing path --- bundle/config/mutator/apply_presets.go | 19 +++++++++---------- bundle/config/mutator/apply_presets_test.go | 4 ++++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/bundle/config/mutator/apply_presets.go b/bundle/config/mutator/apply_presets.go index 6345115f06..3817037565 100644 --- a/bundle/config/mutator/apply_presets.go +++ b/bundle/config/mutator/apply_presets.go @@ -227,17 +227,16 @@ func (m *applyPresets) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnos if !isDatabricksWorkspace { target := b.Config.Bundle.Target path := dyn.NewPath(dyn.Key("targets"), dyn.Key(target), dyn.Key("presets"), dyn.Key("source_linked_deployment")) - diags = diags.Extend( - diag.Diagnostics{ - { - Severity: diag.Warning, - Summary: "source-linked deployment is available only in the Databricks Workspace", - Paths: []dyn.Path{ - path, - }, - Locations: b.Config.GetLocations(dyn.NewPath(dyn.Key("presets"), dyn.Key("source_linked_deployment")).String()), + diags = diags.Append( + diag.Diagnostic{ + Severity: diag.Warning, + Summary: "source-linked deployment is available only in the Databricks Workspace", + Paths: []dyn.Path{ + path, }, - }) + Locations: b.Config.GetLocations(path[2:].String()), + }, + ) disabled := false b.Config.Presets.SourceLinkedDeployment = &disabled diff --git a/bundle/config/mutator/apply_presets_test.go b/bundle/config/mutator/apply_presets_test.go index f11a45d63f..497ef051ad 100644 --- a/bundle/config/mutator/apply_presets_test.go +++ b/bundle/config/mutator/apply_presets_test.go @@ -9,7 +9,9 @@ import ( "github.com/databricks/cli/bundle/config" "github.com/databricks/cli/bundle/config/mutator" "github.com/databricks/cli/bundle/config/resources" + "github.com/databricks/cli/bundle/internal/bundletest" "github.com/databricks/cli/libs/dbr" + "github.com/databricks/cli/libs/dyn" "github.com/databricks/databricks-sdk-go/service/catalog" "github.com/databricks/databricks-sdk-go/service/jobs" "github.com/stretchr/testify/require" @@ -435,6 +437,7 @@ func TestApplyPresetsSourceLinkedDeployment(t *testing.T) { }, } + bundletest.SetLocation(b, "presets.source_linked_deployment", []dyn.Location{{File: "databricks.yml"}}) diags := bundle.Apply(tt.ctx, b, mutator.ApplyPresets()) if diags.HasError() { t.Fatalf("unexpected error: %v", diags) @@ -442,6 +445,7 @@ func TestApplyPresetsSourceLinkedDeployment(t *testing.T) { if tt.expectedWarning != "" { require.Equal(t, tt.expectedWarning, diags[0].Summary) + require.NotEmpty(t, diags[0].Locations) } require.Equal(t, tt.expectedValue, b.Config.Presets.SourceLinkedDeployment)