mirror of https://github.com/databricks/cli.git
Filter out system clusters for `--configure-cluster` (#1031)
## Changes Only clusters with their source attribute equal to `UI` or `API` should be presented in the dropdown. ## Tests Unit test and manual confirmation.
This commit is contained in:
parent
4a228e6f12
commit
10c9eca06f
|
@ -50,7 +50,7 @@ func configureInteractive(cmd *cobra.Command, flags *configureFlags, cfg *config
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
clusterID, err := cfgpickers.AskForCluster(cmd.Context(), w)
|
clusterID, err := cfgpickers.AskForCluster(cmd.Context(), w, cfgpickers.WithoutSystemClusters())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
func loadInteractiveClusters(ctx context.Context, w *databricks.WorkspaceClient, filters []clusterFilter) ([]compatibleCluster, error) {
|
||||||
promptSpinner := cmdio.Spinner(ctx)
|
promptSpinner := cmdio.Spinner(ctx)
|
||||||
promptSpinner <- "Loading list of clusters to select from"
|
promptSpinner <- "Loading list of clusters to select from"
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"github.com/databricks/databricks-sdk-go/qa"
|
"github.com/databricks/databricks-sdk-go/qa"
|
||||||
"github.com/databricks/databricks-sdk-go/service/compute"
|
"github.com/databricks/databricks-sdk-go/service/compute"
|
||||||
"github.com/databricks/databricks-sdk-go/service/iam"
|
"github.com/databricks/databricks-sdk-go/service/iam"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -44,6 +45,27 @@ func TestIsCompatibleWithSnapshots(t *testing.T) {
|
||||||
}, "14.0"))
|
}, "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) {
|
func TestFirstCompatibleCluster(t *testing.T) {
|
||||||
cfg, server := qa.HTTPFixtures{
|
cfg, server := qa.HTTPFixtures{
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue