Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DBAAS-831: update DBaaSConnection status to conform to the Provisioned Service ducktype defined in the Service Binding Specification for Kubernetes #61

Draft
wants to merge 37 commits into
base: dbaas-refactor-rebased
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
26c3136
Integrate Atlas Operator with Red Hat DBaaS
May 13, 2021
3c00e2e
dbaas bundle build
tchughesiv Sep 29, 2021
d0c5997
Revert Dockerfile to use user 1001
jianrongzhang89 Oct 1, 2021
12a63d8
add RH annotations
tchughesiv Oct 6, 2021
eda1ed1
Allow MongoDBAtlasInventory spec.credentialsRef.namespace to be empty
jianrongzhang89 Oct 14, 2021
62ff49e
Support provisioning with DBaaS operator
jianrongzhang89 Jan 24, 2022
cf2b09d
Support provisioning with DBaaS operator
jianrongzhang89 Jan 28, 2022
14ff54b
Support provisioning with DBaaS operator
jianrongzhang89 Jan 28, 2022
b58e62f
Fix lint check formatting errors
jianrongzhang89 Feb 1, 2022
6ea8b53
DBAAS-287 Instance provisioning error with Atlas Project credentials …
jianrongzhang89 Feb 4, 2022
a896de8
DBAAS-291 Mitigate race conditions among different OpenShift clusters…
jianrongzhang89 Feb 8, 2022
5ad878b
DBAAS-309 Remove duplicates in the instance list for DBaaSInventory i…
jianrongzhang89 Feb 10, 2022
a34b938
DBAAS-350 AtlasProject CR deletion gets stuck if the credentials secr…
jianrongzhang89 Feb 17, 2022
0506ae9
DBAAS-368 MongoDB Database instance Provision failed
jianrongzhang89 Mar 1, 2022
eb9f1cc
Support DBaaS 0.1.4 release
jianrongzhang89 Mar 17, 2022
398dfc5
metadata only for deployment watch
tchughesiv Mar 30, 2022
1d204f8
mem limit increase
tchughesiv Mar 28, 2022
f499386
increment dbaas-operator module to 0.1.5
tchughesiv Apr 22, 2022
3765464
handle bundle upgrades
tchughesiv Apr 14, 2022
1441790
rebase fixes
tchughesiv May 24, 2022
7f7fe0e
Update client.go
priyolahiri Apr 28, 2022
34c25d7
addtl rebase fixes
tchughesiv May 24, 2022
0d0e932
Migrate MongoDBInstance from AtlasCluster to AtlasDeployment
jianrongzhang89 May 25, 2022
03c1e57
Update the release process for dbaas
fabritsius May 24, 2022
1c14e65
switch to skipRange
tchughesiv May 26, 2022
6d76611
build cleanup
tchughesiv May 26, 2022
6128988
restrict a referenced secret to the inventory namespace
tchughesiv Jun 14, 2022
f0c9d54
DBAAS-364: update the values for instance phase according to the api …
xieshenzh Aug 2, 2022
6c162c5
helpText addition to credential fields
olavtar Aug 26, 2022
38accb3
DBAAS-364: update Instance Phase field to use the constants from DBaa…
xieshenzh Aug 29, 2022
9b42a18
DBAAS-449 Potential resource/memory leak for MongoDB Atlas Operator f…
jianrongzhang89 Aug 29, 2022
1402242
DBAAS-368 MongoDB Database instance Provision failed: fix core dump i…
jianrongzhang89 Aug 30, 2022
d2f103c
update bundle
tchughesiv Aug 31, 2022
4b21e5e
fix code issues after rebasing on 8/31
jianrongzhang89 Sep 1, 2022
a83e491
Replace deprecated strings.Title with cases
jianrongzhang89 Sep 7, 2022
b145fde
Merge pull request #60 from jianrongzhang89/rebase-fix
jianrongzhang89 Sep 9, 2022
2ecfe4b
DBAAS-831: update DBaaSConnection status to conform to the Provisione…
xieshenzh Sep 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ tmp/

# ready to work samples
deploy/
__debug_bin/
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# Copy DBaaSProvider config
COPY config/dbaasprovider/dbaas_provider.yaml dbaas_provider.yaml

# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download
Expand Down Expand Up @@ -50,6 +53,7 @@ LABEL name="MongoDB Atlas Operator" \
WORKDIR /
COPY --from=builder /workspace/bin/manager .
COPY hack/licenses licenses
COPY --from=builder /workspace/dbaas_provider.yaml .

USER 1001:0
ENTRYPOINT ["/manager"]
54 changes: 32 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ CONTAINER_ENGINE?=docker
# To re-generate a bundle for another specific version without changing the standard setup, you can:
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
VERSION ?= 0.8.0
VERSION ?= 0.3.0

ifndef PRODUCT_VERSION
PRODUCT_VERSION := $(shell git describe --tags --dirty --broken)
endif

CONTAINER_ENGINE?=docker

# CHANNELS define the bundle channels used in the bundle.
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "preview,fast,stable")
# To re-generate a bundle for other specific channels without changing the standard setup, you can:
Expand All @@ -38,17 +40,19 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)

# Base registry for the operator, bundle, catalog images
REGISTRY ?= quay.io/mongodb
# BUNDLE_IMG defines the image:tag used for the bundle.
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
BUNDLE_IMG ?= $(REGISTRY)/mongodb-atlas-controller-bundle:$(VERSION)

# Image URL to use all building/pushing image targets
IMG ?= mongodb-atlas-controller:latest
#BUNDLE_REGISTRY ?= $(REGISTRY)/mongodb-atlas-operator-bundle
OPERATOR_REGISTRY ?= $(REGISTRY)/mongodb-atlas-operator
CATALOG_REGISTRY ?= $(REGISTRY)/mongodb-atlas-catalog
OPERATOR_IMAGE ?= ${OPERATOR_REGISTRY}:${VERSION}
CATALOG_IMAGE ?= ${CATALOG_REGISTRY}:${VERSION}
IMG ?= $(REGISTRY)/mongodb-atlas-kubernetes-dbaas
OPERATOR_REGISTRY ?= $(IMG)

OPERATOR_IMG ?= $(IMG):$(VERSION)
# OPERATOR_IMG ?= $(IMG):latest

BUNDLE_IMG ?= $(IMG)-bundle:$(VERSION)
# BUNDLE_IMG ?= $(IMG)-bundle:latest

CATALOG_IMG ?= $(IMG)-catalog:$(VERSION)
# CATALOG_IMG ?= ${IMG}-catalog:latest

TARGET_NAMESPACE ?= mongodb-atlas-operator-system-test
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -168,37 +172,43 @@ endef
.PHONY: bundle
bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
operator-sdk generate kustomize manifests -q --apis-dir=pkg/api
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
$(KUSTOMIZE) build --load-restrictor LoadRestrictionsNone config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
cd config/manager && $(KUSTOMIZE) edit set image controller=$(OPERATOR_IMG)
$(KUSTOMIZE) build --load-restrictor LoadRestrictionsNone config/manifests | operator-sdk generate bundle -q --overwrite --manifests --version $(VERSION) $(BUNDLE_METADATA_OPTS)
operator-sdk bundle validate ./bundle

.PHONY: image
image: manager ## Build the operator image
$(CONTAINER_ENGINE) build -t $(OPERATOR_IMAGE) .
$(CONTAINER_ENGINE) push $(OPERATOR_IMAGE)
$(CONTAINER_ENGINE) build -t $(OPERATOR_IMG) .
$(CONTAINER_ENGINE) push $(OPERATOR_IMG)

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

.PHONY: bundle-push
bundle-push:
bundle-push: ## Push the bundle image.
$(CONTAINER_ENGINE) push $(BUNDLE_IMG)

# 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).
# These images MUST exist in a registry and be pull-able.
BUNDLE_IMGS ?= $(BUNDLE_IMG)

.PHONY: catalog-build
CATALOG_DIR ?= ./scripts/openshift/atlas-catalog
#catalog-build: IMG=
catalog-build: ## bundle bundle-push ## Build file-based bundle
$(MAKE) image IMG=$(REGISTRY)/mongodb-atlas-operator:$(VERSION)
$(MAKE) image IMG=$(IMG)
CATALOG_DIR=$(CATALOG_DIR) \
CHANNEL=$(DEFAULT_CHANNEL) \
CATALOG_IMAGE=$(CATALOG_IMAGE) \
CATALOG_IMAGE=$(CATALOG_IMG) \
BUNDLE_IMAGE=$(BUNDLE_IMG) \
VERSION=$(VERSION) \
CONTAINER_ENGINE=$(CONTAINER_ENGINE) \
./scripts/build_catalog.sh

.PHONY: catalog-push
catalog-push:
$(CONTAINER_ENGINE) push $(CATALOG_IMAGE)
$(CONTAINER_ENGINE) push $(CATALOG_IMG)

.PHONY: build-subscription
build-subscription:
Expand All @@ -210,12 +220,12 @@ build-subscription:
.PHONY: build-catalogsource
build-catalogsource:
CATALOG_DIR=$(shell dirname "$(CATALOG_DIR)") \
CATALOG_IMAGE=$(CATALOG_IMAGE) \
CATALOG_IMG=$(CATALOG_IMG) \
./scripts/build_catalogsource.sh

.PHONY: deploy-olm
# Deploy atlas operator to the running openshift cluster with OLM
deploy-olm: export IMG=$(REGISTRY)/mongodb-atlas-operator:$(VERSION)
deploy-olm: export IMG=$(OPERATOR_IMAGE)
deploy-olm: bundle-build bundle-push catalog-build catalog-push build-catalogsource build-subscription
oc -n openshift-marketplace delete catalogsource mongodb-atlas-kubernetes-local --ignore-not-found
oc delete namespace $(TARGET_NAMESPACE) --ignore-not-found
Expand All @@ -231,7 +241,7 @@ deploy-olm: bundle-build bundle-push catalog-build catalog-push build-catalogsou

.PHONY: image-push
image-push: ## Push the docker image
$(CONTAINER_ENGINE) push ${IMG}
$(CONTAINER_ENGINE) push ${OPERATOR_IMG}

# Additional make goals
.PHONY: run-kind
Expand Down
30 changes: 28 additions & 2 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
domain: mongodb.com
layout:
- go.kubebuilder.io/v2
- go.kubebuilder.io/v3
plugins:
manifests.sdk.operatorframework.io/v2: {}
scorecard.sdk.operatorframework.io/v2: {}
Expand All @@ -15,7 +15,33 @@ resources:
group: atlas
kind: AtlasDeployment
path: github.com/mongodb/mongodb-atlas-kubernetes/api/v1
version: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: redhat.com
group: dbaas
kind: MongoDBAtlasConnection
path: github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/dbaas
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: redhat.com
group: dbaas
kind: MongoDBAtlasInventory
path: github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/dbaas
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: redhat.com
group: dbaas
kind: MongoDBAtlasInstance
path: github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/dbaas
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
Expand Down
194 changes: 194 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,200 @@ Operator support Third Party Integration.
- [Mongodb Atlas Operator sample](docs/project-integration.md)
- [Atlas documentation Atlas](https://docs.atlas.mongodb.com/reference/api/third-party-integration-settings/)

### Step 4. Test Database as a Service (DBaaS) on OpenShift

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).

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).

**1.** Check DBaaS Registration

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.

```
apiVersion: dbaas.redhat.com/v1alpha1
kind: DBaaSProvider
metadata:
labels:
related-to: dbaas-operator
type: dbaas-provider-registration
name: mongodb-atlas-registration
spec:
connectionKind: MongoDBAtlasConnection
credentialFields:
- displayName: Organization ID
key: orgId
required: true
type: string
- displayName: Public API Key
key: publicApiKey
required: true
type: string
- displayName: Private API Key
key: privateApiKey
required: true
type: maskedstring
inventoryKind: MongoDBAtlasInventory
provider:
displayDescription: Cloud-hosted MongoDB service on AWS, Azure and Google Cloud
displayName: MongoDB Atlas Cloud Database Service
icon:
base64data: <icon image data>
mediatype: image/png
name: Red Hat DBaaS / MongoDB Atlas
```
If the Atlas Operator is undeployed with the OLM, the above registration CR gets cleaned up automatically.

