Skip to content

Commit c189a61

Browse files
Jianrong Zhangtchughesiv
Jianrong Zhang
authored andcommitted
Integrate Atlas Operator with Openshift Database Access
1 parent 9d3b1f3 commit c189a61

File tree

72 files changed

+9246
-184
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+9246
-184
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ tmp/
4242

4343
# ready to work samples
4444
deploy/
45+
__debug_bin/

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ WORKDIR /workspace
55
# Copy the Go Modules manifests
66
COPY go.mod go.mod
77
COPY go.sum go.sum
8+
# Copy DBaaSProvider config
9+
COPY config/dbaasprovider/dbaas_provider.yaml dbaas_provider.yaml
10+
811
# cache deps before building and copying source so that we don't need to re-download as much
912
# and so that source changes don't invalidate our downloaded layer
1013
RUN go mod download
@@ -55,6 +58,7 @@ LABEL name="MongoDB Atlas Operator" \
5558
WORKDIR /
5659
COPY --from=builder /workspace/bin/manager .
5760
COPY hack/licenses licenses
61+
COPY --from=builder /workspace/dbaas_provider.yaml .
5862

5963
USER 1001:0
6064
ENTRYPOINT ["/manager"]

Makefile

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ CONTAINER_ENGINE?=docker
99
# To re-generate a bundle for another specific version without changing the standard setup, you can:
1010
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
1111
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
12-
VERSION ?= $(shell git describe --tags --dirty --broken | cut -c 2-)
12+
VERSION ?= 0.3.0
13+
14+
ifndef PRODUCT_VERSION
15+
PRODUCT_VERSION := $(shell git describe --tags --dirty --broken)
16+
endif
17+
18+
CONTAINER_ENGINE?=docker
1319

1420
# CHANNELS define the bundle channels used in the bundle.
1521
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "preview,fast,stable")
@@ -42,16 +48,19 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
4248

4349
# Base registry for the operator, bundle, catalog images
4450
REGISTRY ?= quay.io/mongodb
45-
# BUNDLE_IMG defines the image:tag used for the bundle.
46-
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
47-
BUNDLE_IMG ?= $(REGISTRY)/mongodb-atlas-kubernetes-operator-prerelease-bundle:$(VERSION)
48-
49-
#IMG ?= mongodb-atlas-kubernetes-operator:latest
50-
#BUNDLE_REGISTRY ?= $(REGISTRY)/mongodb-atlas-operator-bundle
51-
OPERATOR_REGISTRY ?= $(REGISTRY)/mongodb-atlas-kubernetes-operator-prerelease
52-
CATALOG_REGISTRY ?= $(REGISTRY)/mongodb-atlas-kubernetes-operator-prerelease-catalog
53-
OPERATOR_IMAGE ?= ${OPERATOR_REGISTRY}:${VERSION}
54-
CATALOG_IMAGE ?= ${CATALOG_REGISTRY}:${VERSION}
51+
# Image URL to use all building/pushing image targets
52+
IMG ?= $(REGISTRY)/mongodb-atlas-kubernetes-dbaas
53+
OPERATOR_REGISTRY ?= $(IMG)
54+
55+
OPERATOR_IMG ?= $(IMG):$(VERSION)
56+
# OPERATOR_IMG ?= $(IMG):latest
57+
58+
BUNDLE_IMG ?= $(IMG)-bundle:$(VERSION)
59+
# BUNDLE_IMG ?= $(IMG)-bundle:latest
60+
61+
CATALOG_IMG ?= $(IMG)-catalog:$(VERSION)
62+
# CATALOG_IMG ?= ${IMG}-catalog:latest
63+
5564
TARGET_NAMESPACE ?= mongodb-atlas-operator-system-test
5665

5766
# Image URL to use all building/pushing image targets
@@ -176,39 +185,46 @@ rm -rf $$TMP_DIR ;\
176185
endef
177186

178187
.PHONY: bundle
179-
bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
188+
bundle: manifests kustomize ## Generate bundle manifests and metadata, update security context for OpenShift, then validate generated files.
180189
@echo "Building bundle $(VERSION)"
181190
operator-sdk generate kustomize manifests -q --apis-dir=pkg/api
182-
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
183-
$(KUSTOMIZE) build --load-restrictor LoadRestrictionsNone config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
191+
cd config/manager && $(KUSTOMIZE) edit set image controller=$(OPERATOR_IMG)
192+
$(KUSTOMIZE) build --load-restrictor LoadRestrictionsNone config/manifests | operator-sdk generate bundle -q --overwrite --manifests --version $(VERSION) $(BUNDLE_METADATA_OPTS)
184193
operator-sdk bundle validate ./bundle
185194

