mirror of https://github.com/databricks/cli.git
Add a recommendation for pipeline catalogs
This commit is contained in:
parent
65f10d187d
commit
e0b6faddbe
|
@ -65,13 +65,24 @@ func (m *applyPresetsCatalogSchema) Apply(ctx context.Context, b *bundle.Bundle)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pipelines
|
// Pipelines
|
||||||
for _, pl := range r.Pipelines {
|
allSameCatalog := allPipelinesSameCatalog(&r)
|
||||||
|
for key, pl := range r.Pipelines {
|
||||||
if pl.PipelineSpec == nil {
|
if pl.PipelineSpec == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if pl.Catalog == "" {
|
if pl.Catalog == "" {
|
||||||
pl.Catalog = p.Catalog
|
pl.Catalog = p.Catalog
|
||||||
}
|
}
|
||||||
|
if allSameCatalog && pl.Catalog == p.Catalog {
|
||||||
|
// Just for the common case where all pipelines have the same catalog,
|
||||||
|
// we show a recommendation to leave it out and rely on presets.
|
||||||
|
// This can happen when using the original default template.
|
||||||
|
diags = diags.Extend(diag.Diagnostics{{
|
||||||
|
Summary: "Omit the catalog field since it will be automatically populated from presets.catalog",
|
||||||
|
Severity: diag.Recommendation,
|
||||||
|
Locations: b.Config.GetLocations("resources.pipelines." + key + ".catalog"),
|
||||||
|
}})
|
||||||
|
}
|
||||||
if pl.GatewayDefinition != nil {
|
if pl.GatewayDefinition != nil {
|
||||||
if pl.GatewayDefinition.GatewayStorageCatalog == "" {
|
if pl.GatewayDefinition.GatewayStorageCatalog == "" {
|
||||||
pl.GatewayDefinition.GatewayStorageCatalog = p.Catalog
|
pl.GatewayDefinition.GatewayStorageCatalog = p.Catalog
|
||||||
|
@ -347,3 +358,19 @@ func fileIncludesPattern(ctx context.Context, filePath string, expected string)
|
||||||
}
|
}
|
||||||
return matched
|
return matched
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func allPipelinesSameCatalog(r *config.Resources) bool {
|
||||||
|
var firstCatalog string
|
||||||
|
|
||||||
|
for _, pl := range r.Pipelines {
|
||||||
|
if pl.PipelineSpec == nil || pl.PipelineSpec.Catalog == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if firstCatalog == "" {
|
||||||
|
firstCatalog = pl.PipelineSpec.Catalog
|
||||||
|
} else if pl.PipelineSpec.Catalog != firstCatalog {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return firstCatalog != ""
|
||||||
|
}
|
||||||
|
|
|
@ -179,7 +179,7 @@ func TestApplyPresetsCatalogSchemaWhenAlreadySet(t *testing.T) {
|
||||||
b := mockPresetsCatalogSchema()
|
b := mockPresetsCatalogSchema()
|
||||||
recordedFields := recordPlaceholderFields(t, b)
|
recordedFields := recordPlaceholderFields(t, b)
|
||||||
|
|
||||||
diags := bundle.Apply(context.Background(), b, mutator.ApplyPresets())
|
diags := bundle.Apply(context.Background(), b, mutator.ApplyPresetsCatalogSchema())
|
||||||
require.NoError(t, diags.Error())
|
require.NoError(t, diags.Error())
|
||||||
|
|
||||||
for _, f := range recordedFields {
|
for _, f := range recordedFields {
|
||||||
|
@ -190,6 +190,16 @@ func TestApplyPresetsCatalogSchemaWhenAlreadySet(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestApplyPresetsCatalogSchemaRecommmendRemovingCatalog(t *testing.T) {
|
||||||
|
b := mockPresetsCatalogSchema()
|
||||||
|
b.Config.Resources.Jobs["key"].Parameters = nil // avoid warnings about the job parameters
|
||||||
|
b.Config.Resources.Pipelines["key"].Catalog = "my_catalog"
|
||||||
|
|
||||||
|
diags := bundle.Apply(context.Background(), b, mutator.ApplyPresetsCatalogSchema())
|
||||||
|
require.Equal(t, 1, len(diags))
|
||||||
|
require.Equal(t, "Omit the catalog field since it will be automatically populated from presets.catalog", diags[0].Summary)
|
||||||
|
}
|
||||||
|
|
||||||
func TestApplyPresetsCatalogSchemaWhenNotSet(t *testing.T) {
|
func TestApplyPresetsCatalogSchemaWhenNotSet(t *testing.T) {
|
||||||
b := mockPresetsCatalogSchema()
|
b := mockPresetsCatalogSchema()
|
||||||
recordedFields := recordPlaceholderFields(t, b)
|
recordedFields := recordPlaceholderFields(t, b)
|
||||||
|
|
Loading…
Reference in New Issue