Skip to content

Commit

Permalink
Fix compute override for foreach tasks (#1357)
Browse files Browse the repository at this point in the history
## Changes
Fix compute override for foreach tasks.

```
$ databricks bundle deploy --compute-id=xxx
```

## Tests
I added unit tests
  • Loading branch information
kanterov authored Apr 12, 2024
1 parent 4529b1a commit e421564
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion bundle/config/mutator/override_compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ func (m *overrideCompute) Name() string {

func overrideJobCompute(j *resources.Job, compute string) {
for i := range j.Tasks {
task := &j.Tasks[i]
var task = &j.Tasks[i]

if task.ForEachTask != nil {
task = &task.ForEachTask.Task
}

if task.NewCluster != nil || task.ExistingClusterId != "" || task.ComputeKey != "" || task.JobClusterKey != "" {
task.NewCluster = nil
task.JobClusterKey = ""
Expand Down
25 changes: 25 additions & 0 deletions bundle/config/mutator/override_compute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,31 @@ func TestOverridePipelineTask(t *testing.T) {
assert.Empty(t, b.Config.Resources.Jobs["job1"].Tasks[0].ExistingClusterId)
}

func TestOverrideForEachTask(t *testing.T) {
t.Setenv("DATABRICKS_CLUSTER_ID", "newClusterId")
b := &bundle.Bundle{
Config: config.Root{
Resources: config.Resources{
Jobs: map[string]*resources.Job{
"job1": {JobSettings: &jobs.JobSettings{
Name: "job1",
Tasks: []jobs.Task{
{
ForEachTask: &jobs.ForEachTask{},
},
},
}},
},
},
},
}

m := mutator.OverrideCompute()
diags := bundle.Apply(context.Background(), b, m)
require.NoError(t, diags.Error())
assert.Empty(t, b.Config.Resources.Jobs["job1"].Tasks[0].ForEachTask.Task)
}

func TestOverrideProduction(t *testing.T) {
b := &bundle.Bundle{
Config: config.Root{
Expand Down

0 comments on commit e421564

Please sign in to comment.