Skip to content

Commit

Permalink
Merge pull request #1647 from amazeeio/1595-postgres-helmchart
Browse files Browse the repository at this point in the history
Postgres Helmchart
  • Loading branch information
Schnitzel committed Dec 3, 2020
2 parents 3472f1b + 6b83d98 commit d7da4c6
Show file tree
Hide file tree
Showing 60 changed files with 10,657 additions and 9 deletions.
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,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-postgresql-dbaas-provider: local-dev/postgresql-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-postgresql-dbaas-provider

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

Expand Down Expand Up @@ -341,6 +344,7 @@ build-list:
all-k8s-tests-list:= nginx \
python \
drupal \
drupal-postgres \
active-standby-kubernetes \
features-kubernetes

Expand All @@ -366,6 +370,7 @@ all-controller-k8s-tests-list:= features-kubernetes \
nginx \
python \
drupal \
drupal-postgres \
active-standby-kubernetes
all-controller-k8s-tests = $(foreach image,$(all-controller-k8s-tests-list),controller-k8s-tests/$(image))

Expand Down Expand Up @@ -436,10 +441,10 @@ main-test-services = broker logs2email logs2slack logs2rocketchat logs2microsoft
openshift-test-services = openshiftremove openshiftbuilddeploy openshiftbuilddeploymonitor openshiftmisc tests-openshift

# Define a list of which Lagoon Services are needed for kubernetes testing
kubernetes-test-services = kubernetesbuilddeploy kubernetesdeployqueue kubernetesbuilddeploymonitor kubernetesjobs kubernetesjobsmonitor kubernetesremove kubernetesmisc tests-kubernetes local-registry local-dbaas-provider drush-alias
kubernetes-test-services = kubernetesbuilddeploy kubernetesdeployqueue kubernetesbuilddeploymonitor kubernetesjobs kubernetesjobsmonitor kubernetesremove kubernetesmisc tests-kubernetes local-registry local-dbaas-provider local-postgresql-dbaas-provider drush-alias

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

# List of Lagoon Services needed for webhook endpoint testing
webhooks-test-services = webhook-handler webhooks2tasks backup-handler
Expand Down Expand Up @@ -898,6 +903,7 @@ endif
local-dev/helm/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/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/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/helm --kubeconfig="$$(./local-dev/k3d get-kubeconfig --name='$(K3D_NAME)')" --kube-context='$(K3D_NAME)' upgrade --install -n dbaas-operator postgresqlprovider dbaas-operator/postgresqlprovider -f local-dev/helm-values-postgresqlprovider.yml ; \
local-dev/kubectl --kubeconfig="$$(./local-dev/k3d get-kubeconfig --name='$(K3D_NAME)')" --context='$(K3D_NAME)' create namespace lagoon-builddeploy; \
local-dev/helm/helm --kubeconfig="$$(./local-dev/k3d get-kubeconfig --name='$(K3D_NAME)')" --kube-context='$(K3D_NAME)' repo add lagoon-builddeploy https://raw.githubusercontent.com/amazeeio/lagoon-kbd/main/charts ; \
local-dev/helm/helm --kubeconfig="$$(./local-dev/k3d get-kubeconfig --name='$(K3D_NAME)')" --kube-context='$(K3D_NAME)' upgrade --install -n lagoon-builddeploy lagoon-builddeploy lagoon-builddeploy/lagoon-builddeploy \
Expand Down
13 changes: 12 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,17 @@ services:
MYSQL_ROOT_PASSWORD: 'password'
ports:
- '3306:3306'
local-postgresql-dbaas-provider:
image: ${IMAGE_REPO:-lagoon}/local-postgresql-dbaas-provider
restart: always
labels:
lagoon.type: none
environment:
POSTGRES_DB: 'postgres'
POSTGRES_USER: 'postgres'
POSTGRES_PASSWORD: 'password'
ports:
- '5432:5432'
local-minio:
image: minio/minio
entrypoint: sh
Expand Down Expand Up @@ -653,7 +664,7 @@ services:
image: ${IMAGE_REPO:-lagoon}/harbor-database
hostname: harbor-database
ports:
- '5432:5432'
- '5433:5432'
environment:
- POSTGRES_PASSWORD=test123
- POSTGRES_USER=postgres
Expand Down
47 changes: 44 additions & 3 deletions images/kubectl-build-deploy-dind/build-deploy-docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,42 @@ do
MAP_SERVICE_NAME_TO_DBAAS_ENVIRONMENT["${SERVICE_NAME}"]="${DBAAS_ENVIRONMENT}"
fi

