Skip to content

CLOUDP-62037: Add Labels when Creating/Updating cluster with mongocli Atlas #171

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

Merged
merged 20 commits into from
May 14, 2020

Conversation

andreaangiolillo
Copy link
Collaborator

@andreaangiolillo andreaangiolillo commented May 14, 2020

Proposed changes

Jira ticket: CLOUDP-62037

Checklist

  • I have signed the MongoDB CLA
  • I have added tests that prove my fix is effective or that my feature works
  • I have added any necessary documentation (if appropriate)
  • I have run make fmt and formatted my code
  • I have tested my code using cloud-dev

Further comments

Create Cluster:

./bin/mongocli atlas clusters create myCluster24 --provider AWS --region US_EAST_1 --members 3 --tier M10 --mdbVersion 4.2 --diskSizeGB 10
{
	"autoScaling": {
		"diskGBEnabled": true
	},
	"backupEnabled": false,
	"biConnector": {
		"enabled": false,
		"readPreference": "secondary"
	},
	"clusterType": "REPLICASET",
	"diskSizeGB": 10,
	"encryptionAtRestProvider": "NONE",
	"labels": [
		{
			"key": "Infrastructure Tool",
			"value": "mongoCLI"
		}
	],
	"id": "5ebd53141f8fbb684767ebaf",
	"groupId": "5e4e593f70dfbf1010295836",
	"mongoDBVersion": "4.2.6",
	"mongoDBMajorVersion": "4.2",
	"mongoURIUpdated": "2020-05-14T14:17:56Z",
	"name": "myCluster24",
	"numShards": 1,
	"paused": false,
	"pitEnabled": false,
	"providerBackupEnabled": false,
	"providerSettings": {
		"diskIOPS": 100,
		"encryptEBSVolume": true,
		"instanceSizeName": "M10",
		"providerName": "AWS",
		"regionName": "US_EAST_1",
		"volumeType": "STANDARD"
	},
	"replicationFactor": 3,
	"replicationSpec": {
		"US_EAST_1": {
			"analyticsNodes": 0,
			"electableNodes": 3,
			"priority": 7,
			"readOnlyNodes": 0
		}
	},
	"replicationSpecs": [
		{
			"id": "5ebd53141f8fbb684767ebaa",
			"numShards": 1,
			"zoneName": "Zone 1",
			"regionsConfig": {
				"US_EAST_1": {
					"analyticsNodes": 0,
					"electableNodes": 3,
					"priority": 7,
					"readOnlyNodes": 0
				}
			}
		}
	],
	"stateName": "CREATING",
	"connectionStrings": {}
}

Update Cluster:

