Skip to content

Commit a5d89a2

Browse files
authored
CLOUDP-81143: Add failure scenarios to Cluster int tests (#98)
1 parent fedfa1f commit a5d89a2

File tree

6 files changed

+110
-9
lines changed

6 files changed

+110
-9
lines changed

config/crd/bases/atlas.mongodb.com_atlasprojects.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ spec:
124124
this field is updated by the Atlas Operator only after specification
125125
changes
126126
items:
127-
description: TODO solve circular dependency (move ProjectIPAccessList
128-
to subpackage?) Copy of mdbv1.ProjectIPAccessList
127+
description: ProjectIPAccessList is a copy of mdbv1.ProjectIPAccessList
129128
properties:
130129
awsSecurityGroup:
131130
description: Unique identifier of AWS security group in this

pkg/controller/atlascluster/atlascluster_controller.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,14 @@ import (
2929
"sigs.k8s.io/controller-runtime/pkg/event"
3030
"sigs.k8s.io/controller-runtime/pkg/source"
3131

32-
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/watch"
33-
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/workflow"
34-
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/kube"
35-
3632
mdbv1 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1"
3733
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/status"
3834
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/atlas"
3935
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/customresource"
4036
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/statushandler"
37+
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/watch"
38+
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/workflow"
39+
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/kube"
4140
)
4241

4342
// AtlasClusterReconciler reconciles an AtlasCluster object

pkg/controller/atlascluster/cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (r *AtlasClusterReconciler) ensureClusterState(log *zap.SugaredLogger, conn
7474

7575
c, _, err = client.Clusters.Update(ctx, project.Status.ID, cluster.Spec.Name, spec)
7676
if err != nil {
77-
return c, workflow.Terminate(workflow.ClusterNotCreatedInAtlas, err.Error())
77+
return c, workflow.Terminate(workflow.ClusterNotUpdatedInAtlas, err.Error())
7878
}
7979

8080
return c, workflow.InProgress(workflow.ClusterUpdating, "cluster is updating")

pkg/controller/workflow/reason.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const (
2020
// Atlas Cluster reasons
2121
const (
2222
ClusterNotCreatedInAtlas ConditionReason = "ClusterNotCreatedInAtlas"
23+
ClusterNotUpdatedInAtlas ConditionReason = "ClusterNotUpdatedInAtlas"
2324
ClusterCreating ConditionReason = "ClusterCreating"
2425
ClusterUpdating ConditionReason = "ClusterUpdating"
2526
)

pkg/util/testutil/conditions.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ func (m *conditionMatcher) Match(actual interface{}) (success bool, err error) {
4141
if m.ExpectedCondition.Type != "" && c.Type != m.ExpectedCondition.Type {
4242
return false, nil
4343
}
44-
// Add regexp when necessary
4544
if m.ExpectedCondition.Message != "" {
4645
gomega.Expect(c.Message).To(gomega.MatchRegexp(m.ExpectedCondition.Message))
4746
}

test/int/cluster_test.go

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,43 @@ var _ = Describe("AtlasCluster", func() {
122122
}
123123

124124
Describe("Create/Update the cluster", func() {
125+
It("Should fail, then be fixed", func() {
126+
expectedCluster := testAtlasCluster(namespace.Name, "test-cluster", createdProject.Name)
127+
expectedCluster.Spec.Name = ""
128+
129+
By(fmt.Sprintf("Creating the Cluster %s with invalid parameters", kube.ObjectKeyFromObject(expectedCluster)), func() {
130+
createdCluster.ObjectMeta = expectedCluster.ObjectMeta
131+
Expect(k8sClient.Create(context.Background(), expectedCluster)).ToNot(HaveOccurred())
132+
133+
Eventually(
134+
testutil.WaitFor(
135+
k8sClient,
136+
createdCluster,
137+
status.
138+
FalseCondition(status.ClusterReadyType).
139+
WithReason(string(workflow.Internal)). // Internal due to reconciliation failing on the initial GET request
140+
WithMessageRegexp("name is invalid because must be set"),
141+
),
142+
60,
143+
interval,
144+
).Should(BeTrue())
145+
146+
lastGeneration++
147+
})
148+
149+
By("Fixing the cluster", func() {
150+
createdCluster.Spec.Name = "fixed-cluster"
151+
152+
Expect(k8sClient.Update(context.Background(), createdCluster)).To(Succeed())
153+
154+
Eventually(testutil.WaitFor(k8sClient, createdCluster, status.TrueCondition(status.ReadyType), validateClusterCreatingFunc()),
155+
1200, interval).Should(BeTrue())
156+
157+
doCommonChecks()
158+
checkAtlasState()
159+
})
160+
})
161+
125162
It("Should Succeed", func() {
126163
expectedCluster := testAtlasCluster(namespace.Name, "test-cluster", createdProject.Name)
127164

@@ -180,7 +217,14 @@ var _ = Describe("AtlasCluster", func() {
180217

181218
Expect(k8sClient.Update(context.Background(), createdCluster)).To(Succeed())
182219
Eventually(
183-
testutil.WaitFor(k8sClient, createdCluster, status.FalseCondition(status.ClusterReadyType).WithReason(string(workflow.ClusterNotCreatedInAtlas))),
220+
testutil.WaitFor(
221+
k8sClient,
222+
createdCluster,
223+
status.
224+
FalseCondition(status.ClusterReadyType).
225+
WithReason(string(workflow.ClusterNotUpdatedInAtlas)).
226+
WithMessageRegexp("CANNOT_UPDATE_PAUSED_CLUSTER"),
227+
),
184228
60,
185229
interval,
186230
).Should(BeTrue())
@@ -203,6 +247,65 @@ var _ = Describe("AtlasCluster", func() {
203247
Expect(c.ProviderBackupEnabled).To(Equal(createdCluster.Spec.ProviderBackupEnabled))
204248
})
205249
})
250+
251+
By("Setting AutoScaling.Compute.Enabled to false (should fail)", func() {
252+
createdCluster.Spec.ProviderSettings.AutoScaling = &mdbv1.AutoScalingSpec{
253+
Compute: &mdbv1.ComputeSpec{
254+
Enabled: boolptr(false),
255+
},
256+
}
257+
258+
Expect(k8sClient.Update(context.Background(), createdCluster)).To(Succeed())
259+
Eventually(
260+
testutil.WaitFor(
261+
k8sClient,
262+
createdCluster,
263+
status.
264+
FalseCondition(status.ClusterReadyType).
265+
WithReason(string(workflow.ClusterNotUpdatedInAtlas)).
266+
WithMessageRegexp("INVALID_ATTRIBUTE"),
267+
),
268+
60,
269+
interval,
270+
).Should(BeTrue())
271+
272+
lastGeneration++
273+
274+
By("Fixing the Cluster", func() {
275+
createdCluster.Spec.ProviderSettings.AutoScaling = nil
276+
performUpdate()
277+
doCommonChecks()
278+
checkAtlasState()
279+
})
280+
})
281+
282+
By("Setting incorrect instance size (should fail)", func() {
283+
oldSizeName := createdCluster.Spec.ProviderSettings.InstanceSizeName
284+
createdCluster.Spec.ProviderSettings.InstanceSizeName = "M42"
285+
286+
Expect(k8sClient.Update(context.Background(), createdCluster)).To(Succeed())
287+
Eventually(
288+
testutil.WaitFor(
289+
k8sClient,
290+
createdCluster,
291+
status.
292+
FalseCondition(status.ClusterReadyType).
293+
WithReason(string(workflow.ClusterNotUpdatedInAtlas)).
294+
WithMessageRegexp("INVALID_ENUM_VALUE"),
295+
),
296+
60,
297+
interval,
298+
).Should(BeTrue())
299+
300+
lastGeneration++
301+
302+
By("Fixing the Cluster", func() {
303+
createdCluster.Spec.ProviderSettings.InstanceSizeName = oldSizeName
304+
performUpdate()
305+
doCommonChecks()
306+
checkAtlasState()
307+
})
308+
})
206309
})
207310
})
208311
})

0 commit comments

Comments
 (0)