Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Provide more prescriptive error when users fail to create a single node cluster #4168

Merged
merged 7 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion clusters/clusters_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func (cluster Cluster) Validate() error {
if profile == "singleNode" && strings.HasPrefix(master, "local") && resourceClass == "SingleNode" {
return nil
}
return fmt.Errorf("NumWorkers could be 0 only for SingleNode clusters. See https://docs.databricks.com/clusters/single-node.html for more details")
return errors.New(numWorkerErr)
}

// TODO: Remove this once all the resources using clusters are migrated to Go SDK.
Expand Down
21 changes: 20 additions & 1 deletion clusters/resource_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,26 @@ var clusterSchema = resourceClusterSchema()
var clusterSchemaVersion = 4

const (
numWorkerErr = "NumWorkers could be 0 only for SingleNode clusters. See https://docs.databricks.com/clusters/single-node.html for more details"
numWorkerErr = `NumWorkers could be 0 only for SingleNode clusters. To create a single node
shreyas-goenka marked this conversation as resolved.
Show resolved Hide resolved
cluster please include the following configuration in your cluster configuration:

spark_conf = {
"spark.databricks.cluster.profile" : "singleNode"
"spark.master" : "local[*]"
}

custom_tags = {
"ResourceClass" = "SingleNode"
}

Please note that the Databricks Terraform provider cannot detect if the above configuration
is defined in a policy used by the cluster. Please define this in the cluster configuration
itself to create a single node cluster.

For more details please see:
1. https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/cluster#fixed-size-or-autoscaling-cluster
2. https://docs.databricks.com/clusters/single-node.html`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO:Followup on better docs.


unsupportedExceptCreateEditClusterSpecErr = "unsupported type %T, must be one of %scompute.CreateCluster, %scompute.ClusterSpec or %scompute.EditCluster. Please report this issue to the GitHub repo"
)

Expand Down
6 changes: 2 additions & 4 deletions clusters/resource_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1860,8 +1860,7 @@ func TestResourceClusterCreate_SingleNodeFail(t *testing.T) {
"is_pinned": false,
},
}.Apply(t)
assert.Error(t, err)
require.Equal(t, true, strings.Contains(err.Error(), "NumWorkers could be 0 only for SingleNode clusters"))
assert.EqualError(t, err, numWorkerErr)
}

func TestResourceClusterCreate_NegativeNumWorkers(t *testing.T) {
Expand Down Expand Up @@ -1900,8 +1899,7 @@ func TestResourceClusterUpdate_FailNumWorkersZero(t *testing.T) {
"num_workers": 0,
},
}.Apply(t)
assert.Error(t, err)
require.Equal(t, true, strings.Contains(err.Error(), "NumWorkers could be 0 only for SingleNode clusters"))
assert.EqualError(t, err, numWorkerErr)
}

func TestModifyClusterRequestAws(t *testing.T) {
Expand Down
34 changes: 30 additions & 4 deletions jobs/resource_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2056,8 +2056,21 @@ func TestResourceJobCreateSingleNode_Fail(t *testing.T) {
jar = "dbfs://ff/gg/hh.jar"
}`,
}.Apply(t)
assert.Error(t, err)
require.Equal(t, true, strings.Contains(err.Error(), "NumWorkers could be 0 only for SingleNode clusters"))
assert.ErrorContains(t, err, `NumWorkers could be 0 only for SingleNode clusters. To create a single node
cluster please include the following configuration in your cluster configuration:

spark_conf = {
"spark.databricks.cluster.profile" : "singleNode"
"spark.master" : "local[*]"
}

custom_tags = {
"ResourceClass" = "SingleNode"
}

Please note that the Databricks Terraform provider cannot detect if the above configuration
is defined in a policy used by the cluster. Please define this in the cluster configuration
itself to create a single node cluster.`)
}

func TestResourceJobRead(t *testing.T) {
Expand Down Expand Up @@ -2946,8 +2959,21 @@ func TestResourceJobUpdate_FailNumWorkersZero(t *testing.T) {
parameters = ["--cleanup", "full"]
}`,
}.Apply(t)
assert.Error(t, err)
require.Equal(t, true, strings.Contains(err.Error(), "NumWorkers could be 0 only for SingleNode clusters"))
assert.ErrorContains(t, err, `NumWorkers could be 0 only for SingleNode clusters. To create a single node
cluster please include the following configuration in your cluster configuration:

spark_conf = {
"spark.databricks.cluster.profile" : "singleNode"
"spark.master" : "local[*]"
}

custom_tags = {
"ResourceClass" = "SingleNode"
}

Please note that the Databricks Terraform provider cannot detect if the above configuration
is defined in a policy used by the cluster. Please define this in the cluster configuration
itself to create a single node cluster.`)
}

func TestJobsAPIList(t *testing.T) {
Expand Down
Loading