Skip to content

Commit 38eeb21

Browse files
[Fix] Provide more prescriptive error when users fail to create a single node cluster (#4168)
## Changes A better error message is warranted because many DABs customers have reportedly run into this. Original issue: databricks/cli#1546 ## Tests Unit test
1 parent 92357dc commit 38eeb21

File tree

4 files changed

+53
-10
lines changed

4 files changed

+53
-10
lines changed

clusters/clusters_api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ func (cluster Cluster) Validate() error {
447447
if profile == "singleNode" && strings.HasPrefix(master, "local") && resourceClass == "SingleNode" {
448448
return nil
449449
}
450-
return fmt.Errorf("NumWorkers could be 0 only for SingleNode clusters. See https://docs.databricks.com/clusters/single-node.html for more details")
450+
return errors.New(numWorkerErr)
451451
}
452452

453453
// TODO: Remove this once all the resources using clusters are migrated to Go SDK.

clusters/resource_cluster.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,26 @@ var clusterSchema = resourceClusterSchema()
2626
var clusterSchemaVersion = 4
2727

2828
const (
29-
numWorkerErr = "NumWorkers could be 0 only for SingleNode clusters. See https://docs.databricks.com/clusters/single-node.html for more details"
29+
numWorkerErr = `num_workers may be 0 only for single-node clusters. To create a single node
30+
cluster please include the following configuration in your cluster configuration:
31+
32+
spark_conf = {
33+
"spark.databricks.cluster.profile" : "singleNode"
34+
"spark.master" : "local[*]"
35+
}
36+
37+
custom_tags = {
38+
"ResourceClass" = "SingleNode"
39+
}
40+
41+
Please note that the Databricks Terraform provider cannot detect if the above configuration
42+
is defined in a policy used by the cluster. Please define this in the cluster configuration
43+
itself to create a single node cluster.
44+
45+
For more details please see:
46+
1. https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/cluster#fixed-size-or-autoscaling-cluster
47+
2. https://docs.databricks.com/clusters/single-node.html`
48+
3049
unsupportedExceptCreateEditClusterSpecErr = "unsupported type %T, must be one of %scompute.CreateCluster, %scompute.ClusterSpec or %scompute.EditCluster. Please report this issue to the GitHub repo"
3150
)
3251

clusters/resource_cluster_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,8 +1860,7 @@ func TestResourceClusterCreate_SingleNodeFail(t *testing.T) {
18601860
"is_pinned": false,
18611861
},
18621862
}.Apply(t)
1863-
assert.Error(t, err)
1864-
require.Equal(t, true, strings.Contains(err.Error(), "NumWorkers could be 0 only for SingleNode clusters"))
1863+
assert.EqualError(t, err, numWorkerErr)
18651864
}
18661865

18671866
func TestResourceClusterCreate_NegativeNumWorkers(t *testing.T) {
@@ -1900,8 +1899,7 @@ func TestResourceClusterUpdate_FailNumWorkersZero(t *testing.T) {
19001899
"num_workers": 0,
19011900
},
19021901
}.Apply(t)
1903-
assert.Error(t, err)
1904-
require.Equal(t, true, strings.Contains(err.Error(), "NumWorkers could be 0 only for SingleNode clusters"))
1902+
assert.EqualError(t, err, numWorkerErr)
19051903
}
19061904

19071905
func TestModifyClusterRequestAws(t *testing.T) {

jobs/resource_job_test.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,8 +2056,21 @@ func TestResourceJobCreateSingleNode_Fail(t *testing.T) {
20562056
jar = "dbfs://ff/gg/hh.jar"
20572057
}`,
20582058
}.Apply(t)
2059-
assert.Error(t, err)
2060-
require.Equal(t, true, strings.Contains(err.Error(), "NumWorkers could be 0 only for SingleNode clusters"))
2059+
assert.ErrorContains(t, err, `num_workers may be 0 only for single-node clusters. To create a single node
2060+
cluster please include the following configuration in your cluster configuration:
2061+
2062+
spark_conf = {
2063+
"spark.databricks.cluster.profile" : "singleNode"
2064+
"spark.master" : "local[*]"
2065+
}
2066+
2067+
custom_tags = {
2068+
"ResourceClass" = "SingleNode"
2069+
}
2070+
2071+
Please note that the Databricks Terraform provider cannot detect if the above configuration
2072+
is defined in a policy used by the cluster. Please define this in the cluster configuration
2073+
itself to create a single node cluster.`)
20612074
}
20622075

20632076
func TestResourceJobRead(t *testing.T) {
@@ -2946,8 +2959,21 @@ func TestResourceJobUpdate_FailNumWorkersZero(t *testing.T) {
29462959
parameters = ["--cleanup", "full"]
29472960
}`,
29482961
}.Apply(t)
2949-
assert.Error(t, err)
2950-
require.Equal(t, true, strings.Contains(err.Error(), "NumWorkers could be 0 only for SingleNode clusters"))
2962+
assert.ErrorContains(t, err, `num_workers may be 0 only for single-node clusters. To create a single node
2963+
cluster please include the following configuration in your cluster configuration:
2964+
2965+
spark_conf = {
2966+
"spark.databricks.cluster.profile" : "singleNode"
2967+
"spark.master" : "local[*]"
2968+
}
2969+
2970+
custom_tags = {
2971+
"ResourceClass" = "SingleNode"
2972+
}
2973+
2974+
Please note that the Databricks Terraform provider cannot detect if the above configuration
2975+
is defined in a policy used by the cluster. Please define this in the cluster configuration
2976+
itself to create a single node cluster.`)
29512977
}
29522978

29532979
func TestJobsAPIList(t *testing.T) {

0 commit comments

Comments
 (0)