diff --git a/cmd/configure/configure.go b/cmd/configure/configure.go index 1c4d2e6b27..1e94ddae8d 100644 --- a/cmd/configure/configure.go +++ b/cmd/configure/configure.go @@ -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 } diff --git a/libs/databrickscfg/cfgpickers/clusters.go b/libs/databrickscfg/cfgpickers/clusters.go index ac037698e4..d955be35b8 100644 --- a/libs/databrickscfg/cfgpickers/clusters.go +++ b/libs/databrickscfg/cfgpickers/clusters.go @@ -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" diff --git a/libs/databrickscfg/cfgpickers/clusters_test.go b/libs/databrickscfg/cfgpickers/clusters_test.go index 362d6904f5..8afcd6d074 100644 --- a/libs/databrickscfg/cfgpickers/clusters_test.go +++ b/libs/databrickscfg/cfgpickers/clusters_test.go @@ -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" ) @@ -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{ {