-
Notifications
You must be signed in to change notification settings - Fork 184
Added support for creating all-purpose clusters #1698
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
Changes from 2 commits
c55a2dc
7366c69
f667e12
9783b95
b312691
032a74a
bb58bd1
67557b7
0391933
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ func allResourceTypes(t *testing.T) []string { | |
| // the dyn library gives us the correct list of all resources supported. Please | ||
| // also update this check when adding a new resource | ||
| require.Equal(t, []string{ | ||
| "clusters", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does it work with I can see how it works with shared-user clusters, but is (I think?) incompatible with single-user clusters.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does not work with run_as, this list is just list of available resources. Then it's added in |
||
| "experiments", | ||
| "jobs", | ||
| "model_serving_endpoints", | ||
|
|
@@ -133,6 +134,7 @@ func TestRunAsErrorForUnsupportedResources(t *testing.T) { | |
| // some point in the future. These resources are (implicitly) on the deny list, since | ||
| // they are not on the allow list below. | ||
| allowList := []string{ | ||
| "clusters", | ||
| "jobs", | ||
| "models", | ||
| "registered_models", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package resources | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/databricks/cli/libs/log" | ||
| "github.com/databricks/databricks-sdk-go" | ||
| "github.com/databricks/databricks-sdk-go/marshal" | ||
| "github.com/databricks/databricks-sdk-go/service/compute" | ||
| ) | ||
|
|
||
| type Cluster struct { | ||
| ID string `json:"id,omitempty" bundle:"readonly"` | ||
| Permissions []Permission `json:"permissions,omitempty"` | ||
| ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"` | ||
|
|
||
| *compute.ClusterSpec | ||
| } | ||
|
|
||
| func (s *Cluster) UnmarshalJSON(b []byte) error { | ||
| return marshal.Unmarshal(b, s) | ||
| } | ||
|
|
||
| func (s Cluster) MarshalJSON() ([]byte, error) { | ||
| return marshal.Marshal(s) | ||
| } | ||
|
|
||
| func (s *Cluster) Exists(ctx context.Context, w *databricks.WorkspaceClient, id string) (bool, error) { | ||
| _, err := w.Clusters.GetByClusterId(ctx, id) | ||
| if err != nil { | ||
| log.Debugf(ctx, "cluster %s does not exist", id) | ||
| return false, err | ||
| } | ||
| return true, nil | ||
| } | ||
|
|
||
| func (s *Cluster) TerraformResourceName() string { | ||
| return "databricks_cluster" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package tfdyn | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/databricks/cli/bundle/internal/tf/schema" | ||
| "github.com/databricks/cli/libs/dyn" | ||
| "github.com/databricks/cli/libs/dyn/convert" | ||
| "github.com/databricks/cli/libs/log" | ||
| "github.com/databricks/databricks-sdk-go/service/compute" | ||
| ) | ||
|
|
||
| func convertClusterResource(ctx context.Context, vin dyn.Value) (dyn.Value, error) { | ||
| // Normalize the output value to the target schema. | ||
| vout, diags := convert.Normalize(compute.ClusterSpec{}, vin) | ||
| for _, diag := range diags { | ||
| log.Debugf(ctx, "cluster normalization diagnostic: %s", diag.Summary) | ||
| } | ||
|
|
||
| return vout, nil | ||
| } | ||
|
|
||
| type clusterConverter struct{} | ||
|
|
||
| func (clusterConverter) Convert(ctx context.Context, key string, vin dyn.Value, out *schema.Resources) error { | ||
| vout, err := convertClusterResource(ctx, vin) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Add the converted resource to the output. | ||
| out.Cluster[key] = vout.AsAny() | ||
|
|
||
| // Configure permissions for this resource. | ||
| if permissions := convertPermissionsResource(ctx, vin); permissions != nil { | ||
| permissions.JobId = fmt.Sprintf("${databricks_cluster.%s.id}", key) | ||
| out.Permissions["cluster_"+key] = permissions | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func init() { | ||
| registerConverter("clusters", clusterConverter{}) | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.