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
4 changes: 4 additions & 0 deletions libs/jsonschema/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ type Extension struct {
// If the CLI version is less than this value, then validation for this
// schema will fail.
MinDatabricksCliVersion string `json:"min_databricks_cli_version,omitempty"`

// Version of the schema. This is used to determine if the schema is
// compatible with the current CLI version.
Version *int `json:"version,omitempty"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why can't we use MinDatabricksCliVersion for this? They seem to be serving the same purpose

Copy link
Copy Markdown
Contributor Author

@shreyas-goenka shreyas-goenka Nov 9, 2023

Choose a reason for hiding this comment

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

You are right. We don't need this right now. Longer term though this will become necessary since we need a well defined contract for template features we support in every CLI version.

Minimum CLI version does not have a upper bound on supported CLI version for a template. That does not allows us to make breaking changes to templates in future CLI versions.

The main motivation is to keep templates stable. As mlops-stacks goes GA they will start versioning their releases and at that point we need this to define the minimum and maximum template versions supported by a CLI.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

But can it be done with let's say having MaxDatabricksCliVersion later to allow for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, but that's not a great UX. Template authors should not have to track CLI versions supported by their template. A better contract is for them to subscribe to a template version.

I agree though in retrospect that maybe we could have done this in the first place and not added MinDatabricksCliVersion

}
6 changes: 6 additions & 0 deletions libs/template/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (
"golang.org/x/exp/maps"
)

// The latest template schema version supported by the CLI
const latestSchemaVersion = 1

type config struct {
ctx context.Context
values map[string]any
Expand Down Expand Up @@ -49,6 +52,9 @@ func validateSchema(schema *jsonschema.Schema) error {
return fmt.Errorf("property type %s is not supported by bundle templates", v.Type)
}
}
if schema.Version != nil && *schema.Version > latestSchemaVersion {
return fmt.Errorf("template schema version %d is not supported by this version of the CLI. Please upgrade your CLI to the latest version", *schema.Version)
}
return nil
}

Expand Down
35 changes: 35 additions & 0 deletions libs/template/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package template

import (
"context"
"fmt"
"testing"

"github.com/databricks/cli/cmd/root"
Expand Down Expand Up @@ -150,6 +151,40 @@ func TestTemplateValidateSchema(t *testing.T) {
assert.EqualError(t, err, "property type array is not supported by bundle templates")
}

func TestTemplateValidateSchemaVersion(t *testing.T) {
version := latestSchemaVersion
schema := jsonschema.Schema{
Extension: jsonschema.Extension{
Version: &version,
},
}
assert.NoError(t, validateSchema(&schema))

version = latestSchemaVersion + 1
schema = jsonschema.Schema{
Extension: jsonschema.Extension{
Version: &version,
},
}
assert.EqualError(t, validateSchema(&schema), fmt.Sprintf("template schema version %d is not supported by this version of the CLI. Please upgrade your CLI to the latest version", version))

version = 5000
schema = jsonschema.Schema{
Extension: jsonschema.Extension{
Version: &version,
},
}
assert.EqualError(t, validateSchema(&schema), "template schema version 5000 is not supported by this version of the CLI. Please upgrade your CLI to the latest version")

version = 0
schema = jsonschema.Schema{
Extension: jsonschema.Extension{
Version: &version,
},
}
assert.NoError(t, validateSchema(&schema))
}

func TestTemplateEnumValidation(t *testing.T) {
schema := jsonschema.Schema{
Properties: map[string]*jsonschema.Schema{
Expand Down