Skip to content
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
4 changes: 4 additions & 0 deletions docs/command/atlas-clusters-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ Options
- Type
- Required
- Description
* - --autoScalingMode
- string
- false
- The mode in which the cluster scales. Valid values are clusterWideScaling or independentShardScaling.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- The mode in which the cluster scales. Valid values are clusterWideScaling or independentShardScaling.
- Mode in which the cluster scales. Valid values are clusterWideScaling or independentShardScaling.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks i'll update in a follow-up since it will update all docs

* - -h, --help
-
- false
Expand Down
2 changes: 2 additions & 0 deletions internal/cli/clusters/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ var errFailedToLoadClusterFileMessage = errors.New("failed to parse JSON file")
const (
cannotUseFlexWithClusterApisErrorCode = "CANNOT_USE_FLEX_CLUSTER_IN_CLUSTER_API"
deprecateMessageSharedTier = "Deprecation note: the M2 and M5 tiers are now deprecated ('%s' was selected); when selecting M2 or M5, a FLEX tier will be created instead. For the migration guide, visit: https://dochub.mongodb.org/core/flex-migration.\n"
independentShardScalingFlag = "independentShardScaling"
clusterWideScalingFlag = "clusterWideScaling"
)

func Builder() *cobra.Command {
Expand Down
2 changes: 0 additions & 2 deletions internal/cli/clusters/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ const (
regionName = "regionName"
priority = 7
readOnlyNode = 0
independentShardScalingFlag = "independentShardScaling"
clusterWideScalingFlag = "clusterWideScaling"
)

//go:generate go tool go.uber.org/mock/mockgen -typed -destination=create_mock_test.go -package=clusters . ClusterCreator
Expand Down
11 changes: 11 additions & 0 deletions internal/cli/clusters/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (
type ClusterDescriber interface {
AtlasCluster(string, string) (*atlasClustersPinned.AdvancedClusterDescription, error)
FlexCluster(string, string) (*atlasv2.FlexClusterDescription20241113, error)
LatestAtlasCluster(string, string) (*atlasv2.ClusterDescription20240805, error)
GetClusterAutoScalingConfig(string, string) (*atlasv2.ClusterDescriptionAutoScalingModeConfiguration, error)
}

type DescribeOpts struct {
Expand All @@ -55,6 +57,15 @@ var describeTemplate = `ID NAME MDB VER STATE
`

func (opts *DescribeOpts) Run() error {
autoScalingModeConfig, err := opts.store.GetClusterAutoScalingConfig(opts.ConfigProjectID(), opts.name)
if err == nil && autoScalingModeConfig.GetAutoScalingMode() == independentShardScalingFlag {
r, err := opts.store.LatestAtlasCluster(opts.ConfigProjectID(), opts.name)
if err != nil {
return err
}
return opts.Print(r)
}

r, err := opts.store.AtlasCluster(opts.ConfigProjectID(), opts.name)
if err != nil {
return opts.RunFlexCluster(err)
Expand Down
78 changes: 78 additions & 0 deletions internal/cli/clusters/describe_mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions internal/cli/clusters/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import (
"go.uber.org/mock/gomock"
)

var clusterWideScalingConfig = &atlasv2.ClusterDescriptionAutoScalingModeConfiguration{AutoScalingMode: pointer.Get(clusterWideScalingFlag)}
var independentShardScalingConfig = &atlasv2.ClusterDescriptionAutoScalingModeConfiguration{AutoScalingMode: pointer.Get(independentShardScalingFlag)}

func TestDescribe_Run(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := NewMockClusterDescriber(ctrl)
Expand All @@ -39,6 +42,12 @@ func TestDescribe_Run(t *testing.T) {
store: mockStore,
}

mockStore.
EXPECT().
GetClusterAutoScalingConfig(describeOpts.ProjectID, describeOpts.name).
Return(clusterWideScalingConfig, nil).
Times(1)

mockStore.
EXPECT().
AtlasCluster(describeOpts.ProjectID, describeOpts.name).
Expand All @@ -62,6 +71,12 @@ func TestDescribe_RunFlexCluster(t *testing.T) {
store: mockStore,
}

mockStore.
EXPECT().
GetClusterAutoScalingConfig(describeOpts.ProjectID, describeOpts.name).
Return(clusterWideScalingConfig, nil).
Times(1)

mockStore.
EXPECT().
AtlasCluster(describeOpts.ProjectID, describeOpts.name).
Expand Down Expand Up @@ -90,6 +105,12 @@ func TestDescribe_RunFlexCluster_Error(t *testing.T) {
store: mockStore,
}

mockStore.
EXPECT().
GetClusterAutoScalingConfig(describeOpts.ProjectID, describeOpts.name).
Return(clusterWideScalingConfig, nil).
Times(1)

mockStore.
EXPECT().
AtlasCluster(describeOpts.ProjectID, describeOpts.name).
Expand All @@ -104,3 +125,30 @@ func TestDescribe_RunFlexCluster_Error(t *testing.T) {

require.Error(t, describeOpts.Run())
}

func TestDescribe_RunDedicatedCluster_IndependentShardScaling(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := NewMockClusterDescriber(ctrl)

expected := &atlasv2.ClusterDescription20240805{}

describeOpts := &DescribeOpts{
name: "test",
store: mockStore,
}

mockStore.
EXPECT().
GetClusterAutoScalingConfig(describeOpts.ProjectID, describeOpts.name).
Return(independentShardScalingConfig, nil).
Times(1)

mockStore.
EXPECT().
LatestAtlasCluster(describeOpts.ProjectID, describeOpts.name).
Return(expected, nil).
Times(1)

require.NoError(t, describeOpts.Run())
test.VerifyOutputTemplate(t, describeTemplate, expected)
}
15 changes: 13 additions & 2 deletions internal/cli/clusters/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ import (
type ClusterLister interface {
ProjectClusters(string, *store.ListOptions) (*atlasClustersPinned.PaginatedAdvancedClusterDescription, error)
ListFlexClusters(*atlasv2.ListFlexClustersApiParams) (*atlasv2.PaginatedFlexClusters20241113, error)
LatestProjectClusters(string, *store.ListOptions) (*atlasv2.PaginatedClusterDescription20240805, error)
}

type ListOpts struct {
cli.ProjectOpts
cli.OutputOpts
cli.ListOpts
tier string
store ClusterLister
tier string
autoScalingMode string
store ClusterLister
}

func (opts *ListOpts) initStore(ctx context.Context) func() error {
Expand All @@ -66,6 +68,14 @@ func (opts *ListOpts) Run() error {

func (opts *ListOpts) RunDedicatedCluster() error {
listOpts := opts.NewAtlasListOptions()
if opts.autoScalingMode == independentShardScalingFlag {
r, err := opts.store.LatestProjectClusters(opts.ConfigProjectID(), listOpts)
if err != nil {
return err
}
return opts.Print(r)
}

r, err := opts.store.ProjectClusters(opts.ConfigProjectID(), listOpts)
if err != nil {
return err
Expand Down Expand Up @@ -121,6 +131,7 @@ func ListBuilder() *cobra.Command {
}

cmd.Flags().StringVar(&opts.tier, flag.Tier, "", usage.Tier)
cmd.Flags().StringVar(&opts.autoScalingMode, flag.AutoScalingMode, "", usage.AutoScalingMode)
opts.AddListOptsFlags(cmd)

opts.AddProjectOptsFlags(cmd)
Expand Down
39 changes: 39 additions & 0 deletions internal/cli/clusters/list_mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions internal/cli/clusters/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,33 @@ func TestList_RunFlexCluster(t *testing.T) {
require.NoError(t, listOpts.Run())
}

func TestList_RunDedicatedCluster_IndependentShardScaling(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := NewMockClusterLister(ctrl)

expected := &atlasv2.PaginatedClusterDescription20240805{
Results: &[]atlasv2.ClusterDescription20240805{
{
Name: pointer.Get("test"),
Id: pointer.Get("123"),
},
},
}

listOpts := &ListOpts{
store: mockStore,
autoScalingMode: independentShardScalingFlag,
}

mockStore.
EXPECT().
LatestProjectClusters(listOpts.ProjectID, listOpts.NewAtlasListOptions()).
Return(expected, nil).
Times(1)

require.NoError(t, listOpts.Run())
}

func TestListTemplate(t *testing.T) {
test.VerifyOutputTemplate(t, listTemplate, atlasClustersPinned.PaginatedAdvancedClusterDescription{})
}
8 changes: 4 additions & 4 deletions internal/cli/clusters/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ func (opts *WatchOpts) flexClusterWatcher(ctx context.Context) func() (any, bool

func (opts *WatchOpts) watcher(ctx context.Context) func() (any, bool, error) {
return func() (any, bool, error) {
result, err := opts.store.AtlasCluster(opts.ConfigProjectID(), opts.name)
result, err := opts.store.LatestAtlasCluster(opts.ConfigProjectID(), opts.name)
if err != nil {
var atlasClustersPinnedErr *atlasClustersPinned.GenericOpenAPIError
var atlasv2Err *atlasv2.GenericOpenAPIError

if errors.As(err, &atlasClustersPinnedErr) {
if *atlasClustersPinnedErr.Model().Error == http.StatusUnauthorized {
if errors.As(err, &atlasv2Err) {
if atlasv2Err.Model().Error == http.StatusUnauthorized {
// Refresh the access token
// Note: this only updates the config, so we have to re-initialize the store
if err := opts.RefreshAccessToken(ctx); err != nil {
Expand Down
5 changes: 2 additions & 3 deletions internal/cli/clusters/watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/pointer"
"github.com/stretchr/testify/require"
atlasClustersPinned "go.mongodb.org/atlas-sdk/v20240530005/admin"
atlasv2 "go.mongodb.org/atlas-sdk/v20250312003/admin"
"go.uber.org/mock/gomock"
)
Expand All @@ -30,7 +29,7 @@ func TestWatch_Run(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := NewMockClusterDescriber(ctrl)

expected := &atlasClustersPinned.AdvancedClusterDescription{StateName: pointer.Get("IDLE")}
expected := &atlasv2.ClusterDescription20240805{StateName: pointer.Get("IDLE")}

opts := &WatchOpts{
name: "test",
Expand All @@ -40,7 +39,7 @@ func TestWatch_Run(t *testing.T) {

mockStore.
EXPECT().
AtlasCluster(opts.ProjectID, opts.name).
LatestAtlasCluster(opts.ProjectID, opts.name).
Return(expected, nil).
Times(1)

Expand Down
Loading