Skip to content

Commit 6b2ba62

Browse files
authored
pipelines deploy: oss spark pipelines YAML warning message (#3312)
## Changes When deploying any project with an OSS formatted YAML file, ie one that begins with the definitions: field intead of resources:, display an error message explaining that Pipelines CLI does not support OSS files. forces deploy to fail. ## Tests Unit tests checking error message. Acceptance tests in follow-up: #3313
1 parent 69ce9b0 commit 6b2ba62

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

cmd/pipelines/deploy.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,20 @@ func deployCommand() *cobra.Command {
4242
ctx := logdiag.InitContext(cmd.Context())
4343
cmd.SetContext(ctx)
4444

45+
// Enable collection of diagnostics to check for OSS template warning in ConfigureBundleWithVariables
46+
logdiag.SetCollect(ctx, true)
47+
4548
b := utils.ConfigureBundleWithVariables(cmd)
4649
if b == nil || logdiag.HasError(ctx) {
4750
return root.ErrAlreadyPrinted
4851
}
52+
logdiag.SetCollect(ctx, false)
53+
54+
diags := logdiag.FlushCollected(ctx)
55+
// Prevent deploying open-source Spark Declarative Pipelines YAML files with the Pipelines CLI.
56+
if err := checkForOSSTemplateWarning(ctx, diags); err != nil {
57+
return err
58+
}
4959

5060
bundle.ApplyFuncContext(ctx, b, func(context.Context, *bundle.Bundle) {
5161
b.Config.Bundle.Deployment.Lock.Force = forceLock

cmd/pipelines/deploy_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package pipelines
2+
3+
import (
4+
"testing"
5+
6+
"github.com/databricks/cli/libs/diag"
7+
"github.com/databricks/cli/libs/dyn"
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
func TestFormatOSSTemplateWarningMessage(t *testing.T) {
12+
d := diag.Diagnostic{
13+
Severity: diag.Warning,
14+
Summary: "unknown field: definitions",
15+
Paths: []dyn.Path{dyn.EmptyPath},
16+
Locations: []dyn.Location{
17+
{File: "test-pipeline.yml"},
18+
},
19+
}
20+
21+
message := formatOSSTemplateWarningMessage(d)
22+
assert.Contains(t, message, "test-pipeline.yml seems to be formatted for open-source Spark Declarative Pipelines.")
23+
}

cmd/pipelines/utils.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"strings"
78

89
"github.com/databricks/cli/bundle"
910
configresources "github.com/databricks/cli/bundle/config/resources"
1011
"github.com/databricks/cli/bundle/resources"
1112
"github.com/databricks/cli/bundle/run"
1213
"github.com/databricks/cli/libs/cmdio"
14+
"github.com/databricks/cli/libs/diag"
15+
"github.com/databricks/cli/libs/dyn"
16+
"github.com/databricks/cli/libs/logdiag"
1317
)
1418

1519
// Copied from cmd/bundle/run.go
@@ -88,3 +92,37 @@ func keyToRunner(b *bundle.Bundle, arg string) (run.Runner, error) {
8892

8993
return runner, nil
9094
}
95+
96+
// formatOSSTemplateWarningMessage formats the warning message for OSS template pipeline YAML files.
97+
func formatOSSTemplateWarningMessage(d diag.Diagnostic) string {
98+
fileName := "A pipeline YAML file"
99+
if len(d.Locations) > 0 && d.Locations[0].File != "" {
100+
fileName = d.Locations[0].File
101+
}
102+
103+
return fileName + ` seems to be formatted for open-source Spark Declarative Pipelines.
104+
Pipelines CLI currently only supports Lakeflow Declarative Pipelines development.
105+
To see an example of a supported pipelines template, create a new Pipelines CLI project with "pipelines init".`
106+
}
107+
108+
// checkForOSSTemplateWarning checks for a warning in the logs that suggests a pipelines YAML file
109+
// is formatted for open-source Spark Declarative Pipelines and returns an error if found.
110+
// For the Spark Declarative Pipelines template, see: https://github.com/apache/spark/blob/master/python/pyspark/pipelines/init_cli.py
111+
// Logs all collected diagnostics to expose them.
112+
func checkForOSSTemplateWarning(ctx context.Context, diags diag.Diagnostics) error {
113+
var ossWarning *diag.Diagnostic
114+
115+
for _, d := range diags {
116+
// The "definitions" field in the root is expected in OSS Spark Declarative Pipelines templates but is not supported in the Pipelines CLI.
117+
if d.Severity == diag.Warning && strings.Contains(d.Summary, "unknown field: definitions") && len(d.Paths) == 1 && d.Paths[0].Equal(dyn.EmptyPath) {
118+
ossWarning = &d
119+
}
120+
logdiag.LogDiag(ctx, d)
121+
}
122+
123+
if ossWarning != nil {
124+
return errors.New(formatOSSTemplateWarningMessage(*ossWarning))
125+
}
126+
127+
return nil
128+
}

0 commit comments

Comments
 (0)