mirror of https://github.com/databricks/cli.git
Pass compute override as part of the bundle object
This commit is contained in:
parent
5a7b556a5a
commit
34a1698d24
|
@ -33,4 +33,7 @@ type Bundle struct {
|
|||
// For example, 'mode: development' can be used for deployments for
|
||||
// development purposes.
|
||||
Mode Mode `json:"mode,omitempty"`
|
||||
|
||||
// Overrides the compute used for jobs and other supported assets.
|
||||
Compute string `json:"override_compute,omitempty" bundle:"readonly"`
|
||||
}
|
||||
|
|
|
@ -9,32 +9,30 @@ import (
|
|||
"github.com/databricks/cli/bundle/config/resources"
|
||||
)
|
||||
|
||||
type overrideCompute struct {
|
||||
compute string
|
||||
}
|
||||
type overrideCompute struct{}
|
||||
|
||||
func OverrideCompute(compute string) bundle.Mutator {
|
||||
return &overrideCompute{compute: compute}
|
||||
func OverrideCompute() bundle.Mutator {
|
||||
return &overrideCompute{}
|
||||
}
|
||||
|
||||
func (m *overrideCompute) Name() string {
|
||||
return "OverrideCompute"
|
||||
}
|
||||
|
||||
func (m *overrideCompute) overrideJobCompute(j *resources.Job) {
|
||||
func overrideJobCompute(j *resources.Job, compute string) {
|
||||
for i := range j.Tasks {
|
||||
task := &j.Tasks[i]
|
||||
if task.NewCluster != nil {
|
||||
task.NewCluster = nil
|
||||
task.ExistingClusterId = m.compute
|
||||
task.ExistingClusterId = compute
|
||||
} else if task.ExistingClusterId != "" {
|
||||
task.ExistingClusterId = m.compute
|
||||
task.ExistingClusterId = compute
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (m *overrideCompute) Apply(ctx context.Context, b *bundle.Bundle) error {
|
||||
if m.compute == "" {
|
||||
if b.Config.Bundle.Compute == "" {
|
||||
return nil
|
||||
}
|
||||
if b.Config.Bundle.Mode != config.Development {
|
||||
|
@ -43,7 +41,7 @@ func (m *overrideCompute) Apply(ctx context.Context, b *bundle.Bundle) error {
|
|||
|
||||
r := b.Config.Resources
|
||||
for i := range r.Jobs {
|
||||
m.overrideJobCompute(r.Jobs[i])
|
||||
overrideJobCompute(r.Jobs[i], b.Config.Bundle.Compute)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -18,7 +18,8 @@ func TestOverrideCompute(t *testing.T) {
|
|||
bundle := &bundle.Bundle{
|
||||
Config: config.Root{
|
||||
Bundle: config.Bundle{
|
||||
Mode: config.Development,
|
||||
Mode: config.Development,
|
||||
Compute: "newClusterID",
|
||||
},
|
||||
Resources: config.Resources{
|
||||
Jobs: map[string]*resources.Job{
|
||||
|
@ -38,7 +39,7 @@ func TestOverrideCompute(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
m := mutator.OverrideCompute("newClusterID")
|
||||
m := mutator.OverrideCompute()
|
||||
err := m.Apply(context.Background(), bundle)
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, bundle.Config.Resources.Jobs["job1"].Tasks[0].NewCluster)
|
||||
|
|
|
@ -53,7 +53,7 @@ func TestProcessEnvironmentModeApplyDefault(t *testing.T) {
|
|||
bundle := &bundle.Bundle{
|
||||
Config: config.Root{
|
||||
Bundle: config.Bundle{
|
||||
Mode: config.Default,
|
||||
Mode: "",
|
||||
},
|
||||
Resources: config.Resources{
|
||||
Jobs: map[string]*resources.Job{
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
// The initialize phase fills in defaults and connects to the workspace.
|
||||
// Interpolation of fields referring to the "bundle" and "workspace" keys
|
||||
// happens upon completion of this phase.
|
||||
func Initialize(overrideCompute string) bundle.Mutator {
|
||||
func Initialize() bundle.Mutator {
|
||||
return newPhase(
|
||||
"initialize",
|
||||
[]bundle.Mutator{
|
||||
|
@ -25,7 +25,7 @@ func Initialize(overrideCompute string) bundle.Mutator {
|
|||
interpolation.IncludeLookupsInPath("workspace"),
|
||||
interpolation.IncludeLookupsInPath(variable.VariableReferencePrefix),
|
||||
),
|
||||
mutator.OverrideCompute(overrideCompute),
|
||||
mutator.OverrideCompute(),
|
||||
mutator.ProcessEnvironmentMode(),
|
||||
mutator.TranslatePaths(),
|
||||
terraform.Initialize(),
|
||||
|
|
|
@ -21,15 +21,16 @@ var deployCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
func deploy(cmd *cobra.Command, b *bundle.Bundle) error {
|
||||
// If `--force` is specified, force acquisition of the deployment lock.
|
||||
b.Config.Bundle.Lock.Force = forceDeploy
|
||||
|
||||
if computeID == "" {
|
||||
computeID = os.Getenv("DATABRICKS_CLUSTER_ID")
|
||||
}
|
||||
|
||||
// If `--force` is specified, force acquisition of the deployment lock.
|
||||
b.Config.Bundle.Lock.Force = forceDeploy
|
||||
b.Config.Bundle.Compute = computeID
|
||||
|
||||
return bundle.Apply(cmd.Context(), b, bundle.Seq(
|
||||
phases.Initialize(computeID),
|
||||
phases.Initialize(),
|
||||
phases.Build(),
|
||||
phases.Deploy(),
|
||||
))
|
||||
|
|
|
@ -43,7 +43,7 @@ var destroyCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
return bundle.Apply(ctx, b, bundle.Seq(
|
||||
phases.Initialize(""),
|
||||
phases.Initialize(),
|
||||
phases.Build(),
|
||||
phases.Destroy(),
|
||||
))
|
||||
|
|
|
@ -38,7 +38,7 @@ var runCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
err := bundle.Apply(cmd.Context(), b, bundle.Seq(
|
||||
phases.Initialize(computeID),
|
||||
phases.Initialize(),
|
||||
terraform.Interpolate(),
|
||||
terraform.Write(),
|
||||
terraform.StatePull(),
|
||||
|
|
|
@ -39,7 +39,7 @@ var syncCmd = &cobra.Command{
|
|||
b := bundle.Get(cmd.Context())
|
||||
|
||||
// Run initialize phase to make sure paths are set.
|
||||
err := bundle.Apply(cmd.Context(), b, phases.Initialize(""))
|
||||
err := bundle.Apply(cmd.Context(), b, phases.Initialize())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ var validateCmd = &cobra.Command{
|
|||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
b := bundle.Get(cmd.Context())
|
||||
|
||||
err := bundle.Apply(cmd.Context(), b, phases.Initialize(""))
|
||||
err := bundle.Apply(cmd.Context(), b, phases.Initialize())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue