MongoDB Atlas Kubernetes Operator

Overview
A Kubernetes Operator for MongoDB Atlas with which you can manage your MongoDB Atlas projects and clusters from within Kubernetes such as you do with your containerized applications. It is built using the Operator Framework and Kubernetes Custom Resource Definitions (CRDs).
This project was inspired from the MongoDB Atlas Terraform Provider with the goal to have Kubernetes as the single source for both your (stateless) applications and MongoDB Atlas as the persistence layer. The benefit over using the Terraform provider is that mongodbatlas-operator ensures via Reconcile loops to have the desired state matching with the actual state and thus following the GitOps approach.

Scope
Currently it supports:
- Create/Delete MongoDB Atlas Projects
- Create/Delete MongoDB Atlas Clusters
Prerequisites
Getting Started
This example creates a MongoDB Atlas project and a cluster inside this project.
Init
First, create the MongoDB Atlas project CRD and some RBAC:
kubectl create -f deploy/service_account.yaml
kubectl create -f deploy/role.yaml
kubectl create -f deploy/role_binding.yaml
kubectl create -f deploy/crds/knappek_v1alpha1_mongodbatlasproject_crd.yaml
kubectl create -f deploy/crds/knappek_v1alpha1_mongodbatlascluster_crd.yaml
Create a Kubernetes secret containing the Private Key of the MongoDB Atlas Programmatic API Key
kubectl create secret generic example-monogdb-atlas-project \
--from-literal=privateKey=xxxxxxxxx
Adapt the environment variable ATLAS_PUBLIC_KEY in operator.yaml to your public key.
Deploy the MongoDB Atlas Project Operator:
kubectl apply -f deploy/operator.yaml
Create a MongoDB Atlas Project
Adapt knappek_v1alpha1_mongodbatlasproject_cr.yaml accordingly and deploy your first MongoDB Atlas Project
kubectl apply -f deploy/crds/knappek_v1alpha1_mongodbatlasproject_cr.yaml
Create a Cluster
Adapt knappek_v1alpha1_mongodbatlascluster_cr.yaml accordingly and deploy your first MongoDB Atlas Cluster
kubectl apply -f deploy/crds/knappek_v1alpha1_mongodbatlascluster_cr.yaml
List all MongoDB Atlas resources
You can easily list all MongoDB Atlas related resources with
kubectl get mongodbatlas
Cleanup
kubectl delete -f deploy/crds/knappek_v1alpha1_mongodbatlascluster_cr.yaml
kubectl delete -f deploy/crds/knappek_v1alpha1_mongodbatlasproject_cr.yaml
kubectl delete -f deploy/
kubectl delete -f deploy/crds/
Developers Build Guide
Connect to a Kubernetes cluster
export KUBECONFIG=/path/to/config
Create all CRDs that are managed by the operator
Run this once:
make init
Run Operator locally
export ATLAS_PRIVATE_KEY=xxxx-xxxx-xxxx-xxxx
export ATLAS_PUBLIC_KEY=yyyyy
make dev
Create MongoDB Atlas Project
make deploy-project
Create MongoDB Atlas Cluster
make deploy-cluster
Delete MongoDB Atlas Project and Cluster
make delete-cluster
make delete-project
Testing
Unit Tests
The following executes unit tests for the controllers in ./pkg/controller/
make test
E2E Tests
In order to run the end-to-end tests, you first have to create a namespace and a secret containing the private key of the programmatic API key pair which is needed by the Operator to perform API call against the MongoDB Atlas API.
The following command will execute the corresponding kubectl commands for you
export ATLAS_PRIVATE_KEY=xxxx-xxxx-xxxx-xxxx
make inite2etest
Afterwards, you can run the end-to-end tests with
export ATLAS_PUBLIC_KEY=yyyyy
make e2etest ORGANIZATION_ID=123456789
Contributing
Read through the Contributing Guidelines and Code of Conduct.
Create new API
This example creates a new MongoDBAtlasCluster API:
make api KIND=MongoDBAtlasCluster
Create new Controller for the API
To create a controller for the recently created API, run:
make controller KIND=MongoDBAtlasCluster
Create CRDs
make generate-openapi
Create a new Release
You need to have Collaborator permissions to perform this step
A new release will
In order to do this, follow these steps:
-
Change the version in .drone.yml and in operator.yaml according to Semantic Versioning
-
Commit your changes (don't push)
-
Create a new release using SemVer
make release VERSION=<major.minor.patch>
This will kick the CI pipeline and create a new Github Release with the version tag v<major.minor.patch>.