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

Filter out system clusters for --configure-cluster #1031

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 6 additions & 2 deletions cmd/configure/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ func configureInteractive(cmd *cobra.Command, flags *configureFlags, cfg *config

// Ask user to specify a cluster if not already set.
if flags.ConfigureCluster && cfg.ClusterID == "" {
w, err := databricks.NewWorkspaceClient((*databricks.Config)(cfg))
// Create workspace client with configuration without the profile name set.
w, err := databricks.NewWorkspaceClient(&databricks.Config{
Host: cfg.Host,
Token: cfg.Token,
})
if err != nil {
return err
}
clusterID, err := cfgpickers.AskForCluster(cmd.Context(), w)
clusterID, err := cfgpickers.AskForCluster(cmd.Context(), w, cfgpickers.WithoutSystemClusters())
if err != nil {
return err
}
Expand Down
12 changes: 12 additions & 0 deletions libs/databrickscfg/cfgpickers/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ func WithDatabricksConnect(minVersion string) func(*compute.ClusterDetails, *iam
}
}

// WithoutSystemClusters removes clusters created for system purposes (e.g. job runs, pipeline maintenance, etc.).
// It does this by keeping only clusters created through the UI or an API call.
func WithoutSystemClusters() func(*compute.ClusterDetails, *iam.User) bool {
return func(cluster *compute.ClusterDetails, me *iam.User) bool {
switch cluster.ClusterSource {
case compute.ClusterSourceApi, compute.ClusterSourceUi:
return true
}
return false
}
}

func loadInteractiveClusters(ctx context.Context, w *databricks.WorkspaceClient, filters []clusterFilter) ([]compatibleCluster, error) {
promptSpinner := cmdio.Spinner(ctx)
promptSpinner <- "Loading list of clusters to select from"
Expand Down
22 changes: 22 additions & 0 deletions libs/databrickscfg/cfgpickers/clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/databricks/databricks-sdk-go/qa"
"github.com/databricks/databricks-sdk-go/service/compute"
"github.com/databricks/databricks-sdk-go/service/iam"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -44,6 +45,27 @@ func TestIsCompatibleWithSnapshots(t *testing.T) {
}, "14.0"))
}

func TestWithoutSystemClusters(t *testing.T) {
fn := WithoutSystemClusters()

// Sources to exclude.
for _, v := range []string{
"JOB",
"PIPELINE",
"SOME_UNKNOWN_VALUE",
} {
assert.False(t, fn(&compute.ClusterDetails{ClusterSource: compute.ClusterSource(v)}, nil))
}

// Sources to include.
for _, v := range []string{
"UI",
"API",
} {
assert.True(t, fn(&compute.ClusterDetails{ClusterSource: compute.ClusterSource(v)}, nil))
}
}

func TestFirstCompatibleCluster(t *testing.T) {
cfg, server := qa.HTTPFixtures{
{
Expand Down