186195
.PHONY: image
187-
image: ## Build the operator image
188-
$(CONTAINER_ENGINE) build --build-arg VERSION=$(VERSION) -t $(OPERATOR_IMAGE) .
189-
$(CONTAINER_ENGINE) push $(OPERATOR_IMAGE)
196+
image: manager ## Build the operator image
197+
$(CONTAINER_ENGINE) build -t $(OPERATOR_IMG) .
198+
$(CONTAINER_ENGINE) push $(OPERATOR_IMG)
190199

191200
.PHONY: bundle-build
192201
bundle-build: ## Build the bundle image.
193202
$(CONTAINER_ENGINE) build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
194203

195204
.PHONY: bundle-push
196-
bundle-push:
205+
bundle-push: ## Push the bundle image.
197206
$(CONTAINER_ENGINE) push $(BUNDLE_IMG)
198207

208+
# A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0).
209+
# These images MUST exist in a registry and be pull-able.
210+
BUNDLE_IMGS ?= $(BUNDLE_IMG)
211+
199212
.PHONY: catalog-build
200213
CATALOG_DIR ?= ./scripts/openshift/atlas-catalog
201-
catalog-build: image
214+
#catalog-build: IMG=
215+
catalog-build: ## bundle bundle-push ## Build file-based bundle
216+
$(MAKE) image IMG=$(IMG)
202217
CATALOG_DIR=$(CATALOG_DIR) \
203218
CHANNEL=$(DEFAULT_CHANNEL) \
204-
CATALOG_IMAGE=$(CATALOG_IMAGE) \
219+
CATALOG_IMAGE=$(CATALOG_IMG) \
205220
BUNDLE_IMAGE=$(BUNDLE_IMG) \
206221
VERSION=$(VERSION) \
222+
CONTAINER_ENGINE=$(CONTAINER_ENGINE) \
207223
./scripts/build_catalog.sh
208224

209225
.PHONY: catalog-push
210226
catalog-push:
211-
$(CONTAINER_ENGINE) push $(CATALOG_IMAGE)
227+
$(CONTAINER_ENGINE) push $(CATALOG_IMG)
212228

213229
.PHONY: build-subscription
214230
build-subscription:
@@ -226,6 +242,7 @@ build-catalogsource:
226242

227243
.PHONY: deploy-olm
228244
# Deploy atlas operator to the running openshift cluster with OLM
245+
deploy-olm: export IMG=$(OPERATOR_IMAGE)
229246
deploy-olm: bundle-build bundle-push catalog-build catalog-push build-catalogsource build-subscription
230247
oc -n openshift-marketplace delete catalogsource mongodb-atlas-kubernetes-local --ignore-not-found
231248
oc delete namespace $(TARGET_NAMESPACE) --ignore-not-found
@@ -241,7 +258,7 @@ deploy-olm: bundle-build bundle-push catalog-build catalog-push build-catalogsou
241258

242259
.PHONY: image-push
243260
image-push: ## Push the docker image
244-
$(CONTAINER_ENGINE) push ${IMG}
261+
$(CONTAINER_ENGINE) push ${OPERATOR_IMG}
245262

246263
# Additional make goals
247264
.PHONY: run-kind

PROJECT

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
domain: mongodb.com
22
layout:
3-
- go.kubebuilder.io/v2
3+
- go.kubebuilder.io/v3
44
plugins:
55
manifests.sdk.operatorframework.io/v2: {}
66
scorecard.sdk.operatorframework.io/v2: {}
@@ -15,7 +15,33 @@ resources:
1515
group: atlas
1616
kind: AtlasDeployment
1717
path: github.com/mongodb/mongodb-atlas-kubernetes/api/v1
18-
version: v1
18+
- api:
19+
crdVersion: v1
20+
namespaced: true
21+
controller: true
22+
domain: redhat.com
23+
group: dbaas
24+
kind: MongoDBAtlasConnection
25+
path: github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/dbaas
26+
version: v1alpha1
27+
- api:
28+
crdVersion: v1
29+
namespaced: true
30+
controller: true
31+
domain: redhat.com
32+
group: dbaas
33+
kind: MongoDBAtlasInventory
34+
path: github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/dbaas
35+
version: v1alpha1
36+
- api:
37+
crdVersion: v1
38+
namespaced: true
39+
controller: true
40+
domain: redhat.com
41+
group: dbaas
42+
kind: MongoDBAtlasInstance
43+
path: github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/dbaas
44+
version: v1alpha1
1945
- api:
2046
crdVersion: v1
2147
namespaced: true

