mongodbatlas-operator

module
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2019 License: Apache-2.0

README

MongoDB Atlas Kubernetes Operator

Docker Pulls Build Status Go Report Card

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

Deploy the MongoDB Atlas Project Operator:

kubectl apply -f deploy/operator.yaml
Create a MongoDB Atlas Project

Adapt the publicKey and orgID in 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

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

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

make inite2etest PRIVATE_KEY=xxxx-xxxx-xxxx-xxxx

Afterwards, you can run the end-to-end tests with

make e2etest

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:

  1. Change the version in .drone.yml and in operator.yaml according to Semantic Versioning

  2. Commit your changes (don't push)

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

Directories

Path Synopsis
cmd
manager command
pkg
apis/knappek/v1alpha1
Package v1alpha1 contains API Schema definitions for the knappek v1alpha1 API group +k8s:deepcopy-gen=package,register +groupName=knappek.com Package v1alpha1 contains API Schema definitions for the knappek v1alpha1 API group +k8s:deepcopy-gen=package,register +groupName=knappek.com
Package v1alpha1 contains API Schema definitions for the knappek v1alpha1 API group +k8s:deepcopy-gen=package,register +groupName=knappek.com Package v1alpha1 contains API Schema definitions for the knappek v1alpha1 API group +k8s:deepcopy-gen=package,register +groupName=knappek.com
test
e2e

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL