Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This test verifies that bundles can use the 'definitions' field for YAML anchors
# without triggering the OSS Spark Pipelines validation error. This was a regression
# patched in https://github.com/databricks/cli/pull/3889

definitions:
common_cluster_settings: &common_cluster_settings
spark_version: "13.3.x-scala2.12"
node_type_id: "i3.xlarge"
num_workers: 2

resources:
jobs:
my_job:
name: "test job with anchors"
tasks:
- task_key: "main"
new_cluster:
<<: *common_cluster_settings
notebook_task:
notebook_path: "/some/notebook"

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

>>> [CLI] bundle validate
Name: test-bundle
Target: default
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default

Validation OK!
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
trace $CLI bundle validate
23 changes: 0 additions & 23 deletions bundle/phases/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package phases

import (
"context"
"errors"
"path/filepath"

"github.com/databricks/cli/bundle/config/mutator/resourcemutator"

Expand All @@ -18,9 +16,7 @@ import (
"github.com/databricks/cli/bundle/permissions"
"github.com/databricks/cli/bundle/scripts"
"github.com/databricks/cli/bundle/trampoline"
"github.com/databricks/cli/libs/dyn"
"github.com/databricks/cli/libs/log"
"github.com/databricks/cli/libs/logdiag"
)

// The initialize phase fills in defaults and connects to the workspace.
Expand All @@ -29,11 +25,6 @@ import (
func Initialize(ctx context.Context, b *bundle.Bundle) {
log.Info(ctx, "Phase: initialize")

rejectDefinitions(ctx, b)
if logdiag.HasError(ctx) {
return
}

bundle.ApplySeqContext(ctx, b,
// Reads (dynamic): resource.*.*
// Checks that none of resources.<type>.<key> is nil. Raises error otherwise.
Expand Down Expand Up @@ -206,17 +197,3 @@ func Initialize(ctx context.Context, b *bundle.Bundle) {
scripts.Execute(config.ScriptPostInit),
)
}

func rejectDefinitions(ctx context.Context, b *bundle.Bundle) {
if b.Config.Definitions != nil {
v := dyn.GetValue(b.Config.Value(), "definitions")
loc := v.Locations()
filename := "input yaml"
if len(loc) > 0 {
filename = filepath.ToSlash(loc[0].File)
}
logdiag.LogError(ctx, errors.New(filename+` seems to be formatted for open-source Spark Declarative Pipelines.
Pipelines CLI currently only supports Lakeflow Declarative Pipelines development.
To see an example of a supported pipelines template, create a new Pipelines CLI project with "pipelines init".`))
}
}
28 changes: 28 additions & 0 deletions cmd/bundle/utils/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package utils

import (
"context"
"errors"
"path/filepath"
"time"

"github.com/databricks/cli/bundle"
Expand All @@ -11,6 +13,7 @@ import (
"github.com/databricks/cli/bundle/statemgmt"
"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/diag"
"github.com/databricks/cli/libs/dyn"
"github.com/databricks/cli/libs/logdiag"
"github.com/databricks/cli/libs/sync"
"github.com/databricks/cli/libs/telemetry/protos"
Expand Down Expand Up @@ -56,6 +59,9 @@ type ProcessOptions struct {
Validate bool
Build bool
Deploy bool

// Indicate whether the bundle operation originates from the pipelines CLI
IsPipelinesCLI bool
}

func ProcessBundle(cmd *cobra.Command, opts ProcessOptions) (*bundle.Bundle, error) {
Expand Down Expand Up @@ -166,6 +172,14 @@ func ProcessBundleRet(cmd *cobra.Command, opts ProcessOptions) (*bundle.Bundle,
if logdiag.HasError(ctx) {
return b, isDirectEngine, root.ErrAlreadyPrinted
}

// Pipeline CLI only validation.
if opts.IsPipelinesCLI {
rejectDefinitions(ctx, b)
if logdiag.HasError(ctx) {
return b, isDirectEngine, root.ErrAlreadyPrinted
}
}
}

if opts.Validate {
Expand Down Expand Up @@ -210,3 +224,17 @@ func ProcessBundleRet(cmd *cobra.Command, opts ProcessOptions) (*bundle.Bundle,

return b, isDirectEngine, nil
}

func rejectDefinitions(ctx context.Context, b *bundle.Bundle) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit odd to have this here, this package orchestrates existing phases rather than having actual validation logic.

What is we keep it in initialize.go() and then detect pipelines exe via argv[0]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Detecting via argv[0] feels hacky. I don't mind recording IsPipelineCLI in the bundle tree maybe and then record this in initialize.

IMO the current implementation is fine but I'm open to any alternate suggestions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One advantage is it's obvious which code is for pipelines only. You don't have to dive into the guts (the initialize phase here) to see whether some code is for pipelines CLI only or not.

if b.Config.Definitions != nil {
v := dyn.GetValue(b.Config.Value(), "definitions")
loc := v.Locations()
filename := "input yaml"
if len(loc) > 0 {
filename = filepath.ToSlash(loc[0].File)
}
logdiag.LogError(ctx, errors.New(filename+` seems to be formatted for open-source Spark Declarative Pipelines.
Pipelines CLI currently only supports Lakeflow Declarative Pipelines development.
To see an example of a supported pipelines template, create a new Pipelines CLI project with "pipelines init".`))
}
}
11 changes: 6 additions & 5 deletions cmd/pipelines/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ func deployCommand() *cobra.Command {
b.Config.Bundle.Deployment.FailOnActiveRuns = failOnActiveRuns
}
},
Verbose: verbose,
AlwaysPull: true,
FastValidate: true,
Build: true,
Deploy: true,
Verbose: verbose,
AlwaysPull: true,
FastValidate: true,
Build: true,
Deploy: true,
IsPipelinesCLI: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This scopes it down to deploy, but it seems this is something that would be useful in plan & validate as well, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the previous implementation, the error only triggered on deploy. I'll leave it updo the pipelines team if they want this during dry run.

Note pipeliens CLI does not have plan or validate, only a dryrun command.

})
if err != nil {
return err
Expand Down