README.md

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,200 @@ Operator support Third Party Integration.
151151
- [Mongodb Atlas Operator sample](docs/project-integration.md)
152152
- [Atlas documentation Atlas](https://docs.atlas.mongodb.com/reference/api/third-party-integration-settings/)
153153

154+
### Step 4. Test Database as a Service (DBaaS) on OpenShift
155+
156+
The Atlas Operator is integrated with the [Red Hat Database-as-a-Service (DBaaS) Operator](https://github.com/RHEcosystemAppEng/dbaas-operator) which allows application developers to import database instances and connect to the databases through the [Service Binding Operator](https://github.com/redhat-developer/service-binding-operator). More information can be found [here](https://github.com/RHEcosystemAppEng/dbaas-operator#readme).
157+
158+
Note that both the DBaaS Operator and Atlas Operator should be installed through the [Operator Lifecyle Manager (OLM)](https://github.com/operator-framework/operator-lifecycle-manager).
159+
160+
**1.** Check DBaaS Registration
161+
162+
If the DBaaS Operator has been deployed in the OpenShift Cluster, the Atlas Operator automatically creates a cluster level [DBaaSProvider](https://github.com/RHEcosystemAppEng/dbaas-operator/blob/main/config/crd/bases/dbaas.redhat.com_dbaasproviders.yaml) custom resource (CR) object `mongodb-atlas-registration` to automatically register itself with the DBaaS Operator.
163+
164+
```
165+
apiVersion: dbaas.redhat.com/v1alpha1
166+
kind: DBaaSProvider
167+
metadata:
168+
labels:
169+
related-to: dbaas-operator
170+
type: dbaas-provider-registration
171+
name: mongodb-atlas-registration
172+
spec:
173+
connectionKind: MongoDBAtlasConnection
174+
credentialFields:
175+
- displayName: Organization ID
176+
key: orgId
177+
required: true
178+
type: string
179+
- displayName: Public API Key
180+
key: publicApiKey
181+
required: true
182+
type: string
183+
- displayName: Private API Key
184+
key: privateApiKey
185+
required: true
186+
type: maskedstring
187+
inventoryKind: MongoDBAtlasInventory
188+
provider:
189+
displayDescription: Cloud-hosted MongoDB service on AWS, Azure and Google Cloud
190+
displayName: MongoDB Atlas Cloud Database Service
191+
icon:
192+
base64data: <icon image data>
193+
mediatype: image/png
194+
name: Red Hat DBaaS / MongoDB Atlas
195+
```
196+
If the Atlas Operator is undeployed with the OLM, the above registration CR gets cleaned up automatically.
197+
198+
**2.** Check MongoDBAtlasInventory Custom Resource
199+
200+
First an administrator creates a [DBaaSInventory](https://github.com/RHEcosystemAppEng/dbaas-operator/blob/main/config/crd/bases/dbaas.redhat.com_dbaasinventories.yaml) CR for MongoDB. The DBaaS Operator automatically creates a MongoDBAtlasInventory CR, and the Atlas Operator discovers the clusters and instances, and sets the result in the CR status.
201+
Here is an example of MongoDBAtlasInventory CR.
202+
```
203+
apiVersion: dbaas.redhat.com/v1alpha1
204+
kind: MongoDBAtlasInventory
205+
metadata:
206+
name: dbaas-mytest
207+
namespace: openshift-operators
208+
ownerReferences:
209+
- apiVersion: dbaas.redhat.com/v1alpha1
210+
blockOwnerDeletion: true
211+
controller: true
212+
kind: DBaaSInventory
213+
name: dbaas-mytest
214+
uid: 01f5a690-c640-462f-b6e8-ccb9db95df70
215+
spec:
216+
credentialsRef:
217+
name: my-atlas-key
218+
namespace: openshift-operators
219+
status:
220+
conditions:
221+
- lastTransitionTime: "2021-08-18T20:06:47Z"
222+
message: Spec sync OK
223+
reason: SyncOK
224+
status: "True"
225+
type: SpecSynced
226+
instances:
227+
- instanceID: 608df625aa94426b4169999
228+
instanceInfo:
229+
dbaas-cluster1.a00aa.Srv: mongodb+srv://dbaas-cluster1.a00aa.mongodb.net
230+
instanceSizeName: M0
231+
projectID: 608df5e652e1944293e11111
232+
projectName: Project 1
233+
providerName: TENANT
234+
regionName: US_EAST_1
235+
name: DBaaS-Cluster1
236+
- instanceID: 60807282b4ab8d3b3c123456
237+
instanceInfo:
238+
dbaas-cluster1.a00aa.Srv: mongodb+srv://test123.edbca.mongodb.net
239+
instanceSizeName: M10
240+
projectID: 6065e15b16c0731bf3a12333
241+
projectName: Project 2
242+
providerName: AWS
243+
regionName: US_EAST_1
244+
name: test
245+
- instanceID: 12345ffbc9a90e310e642482
246+
instanceInfo:
247+
dbaas-cluster1.a00aa.Srv: mongodb+srv://testcluster1.edbca.mongodb.net
248+
instanceSizeName: M0
249+
projectID: 6065e15b16c0731bf3a12333
250+
projectName: Project 2
251+
providerName: TENANT
252+
regionName: US_EAST_1
253+
name: DBCreatedInAtalas
254+
- instanceID: 60b7a72f4877d05881234567
255+
instanceInfo:
256+
dbaas-cluster1.a00aa.Srv: mongodb+srv://test.abcd9.mongodb.net
257+
instanceSizeName: M10
258+
projectID: 60b798fea37f9f09acc12345
259+
projectName: mytest
260+
providerName: AWS
261+
regionName: US_EAST_1
262+
name: test
263+
```
264+
**3.** Check MongoDBAtlasConnection Custom Resource
265+
266+
Now the application developer can create a [DBaaSConnection](https://github.com/RHEcosystemAppEng/dbaas-operator/blob/main/config/crd/bases/dbaas.redhat.com_dbaasconnections.yaml) CR for connection to the MongoDB database instance found, the DBaaS Operator automatically creates a MongoDBAtlasConnection CR. The Atlas Operator creates a database user in Atlas for the cluster with the default database `admin`. The Atlas Operator stores the db user credentials in a kubernetes secret, and the remaining connection information in a configmap, and then updates the MongoDBAtlasConnection CR status.
267+
268+
Here is an example of MongoDBAtlasConnection CR.
269+
```
270+
apiVersion: dbaas.redhat.com/v1alpha1
271+
kind: MongoDBAtlasConnection
272+
metadata:
273+
name: test-dbaas-connection
274+
namespace: test-namespace
275+
ownerReferences:
276+
- apiVersion: dbaas.redhat.com/v1alpha1
277+
blockOwnerDeletion: true
278+
controller: true
279+
kind: DBaaSConnection
280+
name: test-dbaas-connection
281+
uid: 77193619-6ab1-43c9-acf2-a40c2cfe7703
282+
spec:
283+
instanceID: 12345ffbc9a90e310e642482
284+
inventoryRef:
285+
name: dbaas-mytest
286+
namespace: openshift-operators
287+
status:
288+
conditions:
289+
- lastTransitionTime: "2021-08-18T20:07:51Z"
290+
message: ""
291+
reason: Ready
292+
status: "True"
293+
type: ReadyForBinding
294+
connectionInfoRef:
295+
name: atlas-connection-cm-knp9z
296+
credentialsRef:
297+
name: atlas-db-user-5pc8b
298+
```
299+
The corresponding generated secret:
300+
```
301+
apiVersion: v1
302+
data:
303+
password: cGFzczEyM3dAcmQ=
304+
username: ZGJVc2VyXzEwMQ==
305+
kind: Secret
306+
metadata:
307+
labels:
308+
managed-by: atlas-operator
309+
owner: test-dbaas-connection
310+
owner.kind: MongoDBAtlasConnection
311+
owner.namespace: test-namespace
312+
name: atlas-db-user-5pc8b
313+
namespace: test-namespace
314+
ownerReferences:
315+
- apiVersion: dbaas.redhat.com/v1alpha1
316+
blockOwnerDeletion: false
317+
controller: true
318+
kind: MongoDBAtlasConnection
319+
name: test-dbaas-connection
320+
uid: a50b06db-8fa1-45c9-9893-833a028dfccc
321+
type: Opaque
322+
```
323+
The corresponding generated configmap:
324+
```
325+
apiVersion: v1
326+
data:
327+
host: cluster0.ubajs.mongodb.net
328+
provider: Red Hat DBaaS / MongoDB Atlas
329+
srv: "true"
330+
type: mongodb
331+
kind: ConfigMap
332+
metadata:
333+
labels:
334+
managed-by: atlas-operator
335+
owner: test-dbaas-connection
336+
owner.kind: MongoDBAtlasConnection
337+
owner.namespace: test-namespace
338+
name: atlas-connection-cm-knp9z
339+
namespace: test-namespace
340+
ownerReferences:
341+
- apiVersion: dbaas.redhat.com/v1alpha1
342+
blockOwnerDeletion: false
343+
controller: true
344+
kind: MongoDBAtlasConnection
345+
name: test-dbaas-connection
346+
uid: a50b06db-8fa1-45c9-9893-833a028dfccc
347+
```
154348
## How to Contribute
155349

156350
Please file issues before filing PRs. For PRs to be accepted, contributors must sign

bundle.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LABEL operators.operatorframework.io.bundle.channels.v1=stable
1313
LABEL operators.operatorframework.io.bundle.channel.default.v1=stable
1414
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.15.0+git
1515
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
16-
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v2
16+
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v3
1717

1818
# Labels for testing.
1919
LABEL operators.operatorframework.io.test.mediatype.v1=scorecard+v1

0 commit comments

Comments
 (0)