# "postgres" is a meta service, which allows lagoon to decide itself which of the services to use:
# - postgres-single (a single postgres pod)
# - postgres-dbaas (use the dbaas shared operator)
if [ "$SERVICE_TYPE" == "postgres" ]; then
# if there is already a service existing with the service_name we assume that for this project there has been a
# postgres-single deployed (probably from the past where there was no postgres-shared yet, or postgres-dbaas) and use that one
if kubectl --insecure-skip-tls-verify -n ${NAMESPACE} get service "$SERVICE_NAME" &> /dev/null; then
SERVICE_TYPE="postgres-single"
# heck if this cluster supports the default one, if not we assume that this cluster is not capable of shared PostgreSQL and we use a postgres-single
# real basic check to see if the postgreSQLConsumer exists as a kind
elif [[ "${CAPABILITIES[@]}" =~ "postgres.amazee.io/v1/PostgreSQLConsumer" ]]; then
SERVICE_TYPE="postgres-dbaas"
else
SERVICE_TYPE="postgres-single"
fi

fi

# Previous versions of Lagoon supported "postgres-shared", this has been superseeded by "postgres-dbaas"
if [[ "$SERVICE_TYPE" == "postgres-shared" ]]; then
SERVICE_TYPE="postgres-dbaas"
fi

if [[ "$SERVICE_TYPE" == "postgres-dbaas" ]]; then
# Default plan is the enviroment type
DBAAS_ENVIRONMENT=$(cat $DOCKER_COMPOSE_YAML | shyaml get-value services.$COMPOSE_SERVICE.labels.lagoon\\.postgres-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.postgres-dbaas\\.environment false)
if [ ! $DBAAS_ENVIRONMENT_OVERRIDE == "false" ]; then
DBAAS_ENVIRONMENT=$ENVIRONMENT_DBAAS_ENVIRONMENT_OVERRIDE
fi

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

if [ "$SERVICE_TYPE" == "mongodb-shared" ]; then
MONGODB_SHARED_CLASS=$(cat $DOCKER_COMPOSE_YAML | shyaml get-value services.$COMPOSE_SERVICE.labels.lagoon\\.mongo-shared\\.class "${MONGODB_SHARED_DEFAULT_CLASS}")
MONGODB_SHARED_PLAN=$(cat $DOCKER_COMPOSE_YAML | shyaml get-value services.$COMPOSE_SERVICE.labels.lagoon\\.mongo-shared\\.plan "${ENVIRONMENT_TYPE}")
Expand Down Expand Up @@ -204,6 +240,7 @@ do
# Do not handle images for shared services
if [[ "$SERVICE_TYPE" != "mariadb-dbaas" ]] &&
[[ "$SERVICE_TYPE" != "mariadb-shared" ]] &&
[[ "$SERVICE_TYPE" != "postgres-shared" ]] &&
[[ "$SERVICE_TYPE" != "mongodb-shared" ]]; then
# Generate List of Images to build
IMAGES+=("${IMAGE_NAME}")
Expand Down Expand Up @@ -942,6 +979,10 @@ do
. /kubectl-build-deploy/scripts/exec-kubectl-mariadb-dbaas.sh
;;

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

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

Expand Down Expand Up @@ -1221,9 +1262,9 @@ do

echo "nothing to monitor for $SERVICE_TYPE"

elif [ $SERVICE_TYPE == "postgres" ]; then
# TODO: Remove
echo "nothing to monitor for $SERVICE_TYPE - for now"
elif [ $SERVICE_TYPE == "postgres-dbaas" ]; then

echo "nothing to monitor for $SERVICE_TYPE"

elif [ ! $SERVICE_ROLLOUT_TYPE == "false" ]; then
. /kubectl-build-deploy/scripts/exec-monitor-deploy.sh
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,21 @@
apiVersion: v2
name: postgres-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

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application.
appVersion: 1.16.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "postgres-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 "postgres-dbaas.fullname" -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

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

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

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

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

{{/*
Add annotations
*/}}
{{- define "postgres-dbaas.annotations" -}}
{{ if .Values.annotations }}
{{- toYaml .Values.annotations }}
{{- end }}
{{- end -}}

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

{{/*
Lagoon Labels
*/}}
{{- define "postgres-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 "postgres-dbaas" -}}
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: postgres.amazee.io/v1
kind: PostgreSQLConsumer
metadata:
name: {{ include "postgres-dbaas.fullname" . }}
labels:
{{- include "postgres-dbaas.labels" . | nindent 4 }}
annotations:
{{- include "postgres-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 postgres-dbaas.
# 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,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,21 @@
apiVersion: v2
name: postgres-single
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

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application.
appVersion: 1.16.0

0 comments on commit d7da4c6

Please sign in to comment.