-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Exporter] Use Go SDK to list clusters
This helps us with the following: - use paginated output that is more efficient - automatically filter non-interactive clusters instead of doing it ourselves P.S. We still have usage of 2.0 API coming from mounts and some other places
- Loading branch information
Showing
6 changed files
with
103 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package exporter | ||
|
||
import ( | ||
"log" | ||
"strings" | ||
|
||
sdk_compute "github.com/databricks/databricks-sdk-go/service/compute" | ||
) | ||
|
||
func listClusters(ic *importContext) error { | ||
lastActiveMs := ic.getLastActiveMs() | ||
interactiveClusters := []sdk_compute.ClusterSource{sdk_compute.ClusterSourceUi, sdk_compute.ClusterSourceApi} | ||
|
||
it := ic.workspaceClient.Clusters.List(ic.Context, sdk_compute.ListClustersRequest{ | ||
FilterBy: &sdk_compute.ListClustersFilterBy{ | ||
ClusterSources: interactiveClusters, | ||
}, | ||
PageSize: 100, | ||
}) | ||
i := 0 | ||
for it.HasNext(ic.Context) { | ||
c, err := it.Next(ic.Context) | ||
if err != nil { | ||
return err | ||
} | ||
i++ | ||
|
||
if strings.HasPrefix(c.ClusterName, "terraform-") { | ||
log.Printf("[INFO] Skipping terraform-specific cluster %s", c.ClusterName) | ||
continue | ||
} | ||
if !ic.MatchesName(c.ClusterName) { | ||
log.Printf("[INFO] Skipping %s because it doesn't match %s", c.ClusterName, ic.match) | ||
continue | ||
} | ||
if c.LastRestartedTime > 0 && c.LastRestartedTime < lastActiveMs { | ||
log.Printf("[INFO] Old inactive cluster %s", c.ClusterName) | ||
continue | ||
} | ||
ic.Emit(&resource{ | ||
Resource: "databricks_cluster", | ||
ID: c.ClusterId, | ||
}) | ||
if i%50 == 0 { | ||
log.Printf("[INFO] Scanned %d clusters", i) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (ic *importContext) importCluster(c *sdk_compute.ClusterSpec) { | ||
if c == nil { | ||
return | ||
} | ||
if c.AwsAttributes != nil && c.AwsAttributes.InstanceProfileArn != "" { | ||
ic.Emit(&resource{ | ||
Resource: "databricks_instance_profile", | ||
ID: c.AwsAttributes.InstanceProfileArn, | ||
}) | ||
} | ||
if c.InstancePoolId != "" { | ||
// set enable_elastic_disk to false, and remove aws/gcp/azure_attributes | ||
ic.Emit(&resource{ | ||
Resource: "databricks_instance_pool", | ||
ID: c.InstancePoolId, | ||
}) | ||
} | ||
if c.DriverInstancePoolId != "" { | ||
ic.Emit(&resource{ | ||
Resource: "databricks_instance_pool", | ||
ID: c.DriverInstancePoolId, | ||
}) | ||
} | ||
if c.PolicyId != "" { | ||
ic.Emit(&resource{ | ||
Resource: "databricks_cluster_policy", | ||
ID: c.PolicyId, | ||
}) | ||
} | ||
ic.emitInitScripts(c.InitScripts) | ||
ic.emitSecretsFromSecretsPathMap(c.SparkConf) | ||
ic.emitSecretsFromSecretsPathMap(c.SparkEnvVars) | ||
ic.emitUserOrServicePrincipal(c.SingleUserName) | ||
if c.Kind.String() != "" && c.SingleUserName != "" { | ||
ic.Emit(&resource{ | ||
Resource: "databricks_group", | ||
Attribute: "display_name", | ||
Value: c.SingleUserName, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters