Skip to content

Commit f1d7ab1

Browse files
authored
CLOUDP-326299: List independentShardScaling flag should list only ISS… (#3989)
1 parent 3147f57 commit f1d7ab1

File tree

6 files changed

+128
-2
lines changed

6 files changed

+128
-2
lines changed

docs/command/atlas-clusters-list.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,11 @@ Examples
110110

111111
# Return a JSON-formatted list of all clusters for the project with ID 5e2211c17a3e5a48f5497de3:
112112
atlas clusters list --projectId 5e2211c17a3e5a48f5497de3 --output json
113+
114+
115+
.. code-block::
116+
:copyable: false
117+
118+
# Return a JSON-formatted list of all clusters for the project with ID 5e2211c17a3e5a48f5497de3 and with independent shard scaling mode:
119+
atlas clusters list --projectId 5e2211c17a3e5a48f5497de3 --autoScalingMode independentShardScaling --output json
120+

internal/cli/clusters/list.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type ClusterLister interface {
3636
ProjectClusters(string, *store.ListOptions) (*atlasClustersPinned.PaginatedAdvancedClusterDescription, error)
3737
ListFlexClusters(*atlasv2.ListFlexClustersApiParams) (*atlasv2.PaginatedFlexClusters20241113, error)
3838
LatestProjectClusters(string, *store.ListOptions) (*atlasv2.PaginatedClusterDescription20240805, error)
39+
GetClusterAutoScalingConfig(string, string) (*atlasv2.ClusterDescriptionAutoScalingModeConfiguration, error)
3940
}
4041

4142
type ListOpts struct {
@@ -69,11 +70,15 @@ func (opts *ListOpts) Run() error {
6970

7071
func (opts *ListOpts) RunDedicatedCluster() error {
7172
listOpts := opts.NewAtlasListOptions()
72-
if opts.autoScalingMode == independentShardScalingFlag {
73+
if isIndependentShardScaling(opts.autoScalingMode) {
7374
r, err := opts.store.LatestProjectClusters(opts.ConfigProjectID(), listOpts)
7475
if err != nil {
7576
return err
7677
}
78+
r, err = opts.filterClustersByAutoScalingMode(r)
79+
if err != nil {
80+
return err
81+
}
7782
return opts.Print(r)
7883
}
7984

@@ -85,6 +90,22 @@ func (opts *ListOpts) RunDedicatedCluster() error {
8590
return opts.Print(r)
8691
}
8792

93+
func (opts *ListOpts) filterClustersByAutoScalingMode(clusters *atlasv2.PaginatedClusterDescription20240805) (*atlasv2.PaginatedClusterDescription20240805, error) {
94+
filteredClusters := make([]atlasv2.ClusterDescription20240805, 0)
95+
for _, cluster := range clusters.GetResults() {
96+
clusterAutoScalingConfig, err := opts.store.GetClusterAutoScalingConfig(opts.ConfigProjectID(), *cluster.Name)
97+
if err != nil {
98+
return nil, err
99+
}
100+
if isIndependentShardScaling(clusterAutoScalingConfig.GetAutoScalingMode()) {
101+
filteredClusters = append(filteredClusters, cluster)
102+
}
103+
}
104+
105+
clusters.Results = &filteredClusters
106+
return clusters, nil
107+
}
108+
88109
func (opts *ListOpts) RunFlexCluster() error {
89110
r, err := opts.store.ListFlexClusters(opts.newListFlexClustersAPIParams())
90111
if err != nil {
@@ -118,7 +139,11 @@ func ListBuilder() *cobra.Command {
118139
"output": listTemplate,
119140
},
120141
Example: ` # Return a JSON-formatted list of all clusters for the project with ID 5e2211c17a3e5a48f5497de3:
121-
atlas clusters list --projectId 5e2211c17a3e5a48f5497de3 --output json`,
142+
atlas clusters list --projectId 5e2211c17a3e5a48f5497de3 --output json
143+
144+
# Return a JSON-formatted list of all clusters for the project with ID 5e2211c17a3e5a48f5497de3 and with independent shard scaling mode:
145+
atlas clusters list --projectId 5e2211c17a3e5a48f5497de3 --autoScalingMode independentShardScaling --output json
146+
`,
122147
PreRunE: func(cmd *cobra.Command, _ []string) error {
123148
return opts.PreRunE(
124149
opts.ValidateProjectID,

internal/cli/clusters/list_mock_test.go

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/cli/clusters/list_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ func TestList_RunDedicatedCluster_IndependentShardScaling(t *testing.T) {
9090
Name: pointer.Get("test"),
9191
Id: pointer.Get("123"),
9292
},
93+
{
94+
Name: pointer.Get("nonISS"),
95+
Id: pointer.Get("124"),
96+
},
9397
},
9498
}
9599

@@ -98,6 +102,22 @@ func TestList_RunDedicatedCluster_IndependentShardScaling(t *testing.T) {
98102
autoScalingMode: independentShardScalingFlag,
99103
}
100104

105+
mockStore.
106+
EXPECT().
107+
GetClusterAutoScalingConfig(listOpts.ProjectID, *expected.GetResults()[0].Name).
108+
Return(&atlasv2.ClusterDescriptionAutoScalingModeConfiguration{
109+
AutoScalingMode: pointer.Get(independentShardScalingFlag),
110+
}, nil).
111+
Times(1)
112+
113+
mockStore.
114+
EXPECT().
115+
GetClusterAutoScalingConfig(listOpts.ProjectID, *expected.GetResults()[1].Name).
116+
Return(&atlasv2.ClusterDescriptionAutoScalingModeConfiguration{
117+
AutoScalingMode: pointer.Get(clusterWideScalingFlag),
118+
}, nil).
119+
Times(1)
120+
101121
mockStore.
102122
EXPECT().
103123
LatestProjectClusters(listOpts.ProjectID, listOpts.NewAtlasListOptions()).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
HTTP/2.0 200 OK
2+
Content-Length: 47
3+
Content-Type: application/vnd.atlas.2024-08-05+json;charset=utf-8
4+
Date: Wed, 18 Jun 2025 11:11:40 GMT
5+
Deprecation: Wed, 23 Oct 2024 00:00:00 GMT
6+
Referrer-Policy: strict-origin-when-cross-origin
7+
Server: mdbws
8+
Strict-Transport-Security: max-age=31536000; includeSubdomains;
9+
X-Content-Type-Options: nosniff
10+
X-Envoy-Upstream-Service-Time: 52
11+
X-Frame-Options: DENY
12+
X-Java-Method: ApiAtlasClusterDescriptionResource20240805::getAutoScalingMode
13+
X-Java-Version: 17.0.14+7
14+
X-Mongodb-Service-Version: gitHash=41f34161bc8088e7c5346d8c5a415d0e537c8c00; versionString=master
15+
X-Permitted-Cross-Domain-Policies: none
16+
17+
{"autoScalingMode":"INDEPENDENT_SHARD_SCALING"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
HTTP/2.0 200 OK
2+
Content-Length: 47
3+
Content-Type: application/vnd.atlas.2024-08-05+json;charset=utf-8
4+
Date: Wed, 18 Jun 2025 11:11:40 GMT
5+
Deprecation: Wed, 23 Oct 2024 00:00:00 GMT
6+
Referrer-Policy: strict-origin-when-cross-origin
7+
Server: mdbws
8+
Strict-Transport-Security: max-age=31536000; includeSubdomains;
9+
X-Content-Type-Options: nosniff
10+
X-Envoy-Upstream-Service-Time: 52
11+
X-Frame-Options: DENY
12+
X-Java-Method: ApiAtlasClusterDescriptionResource20240805::getAutoScalingMode
13+
X-Java-Version: 17.0.14+7
14+
X-Mongodb-Service-Version: gitHash=41f34161bc8088e7c5346d8c5a415d0e537c8c00; versionString=master
15+
X-Permitted-Cross-Domain-Policies: none
16+
17+
{"autoScalingMode":"INDEPENDENT_SHARD_SCALING"}

0 commit comments

Comments
 (0)