./bin/mongocli atlas clusters update myCluster01 --diskSizeGB 20
{
	"autoScaling": {
		"diskGBEnabled": true
	},
	"backupEnabled": false,
	"biConnector": {
		"enabled": false,
		"readPreference": "secondary"
	},
	"clusterType": "REPLICASET",
	"diskSizeGB": 20,
	"encryptionAtRestProvider": "NONE",
	"labels": [
		{
			"key": "KeyUpdated",
			"value": "ValueUpdated"
		},
		{
			"key": "NewKey1",
			"value": "newValue1"
		},
		{
			"key": "Infrastructure Tool",
			"value": "mongoCLI"
		}
	],
	"id": "5ebd3d99669f2621a51e830b",
	"groupId": "5e4e593f70dfbf1010295836",
	"mongoDBVersion": "4.2.6",
	"mongoDBMajorVersion": "4.2",
	"mongoURI": "mongodb://mycluster01-shard-00-00.ajlj3.mongodb-dev.net:27017,mycluster01-shard-00-01.ajlj3.mongodb-dev.net:27017,mycluster01-shard-00-02.ajlj3.mongodb-dev.net:27017",
	"mongoURIUpdated": "2020-05-14T12:55:26Z",
	"mongoURIWithOptions": "mongodb://mycluster01-shard-00-00.ajlj3.mongodb-dev.net:27017,mycluster01-shard-00-01.ajlj3.mongodb-dev.net:27017,mycluster01-shard-00-02.ajlj3.mongodb-dev.net:27017/?ssl=true\u0026authSource=admin\u0026replicaSet=atlas-2ejb43-shard-0",
	"name": "myCluster01",
	"numShards": 1,
	"paused": false,
	"pitEnabled": false,
	"providerBackupEnabled": false,
	"providerSettings": {
		"diskIOPS": 100,
		"encryptEBSVolume": true,
		"instanceSizeName": "M10",
		"providerName": "AWS",
		"regionName": "US_EAST_1",
		"volumeType": "STANDARD"
	},
	"replicationFactor": 3,
	"replicationSpec": {
		"US_EAST_1": {
			"analyticsNodes": 0,
			"electableNodes": 3,
			"priority": 7,
			"readOnlyNodes": 0
		}
	},
	"replicationSpecs": [
		{
			"id": "5ebd3d99669f2621a51e8306",
			"numShards": 1,
			"zoneName": "Zone 1",
			"regionsConfig": {
				"US_EAST_1": {
					"analyticsNodes": 0,
					"electableNodes": 3,
					"priority": 7,
					"readOnlyNodes": 0
				}
			}
		}
	],
	"srvAddress": "mongodb+srv://mycluster01.ajlj3.mongodb-dev.net",
	"stateName": "UPDATING",
	"connectionStrings": {
		"standard": "mongodb://mycluster01-shard-00-00.ajlj3.mongodb-dev.net:27017,mycluster01-shard-00-01.ajlj3.mongodb-dev.net:27017,mycluster01-shard-00-02.ajlj3.mongodb-dev.net:27017/?ssl=true\u0026authSource=admin\u0026replicaSet=atlas-2ejb43-shard-0",
		"standardSrv": "mongodb+srv://mycluster01.ajlj3.mongodb-dev.net"
	}
}

@andreaangiolillo andreaangiolillo requested a review from gssbzn May 14, 2020 13:05
Copy link
Collaborator

@gssbzn gssbzn left a comment

Choose a reason for hiding this comment

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

Sorry if the task was not clear but the requirement is not to expose labels as a flag but to always add a label like this but instead of MongoDB Atlas Terraform Provider we'll use "MongoDB CLI

couple of gotchas with this is that we should not override existing labels, this may include the fact of someone already using the Infrastructure Tool key already

@andreaangiolillo andreaangiolillo requested a review from gssbzn May 14, 2020 14:23
Copy link
Collaborator

@gssbzn gssbzn left a comment

Choose a reason for hiding this comment

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

Thanks for doing the changes, this looks almost done, a couple of nits here but nothing too major

@andreaangiolillo andreaangiolillo requested a review from gssbzn May 14, 2020 15:01
Copy link
Collaborator

@gssbzn gssbzn left a comment

Choose a reason for hiding this comment

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

one small nit but this should get us to ready to merge


cluster.GroupID = opts.ProjectID()
return cluster, nil
}

func (opts *atlasClustersCreateOpts) updateLabels(out *atlas.Cluster) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] this method doesn't use opts in its body, so you could make it a generic function like

Suggested change
func (opts *atlasClustersCreateOpts) updateLabels(out *atlas.Cluster) {
func updateLabels(out *atlas.Cluster) {

This also let's you reuse the same function in both create an update

Copy link
Collaborator

@gssbzn gssbzn left a comment

Choose a reason for hiding this comment

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

LGTM thanks for doing this

@andreaangiolillo andreaangiolillo requested a review from gssbzn May 14, 2020 15:12
@andreaangiolillo andreaangiolillo merged commit 8ad942e into master May 14, 2020
@andreaangiolillo andreaangiolillo deleted the CLOUDP-62037 branch May 14, 2020 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants