Skip to content

Commit

Permalink
Add Mongodb DBAAS operator (PR2403 & PR2411) (#2416)
Browse files Browse the repository at this point in the history
  • Loading branch information
Toby Bellwood authored Feb 10, 2021
1 parent bdf71d5 commit ee09835
Show file tree
Hide file tree
Showing 44 changed files with 1,589 additions and 17 deletions.
22 changes: 14 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,15 @@ build/local-git: local-dev/git/Dockerfile
build/local-api-data-watcher-pusher: local-dev/api-data-watcher-pusher/Dockerfile
build/local-registry: local-dev/registry/Dockerfile
build/local-dbaas-provider: local-dev/dbaas-provider/Dockerfile
build/local-mongodb-dbaas-provider: local-dev/mongodb-dbaas-provider/Dockerfile

# Images for local helpers that exist in another folder than the service images
localdevimages := local-git \
local-api-data-watcher-pusher \
local-registry \
local-dbaas-provider
local-dbaas-provider \
local-mongodb-dbaas-provider

service-images += $(localdevimages)
build-localdevimages = $(foreach image,$(localdevimages),build/$(image))

Expand Down Expand Up @@ -307,7 +310,8 @@ all-k8s-tests-list:= nginx \
drupal-php74 \
python \
active-standby-kubernetes \
features-kubernetes
features-kubernetes \
node-mongodb

all-k8s-tests = $(foreach image,$(all-k8s-tests-list),k8s-tests/$(image))

Expand Down Expand Up @@ -357,7 +361,8 @@ all-openshift-tests-list:= features-openshift \
bitbucket \
nginx \
elasticsearch \
active-standby-openshift
active-standby-openshift \
node-mongodb
all-openshift-tests = $(foreach image,$(all-openshift-tests-list),openshift-tests/$(image))

.PHONY: openshift-tests
Expand All @@ -377,10 +382,10 @@ wait-for-keycloak:
main-test-services = broker logs2email logs2slack logs2rocketchat logs2microsoftteams api api-db api-redis keycloak keycloak-db ssh auth-server local-git local-api-data-watcher-pusher local-minio

# Define a list of which Lagoon Services are needed for openshift testing
openshift-test-services = openshiftremove openshiftbuilddeploy openshiftbuilddeploymonitor openshiftmisc tests-openshift
openshift-test-services = openshiftremove openshiftbuilddeploy openshiftbuilddeploymonitor openshiftmisc tests-openshift local-dbaas-provider local-mongodb-dbaas-provider

# Define a list of which Lagoon Services are needed for kubernetes testing
k8s-test-services = controllerhandler tests-kubernetes local-registry local-dbaas-provider drush-alias
k8s-test-services = controllerhandler tests-kubernetes local-registry local-dbaas-provider local-mongodb-dbaas-provider drush-alias

# List of Lagoon Services needed for webhook endpoint testing
webhooks-test-services = webhook-handler webhooks2tasks backup-handler
Expand All @@ -392,7 +397,7 @@ drupal-test-services = drush-alias
webhook-tests = github gitlab bitbucket

# All Tests that use API endpoints
api-tests = node features-openshift features-kubernetes nginx elasticsearch active-standby-openshift active-standby-kubernetes
api-tests = node features-openshift features-kubernetes nginx elasticsearch active-standby-openshift active-standby-kubernetes node-mongodb

# All drupal tests
drupal-tests = drupal-php72 drupal-php73 drupal-php74 drupal-postgres
Expand Down Expand Up @@ -800,9 +805,10 @@ endif
local-dev/helm --kubeconfig="$$(./local-dev/k3d get-kubeconfig --name='$(K3D_NAME)')" --kube-context='$(K3D_NAME)' repo add dioscuri https://raw.githubusercontent.com/amazeeio/dioscuri/main/charts ; \
local-dev/helm --kubeconfig="$$(./local-dev/k3d get-kubeconfig --name='$(K3D_NAME)')" --kube-context='$(K3D_NAME)' upgrade --install -n dioscuri dioscuri dioscuri/dioscuri ; \
local-dev/kubectl --kubeconfig="$$(./local-dev/k3d get-kubeconfig --name='$(K3D_NAME)')" --context='$(K3D_NAME)' create namespace dbaas-operator; \
local-dev/helm --kubeconfig="$$(./local-dev/k3d get-kubeconfig --name='$(K3D_NAME)')" --kube-context='$(K3D_NAME)' repo add dbaas-operator https://raw.githubusercontent.com/amazeeio/dbaas-operator/master/charts ; \
local-dev/helm --kubeconfig="$$(./local-dev/k3d get-kubeconfig --name='$(K3D_NAME)')" --kube-context='$(K3D_NAME)' repo add dbaas-operator https://raw.githubusercontent.com/amazeeio/dbaas-operator/main/charts ; \
local-dev/helm --kubeconfig="$$(./local-dev/k3d get-kubeconfig --name='$(K3D_NAME)')" --kube-context='$(K3D_NAME)' upgrade --install -n dbaas-operator dbaas-operator dbaas-operator/dbaas-operator ; \
local-dev/helm --kubeconfig="$$(./local-dev/k3d get-kubeconfig --name='$(K3D_NAME)')" --kube-context='$(K3D_NAME)' upgrade --install -n dbaas-operator mariadbprovider dbaas-operator/mariadbprovider -f local-dev/helm-values-mariadbprovider.yml ; \
local-dev/helm --kubeconfig="$$(./local-dev/k3d get-kubeconfig --name='$(K3D_NAME)')" --kube-context='$(K3D_NAME)' upgrade --install -n dbaas-operator mongodbprovider dbaas-operator/mongodbprovider -f local-dev/helm-values-mongodbprovider.yml ; \
local-dev/kubectl --kubeconfig="$$(./local-dev/k3d get-kubeconfig --name='$(K3D_NAME)')" --context='$(K3D_NAME)' create namespace harbor; \
local-dev/helm --kubeconfig="$$(./local-dev/k3d get-kubeconfig --name='$(K3D_NAME)')" --kube-context='$(K3D_NAME)' repo add harbor https://helm.goharbor.io ; \
local-dev/helm --kubeconfig="$$(./local-dev/k3d get-kubeconfig --name='$(K3D_NAME)')" --kube-context='$(K3D_NAME)' upgrade --install -n harbor harbor harbor/harbor -f local-dev/helm-values-harbor.yml ; \
Expand Down Expand Up @@ -928,7 +934,7 @@ api-development: build/api build/api-db build/local-api-data-watcher-pusher buil
KIND_VERSION = v0.10.0
GOJQ_VERSION = v0.11.2
KIND_IMAGE = kindest/node:v1.20.2@sha256:8f7ea6e7642c0da54f04a7ee10431549c0257315b3a634f6ef2fecaaedb19bab
TESTS = [api,features-kubernetes,nginx,drupal-php73,drupal-php74,drupal-postgres,python,gitlab,github,bitbucket]
TESTS = [api,features-kubernetes,nginx,drupal-php73,drupal-php74,drupal-postgres,python,gitlab,github,bitbucket,node-mongodb]
CHARTS_TREEISH = main

local-dev/kind:
Expand Down
7 changes: 7 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ services:
MYSQL_ROOT_PASSWORD: 'password'
ports:
- '3306:3306'
local-mongodb-dbaas-provider:
image: ${IMAGE_REPO:-lagoon}/local-mongodb-dbaas-provider
restart: always
labels:
lagoon.type: none
ports:
- '27017:27017'
local-minio:
image: minio/minio
entrypoint: sh
Expand Down
35 changes: 35 additions & 0 deletions images/kubectl-build-deploy-dind/build-deploy-docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,31 @@ do
fi
fi

if [[ "$SERVICE_TYPE" == "mongodb-dbaas" ]]; then
# Default plan is the enviroment type
DBAAS_ENVIRONMENT=$(cat $DOCKER_COMPOSE_YAML | shyaml get-value services.$COMPOSE_SERVICE.labels.lagoon\\.mongodb-dbaas\\.environment "${ENVIRONMENT_TYPE}")

# Allow the dbaas shared servicebroker plan to be overriden by environment in .lagoon.yml
ENVIRONMENT_DBAAS_ENVIRONMENT_OVERRIDE=$(cat .lagoon.yml | shyaml get-value environments.${BRANCH//./\\.}.overrides.$SERVICE_NAME.mongodb-dbaas\\.environment false)
if [ ! $DBAAS_ENVIRONMENT_OVERRIDE == "false" ]; then
DBAAS_ENVIRONMENT=$ENVIRONMENT_DBAAS_ENVIRONMENT_OVERRIDE
fi

# If we have a dbaas environment type override in the api, consume it here
if [ ! -z "$LAGOON_DBAAS_ENVIRONMENT_TYPES" ]; then
IFS=',' read -ra LAGOON_DBAAS_ENVIRONMENT_TYPES_SPLIT <<< "$LAGOON_DBAAS_ENVIRONMENT_TYPES"
for LAGOON_DBAAS_ENVIRONMENT_TYPE in "${LAGOON_DBAAS_ENVIRONMENT_TYPES_SPLIT[@]}"
do
IFS=':' read -ra LAGOON_DBAAS_ENVIRONMENT_TYPE_SPLIT <<< "$LAGOON_DBAAS_ENVIRONMENT_TYPE"
if [ "${LAGOON_DBAAS_ENVIRONMENT_TYPE_SPLIT[0]}" == "$SERVICE_NAME" ]; then
DBAAS_ENVIRONMENT=${LAGOON_DBAAS_ENVIRONMENT_TYPE_SPLIT[1]}
fi
done
fi

MAP_SERVICE_NAME_TO_DBAAS_ENVIRONMENT["${SERVICE_NAME}"]="${DBAAS_ENVIRONMENT}"
fi

if [ "$SERVICE_TYPE" == "none" ]; then
continue
fi
Expand All @@ -245,6 +270,8 @@ do
if [[ "$SERVICE_TYPE" != "mariadb-dbaas" ]] &&
[[ "$SERVICE_TYPE" != "mariadb-shared" ]] &&
[[ "$SERVICE_TYPE" != "postgres-shared" ]] &&
[[ "$SERVICE_TYPE" != "postgres-dbaas" ]] &&
[[ "$SERVICE_TYPE" != "mongodb-dbaas" ]] &&
[[ "$SERVICE_TYPE" != "mongodb-shared" ]]; then
# Generate List of Images to build
IMAGES+=("${IMAGE_NAME}")
Expand Down Expand Up @@ -1336,6 +1363,10 @@ do
. /kubectl-build-deploy/scripts/exec-kubectl-postgres-dbaas.sh
;;

mongodb-dbaas)
. /kubectl-build-deploy/scripts/exec-kubectl-mongodb-dbaas.sh
;;

*)
echo "DBAAS Type ${SERVICE_TYPE} not implemented"; exit 1;

Expand Down Expand Up @@ -1548,6 +1579,10 @@ do

echo "nothing to monitor for $SERVICE_TYPE"

elif [ $SERVICE_TYPE == "mongodb-dbaas" ]; then

echo "nothing to monitor for $SERVICE_TYPE"

elif [ ! $SERVICE_ROLLOUT_TYPE == "false" ]; then
. /kubectl-build-deploy/scripts/exec-monitor-deploy.sh
fi
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v2
name: mongodb-dbaas
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
version: 0.1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "mongodb-dbaas.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "mongodb-dbaas.fullname" -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "mongodb-dbaas.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create full hostname for autogenerated hosts
*/}}
{{- define "mongodb-dbaas.autogeneratedHost" -}}
{{- printf "%s.%s" .Release.Name .Values.routesAutogenerateSuffix | trimSuffix "-" -}}
{{- end -}}

