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

CLOUDP-167782: Clusters Migration #1967

Merged
merged 37 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7316c5d
CLOUDP-167782: Clusters store Migration
swattyT May 28, 2023
0b0e1f8
e2e fixes
swattyT May 28, 2023
ce3cfe6
fix unit tests
matt-condon May 30, 2023
30a4f3c
fix conflicts
swattyT May 30, 2023
bf407df
docs generate
swattyT May 30, 2023
3b64178
tests fix
swattyT May 30, 2023
d74f622
fix unit test
swattyT May 30, 2023
a9495b5
e2e fix
swattyT May 30, 2023
a09409d
e2e fix
swattyT May 30, 2023
b32f3c8
e2e fix
swattyT May 30, 2023
d2244da
CLOUDP-167782: Clusters store Migration
swattyT May 28, 2023
963d4a1
e2e fixes
swattyT May 28, 2023
6c5cd10
fix unit tests
matt-condon May 30, 2023
99e993f
CLOUDP-172196: migrate ListCloudProviderRegions (#1950)
matt-condon May 30, 2023
b175ffc
CLOUDP-167782: Clusters store Migration
swattyT May 28, 2023
a32d164
e2e fixes
swattyT May 28, 2023
e0ce5cb
docs generate
swattyT May 30, 2023
334a064
tests fix
swattyT May 30, 2023
2e24a85
fix unit test
swattyT May 30, 2023
b551b02
e2e fix
swattyT May 30, 2023
e7e2f73
e2e fix
swattyT May 30, 2023
453995b
e2e fix
swattyT May 30, 2023
d6b32a4
fix linting
matt-condon May 31, 2023
8b6e2cf
conflix resolution
swattyT May 31, 2023
74f6db6
conflict
swattyT May 31, 2023
45568d6
error fix
swattyT May 31, 2023
0833df5
fix lint errors
swattyT May 31, 2023
19a9791
lint fix
swattyT May 31, 2023
5b0ac7a
quickstart fix
swattyT Jun 1, 2023
63d0956
conflict resolution
swattyT Jun 1, 2023
364c691
fix regionCongif
swattyT Jun 1, 2023
69977be
remove AWSConfig references
swattyT Jun 1, 2023
251e71d
error fix
swattyT Jun 1, 2023
9f5f66a
Merge branch 'master' into temp/CLOUDP-167782
swattyT Jun 2, 2023
72a35ff
update branch
swattyT Jun 2, 2023
cba1251
fix lint
swattyT Jun 2, 2023
dfc66cd
remove now redundant conversion
matt-condon Jun 2, 2023
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
2 changes: 1 addition & 1 deletion docs/atlascli/command/atlas-clusters-sampleData-load.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@ If the command succeeds, the CLI returns output similar to the following sample.

.. code-block::

Sample Data Job <ID> created.
Sample Data Job <Id> created.


Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@ If the command succeeds, the CLI returns output similar to the following sample.

.. code-block::

Sample Data Job <ID> created.
Sample Data Job <Id> created.


5 changes: 2 additions & 3 deletions internal/cli/atlas/clusters/availableregions/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/mongodb/mongodb-atlas-cli/internal/cli/require"
"github.com/mongodb/mongodb-atlas-cli/internal/config"
"github.com/mongodb/mongodb-atlas-cli/internal/flag"
"github.com/mongodb/mongodb-atlas-cli/internal/pointer"
"github.com/mongodb/mongodb-atlas-cli/internal/store"
"github.com/mongodb/mongodb-atlas-cli/internal/usage"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -50,9 +49,9 @@ var listTemplate = `PROVIDER INSTANCE SIZE REGIONS{{range .Results}}{{ $provider

func (opts *ListOpts) Run() error {
// Set provider if existent
var provider *[]string
var provider []string
if opts.provider != "" {
provider = pointer.Get([]string{opts.provider})
provider = []string{opts.provider}
}

r, err := opts.store.CloudProviderRegions(opts.ConfigProjectID(), opts.tier, provider)
Expand Down
11 changes: 5 additions & 6 deletions internal/cli/atlas/clusters/availableregions/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@ import (
"github.com/golang/mock/gomock"
"github.com/mongodb/mongodb-atlas-cli/internal/flag"
"github.com/mongodb/mongodb-atlas-cli/internal/mocks"
"github.com/mongodb/mongodb-atlas-cli/internal/pointer"
"github.com/mongodb/mongodb-atlas-cli/internal/test"
atlasv2 "go.mongodb.org/atlas-sdk/admin"
"go.mongodb.org/atlas-sdk/admin"
)

func TestList_Run_NoFlags(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := mocks.NewMockCloudProviderRegionsLister(ctrl)

var expected *atlasv2.PaginatedApiAtlasProviderRegions
var empty *[]string
var expected *admin.PaginatedApiAtlasProviderRegions
var empty []string

listOpts := &ListOpts{
store: mockStore,
Expand All @@ -53,7 +52,7 @@ func TestList_Run(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := mocks.NewMockCloudProviderRegionsLister(ctrl)

var expected *atlasv2.PaginatedApiAtlasProviderRegions
var expected *admin.PaginatedApiAtlasProviderRegions

listOpts := &ListOpts{
store: mockStore,
Expand All @@ -63,7 +62,7 @@ func TestList_Run(t *testing.T) {

mockStore.
EXPECT().
CloudProviderRegions(listOpts.ProjectID, listOpts.tier, pointer.Get([]string{listOpts.provider})).
CloudProviderRegions(listOpts.ProjectID, listOpts.tier, []string{listOpts.provider}).
Return(expected, nil).
Times(1)

Expand Down
60 changes: 39 additions & 21 deletions internal/cli/atlas/clusters/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import (
"github.com/mongodb/mongodb-atlas-cli/internal/cli/atlas/clusters/sampledata"
"github.com/mongodb/mongodb-atlas-cli/internal/cli/atlas/search"
"github.com/mongodb/mongodb-atlas-cli/internal/config"
"github.com/mongodb/mongodb-atlas-cli/internal/pointer"
"github.com/spf13/cobra"
atlasv2 "go.mongodb.org/atlas-sdk/admin"
atlas "go.mongodb.org/atlas/mongodbatlas"
)

Expand Down Expand Up @@ -97,56 +99,59 @@ func Builder() *cobra.Command {
return cmd
}

func NewCLILabel() atlas.Label {
func NewCLILabel() atlasv2.NDSLabel {
labelValue := atlasCLILabelValue
if config.ToolName == config.MongoCLI {
labelValue = mongoCLILabelValue
}

return atlas.Label{
Key: labelKey,
Value: labelValue,
return atlasv2.NDSLabel{
Key: pointer.Get(labelKey),
Value: pointer.Get(labelValue),
}
}

func AddLabel(out *atlas.AdvancedCluster, l atlas.Label) {
func AddLabel(out *atlasv2.ClusterDescriptionV15, l atlasv2.NDSLabel) {
if LabelExists(out.Labels, l) {
return
}

out.Labels = append(out.Labels, l)
}

func LabelExists(labels []atlas.Label, l atlas.Label) bool {
func LabelExists(labels []atlasv2.NDSLabel, l atlasv2.NDSLabel) bool {
for _, v := range labels {
if v.Key == l.Key && v.Value == l.Value {
if v.GetKey() == l.GetKey() && v.GetValue() == l.GetValue() {
return true
}
}
return false
}

func RemoveReadOnlyAttributes(out *atlas.AdvancedCluster) {
out.ID = ""
out.CreateDate = ""
out.StateName = ""
out.MongoDBVersion = ""
func RemoveReadOnlyAttributes(out *atlasv2.ClusterDescriptionV15) {
Copy link
Member

Choose a reason for hiding this comment

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

Do you think that this can be a method that we would need to document or include in the SDK?
If yes let's create jira to cover it.

out.Id = nil
out.CreateDate = nil
out.StateName = nil
out.MongoDBVersion = nil
out.ConnectionStrings = nil
isTenant := false
for _, spec := range out.ReplicationSpecs {
spec.ID = ""
for _, c := range spec.RegionConfigs {
if c.ProviderName == tenant {

for i, spec := range out.ReplicationSpecs {
out.ReplicationSpecs[i].Id = nil
for j, config := range spec.RegionConfigs {
out.ReplicationSpecs[i].RegionConfigs[j].ProviderName = config.ProviderName
if config.GetProviderName() == tenant {
isTenant = true
break
}
}
}

if isTenant {
out.BiConnector = nil
out.EncryptionAtRestProvider = ""
out.EncryptionAtRestProvider = nil
out.DiskSizeGB = nil
out.MongoDBMajorVersion = ""
out.MongoDBMajorVersion = nil
out.PitEnabled = nil
out.BackupEnabled = nil
}
Expand All @@ -171,10 +176,23 @@ func RemoveReadOnlyAttributesSharedCluster(out *atlas.Cluster) {
}
}

func AddLabelSharedCluster(out *atlas.Cluster, l atlas.Label) {
if LabelExists(out.Labels, l) {
func SharedLabelExists(labels []atlas.Label, l atlasv2.NDSLabel) bool {
for _, v := range labels {
if v.Key == l.GetKey() && v.Value == l.GetValue() {
return true
}
}
return false
}

func AddLabelSharedCluster(out *atlas.Cluster, l atlasv2.NDSLabel) {
if SharedLabelExists(out.Labels, l) {
return
}

out.Labels = append(out.Labels, l)
l2 := atlas.Label{
Key: l.GetKey(),
Value: l.GetValue(),
}
out.Labels = append(out.Labels, l2)
}
Loading