Skip to content

Commit 0aca5b6

Browse files
Merge pull request #63 from jianrongzhang89/host-fix
DBAAS-956 MongoDB Atlas Operator incorrectly sets host to empty when processing connections
2 parents b145fde + 08efb13 commit 0aca5b6

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

pkg/controller/atlasconnection/atlasconnection_controller.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,16 @@ func (r *MongoDBAtlasConnectionReconciler) Reconcile(cx context.Context, req ctr
150150
projectID := instance.InstanceInfo[dbaas.ProjectIDKey]
151151

152152
if conn.Status.ConnectionInfoRef == nil {
153+
srvString := instance.InstanceInfo[dbaas.ConnectionStringsStandardSrvKey]
154+
if len(srvString) == 0 {
155+
log.Info("Instance connection strings are empty. Will retry.")
156+
result := workflow.Terminate(workflow.MongoDBAtlasInstanceNotReady, "Atlas database instance not ready")
157+
dbaas.SetConnectionCondition(conn, dbaasv1alpha1.DBaaSConnectionProviderSyncType, metav1.ConditionFalse, string(result.Reason()), result.Message())
158+
// Requeue
159+
return ctrl.Result{}, fmt.Errorf("instance connection strings are empty")
160+
}
153161
// Now create a configmap for non-sensitive information needed for connecting to the DB instance
154-
cm := getOwnedConfigMap(conn, instance.InstanceInfo[dbaas.ConnectionStringsStandardSrvKey])
162+
cm := getOwnedConfigMap(conn, srvString)
155163
cmCreated, err := r.Clientset.CoreV1().ConfigMaps(req.Namespace).Create(context.Background(), cm, metav1.CreateOptions{})
156164
if err != nil {
157165
result := workflow.Terminate(workflow.MongoDBAtlasConnectionBackendError, err.Error())

pkg/controller/atlasconnection/atlasconnection_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,19 @@ func TestAtlasConnectionReconcile(t *testing.T) {
206206
expectedStatus: "False",
207207
expectedReason: "InventoryNotFound",
208208
},
209+
"InstanceNotReady": {
210+
createConnection: true,
211+
configMapCreateFail: false,
212+
secretCreateFail: false,
213+
instanceID: "70b7a72f4877d05880cNoSrv",
214+
inventoryReason: "SyncOK",
215+
inventoryStatus: "True",
216+
instancesPath: "../../../test/e2e/data/atlasinventoryconditionsnosrv.json",
217+
expectedErrString: "instance connection strings are empty",
218+
expectedRequeue: false,
219+
expectedStatus: "False",
220+
expectedReason: "InstanceNotReady",
221+
},
209222
"ConfigMapCreateFail": {
210223
createConnection: true,
211224
configMapCreateFail: true,
@@ -251,7 +264,7 @@ func TestAtlasConnectionReconcile(t *testing.T) {
251264
t.Run(tcName, func(t *testing.T) {
252265
instances := []dbaasv1alpha1.Instance{}
253266
if len(tc.instancesPath) > 0 {
254-
data, err := ioutil.ReadFile("../../../test/e2e/data/atlasinventoryexpected.json")
267+
data, err := ioutil.ReadFile(tc.instancesPath)
255268
assert.NoError(t, err)
256269
err = json.Unmarshal(data, &instances)
257270
assert.NoError(t, err)

pkg/controller/workflow/reason.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const (
8181
MongoDBAtlasInstanceReady ConditionReason = "Ready"
8282
MongoDBAtlasInstanceAtlasUnreachable ConditionReason = "Unreachable"
8383
MongoDBAtlasInstanceInventoryNotFound ConditionReason = "InventoryNotFound"
84+
MongoDBAtlasInstanceNotReady ConditionReason = "InstanceNotReady"
8485
MongoDBAtlasInstanceClusterNotFound ConditionReason = "AtlasClusterNotFound"
8586
MongoDBAtlasInstanceBackendError ConditionReason = "BackendError"
8687
MongoDBAtlasInstanceAuthenticationError ConditionReason = "AuthenticationError"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
"instanceID":"70b7a72f4877d05880cNoSrv",
4+
"name":"testb",
5+
"instanceInfo":{
6+
"instanceSizeName":"M10",
7+
"state":"Creating",
8+
"projectID":"608df5e652e1944293e8584a",
9+
"projectName":"Project 1",
10+
"providerName":"AWS",
11+
"regionName":"US_EAST_1"
12+
}
13+
}
14+
]

0 commit comments

Comments
 (0)