{{- define "mongodb-dbaas.fullnameUppercase" -}}
{{ include "mongodb-dbaas.fullname" . | upper | replace "-" "_" }}
{{- end -}}

{{/*
Common labels
*/}}
{{- define "mongodb-dbaas.labels" -}}
helm.sh/chart: {{ include "mongodb-dbaas.chart" . }}
{{ include "mongodb-dbaas.selectorLabels" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{ include "mongodb-dbaas.lagoonLabels" . }}

{{- end -}}

{{/*
Selector labels
*/}}
{{- define "mongodb-dbaas.selectorLabels" -}}
app.kubernetes.io/name: {{ include "mongodb-dbaas.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}

{{/*
Lagoon Labels
*/}}
{{- define "mongodb-dbaas.lagoonLabels" -}}
lagoon.sh/service: {{ .Release.Name }}
lagoon.sh/service-type: {{ .Chart.Name }}
lagoon.sh/project: {{ .Values.project }}
lagoon.sh/environment: {{ .Values.environment }}
lagoon.sh/environmentType: {{ .Values.environmentType }}
lagoon.sh/buildType: {{ .Values.buildType }}
{{- end -}}

{{/*
Annotations
*/}}
{{- define "mongodb-dbaas.annotations" -}}
lagoon.sh/version: {{ .Values.lagoonVersion | quote }}
{{- if .Values.branch }}
lagoon.sh/branch: {{ .Values.branch | quote }}
{{- end }}
{{- if .Values.prNumber }}
lagoon.sh/prNumber: {{ .Values.prNumber | quote }}
lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }}
lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }}
{{- end }}
{{- end -}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: mongodb.amazee.io/v1
kind: MongoDBConsumer
metadata:
name: {{ include "mongodb-dbaas.fullname" . }}
labels:
{{- include "mongodb-dbaas.labels" . | nindent 4 }}
annotations:
{{- include "mongodb-dbaas.annotations" . | nindent 4 }}

spec:
environment: {{ .Values.environment}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Default values for nginx.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

environment: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# The operator can sometimes take a bit, wait until the details are available
# We added a timeout of 10 minutes (120 retries) before exit
OPERATOR_COUNTER=1
OPERATOR_TIMEOUT=180
# use the secret name from the consumer to prevent credential clash
until kubectl --insecure-skip-tls-verify -n ${NAMESPACE} get mongodbconsumer/${SERVICE_NAME} -o yaml | shyaml get-value spec.consumer.database
do
if [ $OPERATOR_COUNTER -lt $OPERATOR_TIMEOUT ]; then
let SERVICE_BROKER_COUNTER=SERVICE_BROKER_COUNTER+1
echo "Service for ${SERVICE_NAME} not available yet, waiting for 5 secs"
sleep 5
else
echo "Timeout of $OPERATOR_TIMEOUT for ${SERVICE_NAME} creation reached"
exit 1
fi
done
set +x
# Grab the details from the consumer spec
DB_HOST=$(kubectl --insecure-skip-tls-verify -n ${NAMESPACE} get mongodbconsumer/${SERVICE_NAME} -o yaml | shyaml get-value spec.consumer.services.primary)
DB_USER=$(kubectl --insecure-skip-tls-verify -n ${NAMESPACE} get mongodbconsumer/${SERVICE_NAME} -o yaml | shyaml get-value spec.consumer.username)
DB_PASSWORD=$(kubectl --insecure-skip-tls-verify -n ${NAMESPACE} get mongodbconsumer/${SERVICE_NAME} -o yaml | shyaml get-value spec.consumer.password)
DB_NAME=$(kubectl --insecure-skip-tls-verify -n ${NAMESPACE} get mongodbconsumer/${SERVICE_NAME} -o yaml | shyaml get-value spec.consumer.database)
DB_PORT=$(kubectl --insecure-skip-tls-verify -n ${NAMESPACE} get mongodbconsumer/${SERVICE_NAME} -o yaml | shyaml get-value spec.provider.port)
DB_AUTHSOURCE=$(kubectl --insecure-skip-tls-verify -n ${NAMESPACE} get mongodbconsumer/${SERVICE_NAME} -o yaml | shyaml get-value spec.provider.auth.source)
DB_AUTHMECHANISM=$(kubectl --insecure-skip-tls-verify -n ${NAMESPACE} get mongodbconsumer/${SERVICE_NAME} -o yaml | shyaml get-value spec.provider.auth.mechanism)
DB_AUTHTLS=$(kubectl --insecure-skip-tls-verify -n ${NAMESPACE} get mongodbconsumer/${SERVICE_NAME} -o yaml | shyaml get-value spec.provider.auth.tls)

# Add credentials to our configmap, prefixed with the name of the servicename of this servicebroker
kubectl patch --insecure-skip-tls-verify \
-n ${NAMESPACE} \
configmap lagoon-env \
-p "{\"data\":{\"${SERVICE_NAME_UPPERCASE}_HOST\":\"${DB_HOST}\", \"${SERVICE_NAME_UPPERCASE}_USERNAME\":\"${DB_USER}\", \"${SERVICE_NAME_UPPERCASE}_PASSWORD\":\"${DB_PASSWORD}\", \"${SERVICE_NAME_UPPERCASE}_DATABASE\":\"${DB_NAME}\", \"${SERVICE_NAME_UPPERCASE}_PORT\":\"${DB_PORT}\", \"${SERVICE_NAME_UPPERCASE}_AUTHSOURCE\":\"${DB_AUTHSOURCE}\", \"${SERVICE_NAME_UPPERCASE}_AUTHMECHANISM\":\"${DB_AUTHMECHANISM}\", \"${SERVICE_NAME_UPPERCASE}_AUTHTLS\":\"${DB_AUTHTLS}\" }}"

set -x
36 changes: 35 additions & 1 deletion images/oc-build-deploy-dind/build-deploy-docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,31 @@ do
fi
fi

if [[ "$SERVICE_TYPE" == "mongodb-dbaas" ]]; then
# Default plan is the enviroment type
DBAAS_ENVIRONMENT=$(cat $DOCKER_COMPOSE_YAML | shyaml get-value services.$COMPOSE_SERVICE.labels.lagoon\\.$SERVICE_TYPE\\.environment "${ENVIRONMENT_TYPE}")

# Allow the dbaas shared servicebroker plan to be overriden by environment in .lagoon.yml
ENVIRONMENT_DBAAS_ENVIRONMENT_OVERRIDE=$(cat .lagoon.yml | shyaml get-value environments.${BRANCH}.overrides.$SERVICE_NAME.$SERVICE_TYPE\\.environment false)
if [ ! $DBAAS_ENVIRONMENT_OVERRIDE == "false" ]; then
DBAAS_ENVIRONMENT=$ENVIRONMENT_DBAAS_ENVIRONMENT_OVERRIDE
fi

# If we have a dbaas environment type override in the api, consume it here
if [ ! -z "$LAGOON_DBAAS_ENVIRONMENT_TYPES" ]; then
IFS=',' read -ra LAGOON_DBAAS_ENVIRONMENT_TYPES_SPLIT <<< "$LAGOON_DBAAS_ENVIRONMENT_TYPES"
for LAGOON_DBAAS_ENVIRONMENT_TYPE in "${LAGOON_DBAAS_ENVIRONMENT_TYPES_SPLIT[@]}"
do
IFS=':' read -ra LAGOON_DBAAS_ENVIRONMENT_TYPE_SPLIT <<< "$LAGOON_DBAAS_ENVIRONMENT_TYPE"
if [ "${LAGOON_DBAAS_ENVIRONMENT_TYPE[0]}" == "$SERVICE_NAME" ]; then
DBAAS_ENVIRONMENT_TYPE=${LAGOON_DBAAS_ENVIRONMENT_TYPE[1]}
fi
done
fi

MAP_SERVICE_NAME_TO_DBAAS_ENVIRONMENT["${SERVICE_NAME}"]="$DBAAS_ENVIRONMENT"
fi

if [ "$SERVICE_TYPE" == "none" ]; then
continue
fi
Expand All @@ -240,7 +265,8 @@ do
# Do not handle images for shared services
if [[ "$SERVICE_TYPE" != "mariadb-dbaas" ]] &&
[[ "$SERVICE_TYPE" != "mariadb-shared" ]] &&
[[ "$SERVICE_TYPE" != "mongodb-shared" ]]; then
[[ "$SERVICE_TYPE" != "mongodb-shared" ]] &&
[[ "$SERVICE_TYPE" != "mongodb-dbaas" ]]; then
# Generate List of Images to build
IMAGES+=("${IMAGE_NAME}")
fi
Expand Down Expand Up @@ -1034,6 +1060,10 @@ do
set -x
;;

mongodb-dbaas)
. /oc-build-deploy/scripts/exec-openshift-mongodb-dbaas.sh
;;

*)
echo "ServiceBroker Type ${SERVICE_TYPE} not implemented"; exit 1;

Expand Down Expand Up @@ -1346,6 +1376,10 @@ do

echo "nothing to monitor for $SERVICE_TYPE"

elif [ $SERVICE_TYPE == "mongodb-dbaas" ]; then

echo "nothing to monitor for $SERVICE_TYPE"

elif [ ! $SERVICE_ROLLOUT_TYPE == "false" ]; then
. /oc-build-deploy/scripts/exec-monitor-deploy.sh
fi
Expand Down
Loading

0 comments on commit ee09835

Please sign in to comment.