Skip to content

Commit b145fde

Browse files
Merge pull request #60 from jianrongzhang89/rebase-fix
Fix code issues after rebasing on 8/31
2 parents d2f103c + a83e491 commit b145fde

12 files changed

+69
-65
lines changed

pkg/api/v1/atlasproject_types.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func (p *AtlasProject) GetCondition(condType status.ConditionType) *status.Condi
153153

154154
// CheckConditions check AtlasProject conditions
155155
// First check if ReadyType condition exists and is True
156-
// Then check if a condition of ProjectReadyType, ClusterReadyType, IPAccessListReadyType or PrivateEndpointReadyType condition exists and is False
156+
// Then check if a condition of ProjectReadyType, DeploymentReadyType, IPAccessListReadyType or PrivateEndpointReadyType condition exists and is False
157157
// returns nil otherwise
158158
func (p *AtlasProject) CheckConditions() *status.Condition {
159159
cond := p.GetCondition(status.ReadyType)
@@ -164,7 +164,7 @@ func (p *AtlasProject) CheckConditions() *status.Condition {
164164
if cond != nil && cond.Status == corev1.ConditionFalse {
165165
return cond
166166
}
167-
cond = p.GetCondition(status.ClusterReadyType)
167+
cond = p.GetCondition(status.DeploymentReadyType)
168168
if cond != nil && cond.Status == corev1.ConditionFalse {
169169
return cond
170170
}

pkg/controller/atlasdeployment/deployment.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ func ensureDeploymentState(ctx *workflow.Context, project *mdbv1.AtlasProject, d
5555
return atlasDeployment, workflow.InProgress(workflow.DeploymentUpdating, "deployment is updating")
5656

5757
case "DELETING":
58-
return atlasCluster, workflow.InProgress(workflow.ClusterDeleting, "cluster is being deleted")
58+
return atlasDeployment, workflow.InProgress(workflow.DeploymentDeleting, "deployment is being deleted")
5959

6060
case "DELETED":
61-
return atlasCluster, workflow.InProgress(workflow.ClusterDeleted, "cluster has been deleted")
61+
return atlasDeployment, workflow.InProgress(workflow.DeploymentDeleted, "deployment has been deleted")
6262
default:
6363
return atlasDeployment, workflow.Terminate(workflow.Internal, fmt.Sprintf("unknown deployment state %q", atlasDeployment.StateName))
6464
}

pkg/controller/atlasinstance/atlasinstance_controller.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func (r *MongoDBAtlasInstanceReconciler) reconcileAtlasDeployment(cx context.Con
227227
return ctrl.Result{}, err
228228
}
229229

230-
result := setInstanceStatusWithClusterInfo(atlasClient, inst, atlasDeployment, instData.ProjectName)
230+
result := setInstanceStatusWithDeploymentInfo(atlasClient, inst, atlasDeployment, instData.ProjectName)
231231
if !result.IsOk() {
232232
log.Infof("Error setting instance status: %v", result.Message())
233233
return ctrl.Result{}, errors.New(result.Message())
@@ -461,7 +461,7 @@ func instanceMutateFn(atlasProject *v1.AtlasProject, atlasDeployment *v1.AtlasDe
461461
}
462462
}
463463

464-
func setInstanceStatusWithClusterInfo(atlasClient *mongodbatlas.Client, inst *dbaas.MongoDBAtlasInstance, atlasDeployment *v1.AtlasDeployment, project string) workflow.Result {
464+
func setInstanceStatusWithDeploymentInfo(atlasClient *mongodbatlas.Client, inst *dbaas.MongoDBAtlasInstance, atlasDeployment *v1.AtlasDeployment, project string) workflow.Result {
465465
instInfo, result := atlasinventory.GetClusterInfo(atlasClient, project, inst.Spec.Name)
466466
if result.IsOk() {
467467
// Stores the phase info in inst.Status.Phase and remove from instInfo.InstanceInf map
@@ -476,7 +476,7 @@ func setInstanceStatusWithClusterInfo(atlasClient *mongodbatlas.Client, inst *db
476476
}
477477
statusFound := false
478478
for _, cond := range atlasDeployment.Status.Conditions {
479-
if cond.Type == status.ClusterReadyType {
479+
if cond.Type == status.DeploymentReadyType {
480480
statusFound = true
481481
if cond.Status == corev1.ConditionTrue {
482482
dbaas.SetInstanceCondition(inst, dbaasv1alpha1.DBaaSInstanceProviderSyncType, metav1.ConditionStatus(cond.Status), "Ready", cond.Message)

pkg/controller/atlasinstance/atlasinstance_test.go

+44-44
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import (
4848
func TestGetInstanceData(t *testing.T) {
4949
log := zaptest.Logger(t).Sugar()
5050
testCase := map[string]struct {
51-
clusterName string
51+
deploymentName string
5252
projectName string
5353
providerName string
5454
regionName string
@@ -59,7 +59,7 @@ func TestGetInstanceData(t *testing.T) {
5959
expErrMsg string
6060
}{
6161
"Nominal": {
62-
clusterName: "myCluster",
62+
deploymentName: "myDeployment",
6363
projectName: "myProject",
6464
providerName: "GCP",
6565
regionName: "GCP_REGION",
@@ -69,8 +69,8 @@ func TestGetInstanceData(t *testing.T) {
6969
expInstanceSizeName: "M10",
7070
expErrMsg: "",
7171
},
72-
"MissingClusterName": {
73-
clusterName: "",
72+
"MissingDeploymentName": {
73+
deploymentName: "",
7474
projectName: "myProject",
7575
providerName: "GCP",
7676
regionName: "GCP_REGION",
@@ -81,7 +81,7 @@ func TestGetInstanceData(t *testing.T) {
8181
expErrMsg: "missing clusterName",
8282
},
8383
"MissingProjectName": {
84-
clusterName: "myCluster",
84+
deploymentName: "myDeployment",
8585
projectName: "",
8686
providerName: "GCP",
8787
regionName: "GCP_REGION",
@@ -92,7 +92,7 @@ func TestGetInstanceData(t *testing.T) {
9292
expErrMsg: "missing projectName",
9393
},
9494
"UseDefaultProvider": {
95-
clusterName: "myCluster",
95+
deploymentName: "myDeployment",
9696
projectName: "myProject",
9797
providerName: "",
9898
regionName: "AWS_REGION",
@@ -103,7 +103,7 @@ func TestGetInstanceData(t *testing.T) {
103103
expErrMsg: "",
104104
},
105105
"UseDefaultRegion": {
106-
clusterName: "myCluster",
106+
deploymentName: "myDeployment",
107107
projectName: "myProject",
108108
providerName: "AWS",
109109
regionName: "",
@@ -114,7 +114,7 @@ func TestGetInstanceData(t *testing.T) {
114114
expErrMsg: "",
115115
},
116116
"UseDefaultInstanceSizeName": {
117-
clusterName: "myCluster",
117+
deploymentName: "myDeployment",
118118
projectName: "myProject",
119119
providerName: "AWS",
120120
regionName: "US_EAST_1",
@@ -142,7 +142,7 @@ func TestGetInstanceData(t *testing.T) {
142142
Name: fmt.Sprintf("inventory-%s", tcName),
143143
Namespace: "dbaas-operator",
144144
},
145-
Name: tc.clusterName,
145+
Name: tc.deploymentName,
146146
CloudProvider: tc.providerName,
147147
CloudRegion: tc.regionName,
148148
OtherInstanceParams: map[string]string{
@@ -154,7 +154,7 @@ func TestGetInstanceData(t *testing.T) {
154154

155155
expected := &InstanceData{
156156
ProjectName: tc.projectName,
157-
ClusterName: tc.clusterName,
157+
ClusterName: tc.deploymentName,
158158
ProviderName: tc.expProviderName,
159159
RegionName: tc.expRegionName,
160160
InstanceSizeName: tc.expInstanceSizeName,
@@ -210,25 +210,25 @@ func setupMockAltasServer(t *testing.T) (client *mongodbatlas.Client, teardown f
210210
}
211211
}).Methods(http.MethodGet)
212212

213-
router.HandleFunc("/api/atlas/v1.0/groups/{group-id}/clusters/{cluster-name}", func(w http.ResponseWriter, r *http.Request) {
213+
router.HandleFunc("/api/atlas/v1.0/groups/{group-id}/clusters/{deployment-name}", func(w http.ResponseWriter, r *http.Request) {
214214
vars := mux.Vars(r)
215215
groupID, ok := vars["group-id"]
216216
if !ok {
217217
fmt.Fprint(w, "group-id is missing in parameters")
218218
}
219-
clusterName, ok := vars["cluster-name"]
219+
deploymentName, ok := vars["deployment-name"]
220220
if !ok {
221-
fmt.Fprint(w, "cluster-name is missing in parameters")
221+
fmt.Fprint(w, "deployment-name is missing in parameters")
222222
}
223-
data, err := ioutil.ReadFile(fmt.Sprintf("../../../test/e2e/data/atlasclusterget_%s_%s.json", groupID, clusterName))
223+
data, err := ioutil.ReadFile(fmt.Sprintf("../../../test/e2e/data/atlasdeploymentget_%s_%s.json", groupID, deploymentName))
224224
if err == nil {
225225
assert.NoError(t, err)
226226
w.WriteHeader(http.StatusOK)
227227
fmt.Fprint(w, string(data))
228228
} else {
229229
w.WriteHeader(http.StatusNotFound)
230-
f := "{\"detail\":\"No cluster named %s exists in group %s.\",\"error\":404,\"errorCode\":\"CLUSTER_NOT_FOUND\",\"parameters\":[\"%s\",\"groupid123\"],\"reason\":\"Not Found\"}"
231-
fmt.Fprintf(w, f, clusterName, groupID, clusterName)
230+
f := "{\"detail\":\"No deployment named %s exists in group %s.\",\"error\":404,\"errorCode\":\"CLUSTER_NOT_FOUND\",\"parameters\":[\"%s\",\"groupid123\"],\"reason\":\"Not Found\"}"
231+
fmt.Fprintf(w, f, deploymentName, groupID, deploymentName)
232232
}
233233
}).Methods(http.MethodGet)
234234

@@ -244,43 +244,43 @@ func setupMockAltasServer(t *testing.T) (client *mongodbatlas.Client, teardown f
244244
return client, server.Close
245245
}
246246

247-
func TestSetInstanceStatusWithClusterInfo(t *testing.T) {
247+
func TestSetInstanceStatusWithDeploymentInfo(t *testing.T) {
248248
atlasClient, teardown := setupMockAltasServer(t)
249249
defer teardown()
250250

251251
namespace := "default"
252252
testCase := map[string]struct {
253-
clusterName string
254-
projectName string
255-
expErrMsg string
256-
expPhase dbaasv1alpha1.DBaasInstancePhase
257-
expStatus string
253+
deploymentName string
254+
projectName string
255+
expErrMsg string
256+
expPhase dbaasv1alpha1.DBaasInstancePhase
257+
expStatus string
258258
}{
259-
"ClusterCreating": {
260-
clusterName: "myclustercreating",
261-
projectName: "myproject",
262-
expErrMsg: "",
263-
expPhase: dbaasv1alpha1.InstancePhaseCreating,
264-
expStatus: "True",
259+
"DeploymentCreating": {
260+
deploymentName: "mydeploymentcreating",
261+
projectName: "myproject",
262+
expErrMsg: "",
263+
expPhase: dbaasv1alpha1.InstancePhaseCreating,
264+
expStatus: "True",
265265
},
266-
"ClusterReady": {
267-
clusterName: "myclusterready",
268-
projectName: "myproject",
269-
expErrMsg: "",
270-
expPhase: dbaasv1alpha1.InstancePhaseReady,
271-
expStatus: "True",
266+
"DeploymentReady": {
267+
deploymentName: "mydeploymentready",
268+
projectName: "myproject",
269+
expErrMsg: "",
270+
expPhase: dbaasv1alpha1.InstancePhaseReady,
271+
expStatus: "True",
272272
},
273273
"InvalidProject": {
274-
clusterName: "myclusterready",
275-
projectName: "myproject-invalid",
276-
expErrMsg: "NOT_IN_GROUP",
274+
deploymentName: "mydeploymentready",
275+
projectName: "myproject-invalid",
276+
expErrMsg: "NOT_IN_GROUP",
277277
},
278278
}
279279
for tcName, tc := range testCase {
280280
t.Run(tcName, func(t *testing.T) {
281281
atlasDeployment := &v1.AtlasDeployment{
282282
ObjectMeta: metav1.ObjectMeta{
283-
Name: "my-cluster-free",
283+
Name: "my-deployment-free",
284284
Namespace: namespace,
285285
},
286286
Spec: v1.AtlasDeploymentSpec{
@@ -289,7 +289,7 @@ func TestSetInstanceStatusWithClusterInfo(t *testing.T) {
289289
Namespace: namespace,
290290
},
291291
DeploymentSpec: &v1.DeploymentSpec{
292-
Name: tc.clusterName,
292+
Name: tc.deploymentName,
293293
ProviderSettings: &v1.ProviderSettingsSpec{
294294
BackingProviderName: "AWS",
295295
InstanceSizeName: "M0",
@@ -307,7 +307,7 @@ func TestSetInstanceStatusWithClusterInfo(t *testing.T) {
307307
LastTransitionTime: metav1.Now(),
308308
},
309309
{
310-
Type: status.ConditionType("ClusterReady"),
310+
Type: status.ConditionType("DeploymentReady"),
311311
Status: corev1.ConditionTrue,
312312
LastTransitionTime: metav1.Now(),
313313
},
@@ -325,13 +325,13 @@ func TestSetInstanceStatusWithClusterInfo(t *testing.T) {
325325
Name: "my-inventory",
326326
Namespace: namespace,
327327
},
328-
Name: tc.clusterName,
328+
Name: tc.deploymentName,
329329
OtherInstanceParams: map[string]string{
330330
"projectName": tc.projectName,
331331
},
332332
},
333333
}
334-
result := setInstanceStatusWithClusterInfo(atlasClient, inst, atlasDeployment, tc.projectName)
334+
result := setInstanceStatusWithDeploymentInfo(atlasClient, inst, atlasDeployment, tc.projectName)
335335
if len(tc.expErrMsg) == 0 {
336336
cond := dbaas.GetInstanceCondition(inst, dbaasv1alpha1.DBaaSInstanceProviderSyncType)
337337
assert.NotNil(t, cond)
@@ -366,7 +366,7 @@ func TestAtlasInstanceReconcile(t *testing.T) {
366366
}
367367

368368
tcName := "mytest"
369-
clusterName := "myclusternew"
369+
deploymentName := "mydeploymentnew"
370370
projectName := "myproject"
371371
expectedPhase := dbaasv1alpha1.InstancePhasePending
372372
expectedErrString := "CLUSTER_NOT_FOUND"
@@ -414,7 +414,7 @@ func TestAtlasInstanceReconcile(t *testing.T) {
414414
Namespace: "dbaas-operator",
415415
},
416416
Spec: dbaasv1alpha1.DBaaSInstanceSpec{
417-
Name: clusterName,
417+
Name: deploymentName,
418418
InventoryRef: dbaasv1alpha1.NamespacedName{
419419
Name: inventory.Name,
420420
Namespace: inventory.Namespace,

pkg/controller/atlasinventory/inventory.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import (
55
"net/http"
66
"strings"
77

8+
"golang.org/x/text/cases"
9+
"golang.org/x/text/language"
10+
811
"go.mongodb.org/atlas/mongodbatlas"
912

1013
dbaasv1alpha1 "github.com/RHEcosystemAppEng/dbaas-operator/api/v1alpha1"
@@ -76,7 +79,8 @@ func GetInstance(project mongodbatlas.Project, cluster mongodbatlas.Cluster) dba
7679
// Deleting - cluster deletion in progress
7780
// Deleted - cluster has been deleted
7881
// Ready - cluster provisioning complete
79-
phase := parsePhase(strings.Title(strings.ToLower(cluster.StateName)))
82+
caser := cases.Title(language.AmericanEnglish)
83+
phase := parsePhase(caser.String(strings.ToLower(cluster.StateName)))
8084
provider := cluster.ProviderSettings.BackingProviderName
8185
if len(provider) == 0 {
8286
provider = cluster.ProviderSettings.ProviderName

pkg/controller/atlasinventory/inventory_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func setupMockAltasServer(t *testing.T) (client *mongodbatlas.Client, teardown f
8787
if !ok {
8888
fmt.Fprint(w, "group-id is missing in parameters")
8989
}
90-
data, err := ioutil.ReadFile(fmt.Sprintf("../../../test/e2e/data/atlasclusterlistresp_%s.json", groupID))
90+
data, err := ioutil.ReadFile(fmt.Sprintf("../../../test/e2e/data/atlasdeploymentlistresp_%s.json", groupID))
9191
assert.NoError(t, err)
9292
if err == nil {
9393
fmt.Fprint(w, string(data))

pkg/controller/workflow/reason.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ const (
3434

3535
// Atlas Cluster reasons
3636
const (
37-
ClusterNotCreatedInAtlas ConditionReason = "ClusterNotCreatedInAtlas"
38-
ClusterNotUpdatedInAtlas ConditionReason = "ClusterNotUpdatedInAtlas"
39-
ClusterCreating ConditionReason = "ClusterCreating"
40-
ClusterUpdating ConditionReason = "ClusterUpdating"
41-
ClusterDeleting ConditionReason = "ClusterDeleting"
42-
ClusterDeleted ConditionReason = "ClusterDeleted"
43-
ClusterConnectionSecretsNotCreated ConditionReason = "ClusterConnectionSecretsNotCreated"
44-
ClusterAdvancedOptionsAreNotReady ConditionReason = "ClusterAdvancedOptionsAreNotReady"
37+
DeploymentNotCreatedInAtlas ConditionReason = "DeploymentNotCreatedInAtlas"
38+
DeploymentNotUpdatedInAtlas ConditionReason = "DeploymentNotUpdatedInAtlas"
39+
DeploymentCreating ConditionReason = "DeploymentCreating"
40+
DeploymentUpdating ConditionReason = "DeploymentUpdating"
41+
DeploymentDeleting ConditionReason = "DeploymentDeleting"
42+
DeploymentDeleted ConditionReason = "DeploymentDeleted"
43+
DeploymentConnectionSecretsNotCreated ConditionReason = "DeploymentConnectionSecretsNotCreated"
44+
DeploymentAdvancedOptionsAreNotReady ConditionReason = "DeploymentAdvancedOptionsAreNotReady"
4545
)
4646

4747
// Atlas Database User reasons

test/e2e/data/atlasclusterget_groupid123_myclustercreating.json renamed to test/e2e/data/atlasdeploymentget_groupid123_mydeploymentcreating.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"mongoURI":"mongodb://dmycluster-shard-00-00.hhhjj.mongodb.net:27017,mycluster-shard-00-01.hhhjj.mongodb.net:27017,mycluster-shard-00-02.hhhjj.mongodb.net:27017",
4545
"mongoURIUpdated":"2021-09-13T13:53:50Z",
4646
"mongoURIWithOptions":"mongodb://dmycluster-shard-00-00.hhhjj.mongodb.net:27017,mycluster-shard-00-01.hhhjj.mongodb.net:27017,mycluster-shard-00-02.hhhjj.mongodb.net:27017/?ssl=true&authSource=admin&replicaSet=atlas-nwp2f7-shard-0",
47-
"name":"myclustercreating",
47+
"name":"mydeploymentcreating",
4848
"numShards":1,
4949
"paused":false,
5050
"pitEnabled":false,
@@ -86,7 +86,7 @@
8686
}
8787
],
8888
"rootCertType":"ISRGROOTX1",
89-
"srvAddress":"mongodb+srv://myclusterready.hhhjj.mongodb.net",
89+
"srvAddress":"mongodb+srv://mydeploymentready.hhhjj.mongodb.net",
9090
"stateName":"CREATING",
9191
"versionReleaseSystem":"LTS"
9292
}

test/e2e/data/atlasclusterget_groupid123_myclusterready.json renamed to test/e2e/data/atlasdeploymentget_groupid123_mydeploymentready.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"mongoURI":"mongodb://dmycluster-shard-00-00.hhhjj.mongodb.net:27017,mycluster-shard-00-01.hhhjj.mongodb.net:27017,mycluster-shard-00-02.hhhjj.mongodb.net:27017",
4545
"mongoURIUpdated":"2021-09-13T13:53:50Z",
4646
"mongoURIWithOptions":"mongodb://dmycluster-shard-00-00.hhhjj.mongodb.net:27017,mycluster-shard-00-01.hhhjj.mongodb.net:27017,mycluster-shard-00-02.hhhjj.mongodb.net:27017/?ssl=true&authSource=admin&replicaSet=atlas-nwp2f7-shard-0",
47-
"name":"myclusterready",
47+
"name":"mydeploymentready",
4848
"numShards":1,
4949
"paused":false,
5050
"pitEnabled":false,
@@ -86,7 +86,7 @@
8686
}
8787
],
8888
"rootCertType":"ISRGROOTX1",
89-
"srvAddress":"mongodb+srv://myclusterready.hhhjj.mongodb.net",
89+
"srvAddress":"mongodb+srv://mydeploymentready.hhhjj.mongodb.net",
9090
"stateName":"IDLE",
9191
"versionReleaseSystem":"LTS"
9292
}

0 commit comments

Comments
 (0)