@@ -115,27 +115,7 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment-
115115
116116 doDeploymentStatusChecks := func () {
117117 By ("Checking observed Deployment state" , func () {
118- deploymentName := createdDeployment .GetDeploymentName ()
119- Expect (deploymentName ).ToNot (BeEmpty ())
120-
121- atlasDeployment , _ , err := atlasClient .ClustersApi .
122- GetCluster (context .Background (), createdProject .Status .ID , deploymentName ).
123- Execute ()
124- Expect (err ).ToNot (HaveOccurred ())
125-
126- Expect (createdDeployment .Status .ConnectionStrings ).NotTo (BeNil ())
127- Expect (createdDeployment .Status .ConnectionStrings .Standard ).To (Equal (atlasDeployment .ConnectionStrings .GetStandard ()))
128- Expect (createdDeployment .Status .ConnectionStrings .StandardSrv ).To (Equal (atlasDeployment .ConnectionStrings .GetStandardSrv ()))
129- Expect (createdDeployment .Status .MongoDBVersion ).To (Equal (atlasDeployment .GetMongoDBVersion ()))
130- Expect (createdDeployment .Status .StateName ).To (Equal ("IDLE" ))
131- Expect (createdDeployment .Status .Conditions ).To (HaveLen (4 ))
132- Expect (createdDeployment .Status .Conditions ).To (ConsistOf (conditions .MatchConditions (
133- api .TrueCondition (api .DeploymentReadyType ),
134- api .TrueCondition (api .ReadyType ),
135- api .TrueCondition (api .ValidationSucceeded ),
136- api .TrueCondition (api .ResourceVersionStatus ),
137- )))
138- Expect (createdDeployment .Status .ObservedGeneration ).To (Equal (createdDeployment .Generation ))
118+ doDeploymentStatusChecksFor (createdProject , createdDeployment )
139119 })
140120 }
141121
@@ -311,59 +291,6 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment-
311291 })
312292 })
313293
314- Describe ("Create deployment & change ReplicationSpecs" , Label ("focus-AtlasDeploymentSharding" ), func () {
315- It ("Should Succeed" , func (ctx context.Context ) {
316- createdDeployment = akov2 .DefaultAWSDeployment (namespace .Name , createdProject .Name ).
317- WithInstanceSize ("M30" )
318-
319- // Atlas will add some defaults in case the Atlas Operator doesn't set them
320- replicationSpecsCheck := func (deployment * admin.ClusterDescription20240805 ) {
321- Expect (deployment .GetReplicationSpecs ()[0 ].GetId ()).NotTo (BeEmpty ())
322- Expect (deployment .GetReplicationSpecs ()[0 ].GetZoneName ()).To (Equal ("Zone 1" ))
323- Expect (deployment .GetReplicationSpecs ()[0 ].GetRegionConfigs ()).To (HaveLen (1 ))
324- Expect (deployment .GetReplicationSpecs ()[0 ].GetRegionConfigs ()[0 ]).NotTo (BeNil ())
325- }
326-
327- By (fmt .Sprintf ("Creating the Deployment %s" , kube .ObjectKeyFromObject (createdDeployment )), func () {
328- performCreate (createdDeployment , 30 * time .Minute )
329-
330- doDeploymentStatusChecks ()
331-
332- singleNumShard := func (deployment * admin.ClusterDescription20240805 ) {
333- Expect (len (deployment .GetReplicationSpecs ())).To (Equal (1 ))
334- }
335- checkAtlasState (replicationSpecsCheck , singleNumShard )
336- })
337-
338- By ("Upgrade to sharded" , func () {
339- createdDeployment = performUpdate (ctx , 40 * time .Minute , client .ObjectKeyFromObject (createdDeployment ), func (deployment * akov2.AtlasDeployment ) {
340- deployment .Spec .DeploymentSpec .ClusterType = "SHARDED"
341- })
342- doDeploymentStatusChecks ()
343-
344- singleNumShard := func (deployment * admin.ClusterDescription20240805 ) {
345- Expect (len (deployment .GetReplicationSpecs ())).To (Equal (1 ))
346- }
347- // ReplicationSpecs has the same defaults but the number of shards has changed
348- checkAtlasState (replicationSpecsCheck , singleNumShard )
349- })
350-
351- By ("Increase number of shards" , func () {
352- numShards := 2
353- createdDeployment = performUpdate (ctx , 40 * time .Minute , client .ObjectKeyFromObject (createdDeployment ), func (deployment * akov2.AtlasDeployment ) {
354- deployment .Spec .DeploymentSpec .ReplicationSpecs [0 ].NumShards = numShards
355- })
356- doDeploymentStatusChecks ()
357-
358- twoNumShard := func (deployment * admin.ClusterDescription20240805 ) {
359- Expect (len (deployment .GetReplicationSpecs ())).To (Equal (numShards ))
360- }
361- // ReplicationSpecs has the same defaults but the number of shards has changed
362- checkAtlasState (replicationSpecsCheck , twoNumShard )
363- })
364- })
365- })
366-
367294 Describe ("Create deployment & increase InstanceSize" , func () {
368295 It ("Should Succeed" , func (ctx context.Context ) {
369296 expectedDeployment := akov2 .DefaultAWSDeployment (namespace .Name , createdProject .Name )
@@ -1501,6 +1428,156 @@ var _ = Describe("AtlasDeployment", Ordered, Label("int", "AtlasDeployment", "de
15011428 })
15021429})
15031430
1431+ var _ = Describe ("AtlasDeploymentSharding" , Label ("int" , "AtlasDeploymentSharding" , "deployment-non-backups" ), func () {
1432+ var (
1433+ connectionSecret * corev1.Secret
1434+ createdProject * akov2.AtlasProject
1435+ createdDeployment * akov2.AtlasDeployment
1436+ manualDeletion bool
1437+ )
1438+
1439+ BeforeEach (func () {
1440+ prepareControllers (false )
1441+
1442+ deployment .NewAtlasDeployments (atlasClient .ClustersApi , atlasClient .ServerlessInstancesApi , atlasClient .GlobalClustersApi , atlasClient .FlexClustersApi , false )
1443+ createdDeployment = & akov2.AtlasDeployment {}
1444+
1445+ manualDeletion = false
1446+
1447+ connectionSecret = createConnectionSecret ()
1448+ createdProject = createProject (connectionSecret )
1449+ })
1450+
1451+ AfterEach (func () {
1452+ if DeploymentDevMode {
1453+ return
1454+ }
1455+ if manualDeletion && createdProject != nil {
1456+ By ("Deleting the deployment in Atlas manually" , func () {
1457+ // We need to remove the deployment in Atlas to let project get removed
1458+ _ , err := atlasClient .ClustersApi .
1459+ DeleteCluster (context .Background (), createdProject .ID (), createdDeployment .GetDeploymentName ()).
1460+ Execute ()
1461+ Expect (err ).NotTo (HaveOccurred ())
1462+ Eventually (checkAtlasDeploymentRemoved (createdProject .Status .ID , createdDeployment .GetDeploymentName ()), 600 , interval ).Should (BeTrue ())
1463+ createdDeployment = nil
1464+ })
1465+ }
1466+ if createdProject != nil && createdProject .Status .ID != "" {
1467+ if createdDeployment != nil {
1468+ deleteDeploymentFromKubernetes (createdProject , createdDeployment )
1469+ }
1470+
1471+ deleteProjectFromKubernetes (createdProject )
1472+ }
1473+ removeControllersAndNamespace ()
1474+ })
1475+
1476+ doDeploymentStatusChecks := func () {
1477+ By ("Checking observed Deployment state" , func () {
1478+ doDeploymentStatusChecksFor (createdProject , createdDeployment )
1479+ })
1480+ }
1481+
1482+ checkAtlasState := func (additionalChecks ... func (c * admin.ClusterDescription20240805 )) {
1483+ By ("Verifying Deployment state in Atlas" , func () {
1484+ atlasDeploymentAsAtlas , _ , err := atlasClient .ClustersApi .
1485+ GetCluster (context .Background (), createdProject .Status .ID , createdDeployment .GetDeploymentName ()).
1486+ Execute ()
1487+ Expect (err ).ToNot (HaveOccurred ())
1488+
1489+ for _ , check := range additionalChecks {
1490+ check (atlasDeploymentAsAtlas )
1491+ }
1492+ })
1493+ }
1494+
1495+ performCreate := func (deployment * akov2.AtlasDeployment , timeout time.Duration ) {
1496+ Expect (k8sClient .Create (context .Background (), deployment )).To (Succeed ())
1497+
1498+ Eventually (func (g Gomega ) bool {
1499+ return resources .CheckCondition (k8sClient , createdDeployment , api .TrueCondition (api .ReadyType ), validateDeploymentCreatingFunc (g ))
1500+ }).WithTimeout (timeout ).WithPolling (interval ).Should (BeTrue ())
1501+ }
1502+
1503+ Describe ("Create deployment & change ReplicationSpecs" , func () {
1504+ It ("Should Succeed" , func (ctx context.Context ) {
1505+ createdDeployment = akov2 .DefaultAWSDeployment (namespace .Name , createdProject .Name ).
1506+ WithInstanceSize ("M30" )
1507+
1508+ // Atlas will add some defaults in case the Atlas Operator doesn't set them
1509+ replicationSpecsCheck := func (deployment * admin.ClusterDescription20240805 ) {
1510+ Expect (deployment .GetReplicationSpecs ()[0 ].GetId ()).NotTo (BeEmpty ())
1511+ Expect (deployment .GetReplicationSpecs ()[0 ].GetZoneName ()).To (Equal ("Zone 1" ))
1512+ Expect (deployment .GetReplicationSpecs ()[0 ].GetRegionConfigs ()).To (HaveLen (1 ))
1513+ Expect (deployment .GetReplicationSpecs ()[0 ].GetRegionConfigs ()[0 ]).NotTo (BeNil ())
1514+ }
1515+
1516+ By (fmt .Sprintf ("Creating the Deployment %s" , kube .ObjectKeyFromObject (createdDeployment )), func () {
1517+ performCreate (createdDeployment , 30 * time .Minute )
1518+
1519+ doDeploymentStatusChecks ()
1520+
1521+ singleNumShard := func (deployment * admin.ClusterDescription20240805 ) {
1522+ Expect (len (deployment .GetReplicationSpecs ())).To (Equal (1 ))
1523+ }
1524+ checkAtlasState (replicationSpecsCheck , singleNumShard )
1525+ })
1526+
1527+ By ("Upgrade to sharded" , func () {
1528+ createdDeployment = performUpdate (ctx , 40 * time .Minute , client .ObjectKeyFromObject (createdDeployment ), func (deployment * akov2.AtlasDeployment ) {
1529+ deployment .Spec .DeploymentSpec .ClusterType = "SHARDED"
1530+ })
1531+ doDeploymentStatusChecks ()
1532+
1533+ singleNumShard := func (deployment * admin.ClusterDescription20240805 ) {
1534+ Expect (len (deployment .GetReplicationSpecs ())).To (Equal (1 ))
1535+ }
1536+ // ReplicationSpecs has the same defaults but the number of shards has changed
1537+ checkAtlasState (replicationSpecsCheck , singleNumShard )
1538+ })
1539+
1540+ By ("Increase number of shards" , func () {
1541+ numShards := 2
1542+ createdDeployment = performUpdate (ctx , 40 * time .Minute , client .ObjectKeyFromObject (createdDeployment ), func (deployment * akov2.AtlasDeployment ) {
1543+ deployment .Spec .DeploymentSpec .ReplicationSpecs [0 ].NumShards = numShards
1544+ })
1545+ doDeploymentStatusChecks ()
1546+
1547+ twoNumShard := func (deployment * admin.ClusterDescription20240805 ) {
1548+ Expect (len (deployment .GetReplicationSpecs ())).To (Equal (numShards ))
1549+ }
1550+ // ReplicationSpecs has the same defaults but the number of shards has changed
1551+ checkAtlasState (replicationSpecsCheck , twoNumShard )
1552+ })
1553+ })
1554+ })
1555+ })
1556+
1557+ func doDeploymentStatusChecksFor (createdProject * akov2.AtlasProject , createdDeployment * akov2.AtlasDeployment ) {
1558+ deploymentName := createdDeployment .GetDeploymentName ()
1559+ Expect (deploymentName ).ToNot (BeEmpty ())
1560+
1561+ atlasDeployment , _ , err := atlasClient .ClustersApi .
1562+ GetCluster (context .Background (), createdProject .Status .ID , deploymentName ).
1563+ Execute ()
1564+ Expect (err ).ToNot (HaveOccurred ())
1565+
1566+ Expect (createdDeployment .Status .ConnectionStrings ).NotTo (BeNil ())
1567+ Expect (createdDeployment .Status .ConnectionStrings .Standard ).To (Equal (atlasDeployment .ConnectionStrings .GetStandard ()))
1568+ Expect (createdDeployment .Status .ConnectionStrings .StandardSrv ).To (Equal (atlasDeployment .ConnectionStrings .GetStandardSrv ()))
1569+ Expect (createdDeployment .Status .MongoDBVersion ).To (Equal (atlasDeployment .GetMongoDBVersion ()))
1570+ Expect (createdDeployment .Status .StateName ).To (Equal ("IDLE" ))
1571+ Expect (createdDeployment .Status .Conditions ).To (HaveLen (4 ))
1572+ Expect (createdDeployment .Status .Conditions ).To (ConsistOf (conditions .MatchConditions (
1573+ api .TrueCondition (api .DeploymentReadyType ),
1574+ api .TrueCondition (api .ReadyType ),
1575+ api .TrueCondition (api .ValidationSucceeded ),
1576+ api .TrueCondition (api .ResourceVersionStatus ),
1577+ )))
1578+ Expect (createdDeployment .Status .ObservedGeneration ).To (Equal (createdDeployment .Generation ))
1579+ }
1580+
15041581func validateDeploymentCreatingFunc (g Gomega ) func (a api.AtlasCustomResource ) {
15051582 startedCreation := false
15061583 return func (a api.AtlasCustomResource ) {
0 commit comments