**2.** Check MongoDBAtlasInventory Custom Resource

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.
Here is an example of MongoDBAtlasInventory CR.
```
apiVersion: dbaas.redhat.com/v1alpha1
kind: MongoDBAtlasInventory
metadata:
name: dbaas-mytest
namespace: openshift-operators
ownerReferences:
- apiVersion: dbaas.redhat.com/v1alpha1
blockOwnerDeletion: true
controller: true
kind: DBaaSInventory
name: dbaas-mytest
uid: 01f5a690-c640-462f-b6e8-ccb9db95df70
spec:
credentialsRef:
name: my-atlas-key
namespace: openshift-operators
status:
conditions:
- lastTransitionTime: "2021-08-18T20:06:47Z"
message: Spec sync OK
reason: SyncOK
status: "True"
type: SpecSynced
instances:
- instanceID: 608df625aa94426b4169999
instanceInfo:
dbaas-cluster1.a00aa.Srv: mongodb+srv://dbaas-cluster1.a00aa.mongodb.net
instanceSizeName: M0
projectID: 608df5e652e1944293e11111
projectName: Project 1
providerName: TENANT
regionName: US_EAST_1
name: DBaaS-Cluster1
- instanceID: 60807282b4ab8d3b3c123456
instanceInfo:
dbaas-cluster1.a00aa.Srv: mongodb+srv://test123.edbca.mongodb.net
instanceSizeName: M10
projectID: 6065e15b16c0731bf3a12333
projectName: Project 2
providerName: AWS
regionName: US_EAST_1
name: test
- instanceID: 12345ffbc9a90e310e642482
instanceInfo:
dbaas-cluster1.a00aa.Srv: mongodb+srv://testcluster1.edbca.mongodb.net
instanceSizeName: M0
projectID: 6065e15b16c0731bf3a12333
projectName: Project 2
providerName: TENANT
regionName: US_EAST_1
name: DBCreatedInAtalas
- instanceID: 60b7a72f4877d05881234567
instanceInfo:
dbaas-cluster1.a00aa.Srv: mongodb+srv://test.abcd9.mongodb.net
instanceSizeName: M10
projectID: 60b798fea37f9f09acc12345
projectName: mytest
providerName: AWS
regionName: US_EAST_1
name: test
```
**3.** Check MongoDBAtlasConnection Custom Resource

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.

Here is an example of MongoDBAtlasConnection CR.
```
apiVersion: dbaas.redhat.com/v1alpha1
kind: MongoDBAtlasConnection
metadata:
name: test-dbaas-connection
namespace: test-namespace
ownerReferences:
- apiVersion: dbaas.redhat.com/v1alpha1
blockOwnerDeletion: true
controller: true
kind: DBaaSConnection
name: test-dbaas-connection
uid: 77193619-6ab1-43c9-acf2-a40c2cfe7703
spec:
instanceID: 12345ffbc9a90e310e642482
inventoryRef:
name: dbaas-mytest
namespace: openshift-operators
status:
conditions:
- lastTransitionTime: "2021-08-18T20:07:51Z"
message: ""
reason: Ready
status: "True"
type: ReadyForBinding
connectionInfoRef:
name: atlas-connection-cm-knp9z
credentialsRef:
name: atlas-db-user-5pc8b
```
The corresponding generated secret:
```
apiVersion: v1
data:
password: cGFzczEyM3dAcmQ=
username: ZGJVc2VyXzEwMQ==
kind: Secret
metadata:
labels:
managed-by: atlas-operator
owner: test-dbaas-connection
owner.kind: MongoDBAtlasConnection
owner.namespace: test-namespace
name: atlas-db-user-5pc8b
namespace: test-namespace
ownerReferences:
- apiVersion: dbaas.redhat.com/v1alpha1
blockOwnerDeletion: false
controller: true
kind: MongoDBAtlasConnection
name: test-dbaas-connection
uid: a50b06db-8fa1-45c9-9893-833a028dfccc
type: Opaque
```
The corresponding generated configmap:
```
apiVersion: v1
data:
host: cluster0.ubajs.mongodb.net
provider: Red Hat DBaaS / MongoDB Atlas
srv: "true"
type: mongodb
kind: ConfigMap
metadata:
labels:
managed-by: atlas-operator
owner: test-dbaas-connection
owner.kind: MongoDBAtlasConnection
owner.namespace: test-namespace
name: atlas-connection-cm-knp9z
namespace: test-namespace
ownerReferences:
- apiVersion: dbaas.redhat.com/v1alpha1
blockOwnerDeletion: false
controller: true
kind: MongoDBAtlasConnection
name: test-dbaas-connection
uid: a50b06db-8fa1-45c9-9893-833a028dfccc
```
## How to Contribute

Please file issues before filing PRs. For PRs to be accepted, contributors must sign
Expand Down
Loading