Support cluster overrides with cluster_key and compute_key (#696)

## Changes

Support `databricks bundle deploy --compute-id my_all_purpose_cluster`
in two missing cases.
This commit is contained in:
Lennart Kats (databricks) 2023-08-28 00:51:35 -07:00 committed by GitHub
parent a5b86093ec
commit 861f33d376
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 3 deletions

View File

@ -23,10 +23,10 @@ func (m *overrideCompute) Name() string {
func overrideJobCompute(j *resources.Job, compute string) {
for i := range j.Tasks {
task := &j.Tasks[i]
if task.NewCluster != nil {
if task.NewCluster != nil || task.ExistingClusterId != "" || task.ComputeKey != "" || task.JobClusterKey != "" {
task.NewCluster = nil
task.ExistingClusterId = compute
} else if task.ExistingClusterId != "" {
task.JobClusterKey = ""
task.ComputeKey = ""
task.ExistingClusterId = compute
}
}

View File

@ -34,6 +34,12 @@ func TestOverrideDevelopment(t *testing.T) {
{
ExistingClusterId: "cluster2",
},
{
ComputeKey: "compute_key",
},
{
JobClusterKey: "cluster_key",
},
},
}},
},
@ -47,6 +53,12 @@ func TestOverrideDevelopment(t *testing.T) {
assert.Nil(t, bundle.Config.Resources.Jobs["job1"].Tasks[0].NewCluster)
assert.Equal(t, "newClusterID", bundle.Config.Resources.Jobs["job1"].Tasks[0].ExistingClusterId)
assert.Equal(t, "newClusterID", bundle.Config.Resources.Jobs["job1"].Tasks[1].ExistingClusterId)
assert.Equal(t, "newClusterID", bundle.Config.Resources.Jobs["job1"].Tasks[2].ExistingClusterId)
assert.Equal(t, "newClusterID", bundle.Config.Resources.Jobs["job1"].Tasks[3].ExistingClusterId)
assert.Nil(t, bundle.Config.Resources.Jobs["job1"].Tasks[0].NewCluster)
assert.Empty(t, bundle.Config.Resources.Jobs["job1"].Tasks[2].ComputeKey)
assert.Empty(t, bundle.Config.Resources.Jobs["job1"].Tasks[3].JobClusterKey)
}
func TestOverrideDevelopmentEnv(t *testing.T) {
@ -77,6 +89,31 @@ func TestOverrideDevelopmentEnv(t *testing.T) {
assert.Equal(t, "cluster2", bundle.Config.Resources.Jobs["job1"].Tasks[1].ExistingClusterId)
}
func TestOverridePipelineTask(t *testing.T) {
os.Setenv("DATABRICKS_CLUSTER_ID", "newClusterId")
bundle := &bundle.Bundle{
Config: config.Root{
Resources: config.Resources{
Jobs: map[string]*resources.Job{
"job1": {JobSettings: &jobs.JobSettings{
Name: "job1",
Tasks: []jobs.Task{
{
PipelineTask: &jobs.PipelineTask{},
},
},
}},
},
},
},
}
m := mutator.OverrideCompute()
err := m.Apply(context.Background(), bundle)
require.NoError(t, err)
assert.Empty(t, bundle.Config.Resources.Jobs["job1"].Tasks[0].ExistingClusterId)
}
func TestOverrideProduction(t *testing.T) {
bundle := &bundle.Bundle{
Config: config.Root{