Skip to content

Commit

Permalink
Automatically finalize the cluster with a post-install job (#108)
Browse files Browse the repository at this point in the history
Create a job after the installation to finalize the cluster. The job can also create default databases such as _global_changes.
  • Loading branch information
rileyai-dev authored Jan 17, 2023
1 parent 53d334c commit 7b52f9f
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 8 deletions.
2 changes: 1 addition & 1 deletion couchdb/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v1
name: couchdb
version: 4.0.0
version: 4.1.0
appVersion: 3.2.1
description: A database featuring seamless multi-master sync, that scales from
big data to mobile, with an intuitive HTTP/JSON API and designed for
Expand Down
4 changes: 4 additions & 0 deletions couchdb/NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# NEWS

## 4.1.0

- Added the `autoSetup` to automatically finalize the cluster after installation

## 4.0.0

- Simplified the `adminHash` in the secret
Expand Down
15 changes: 10 additions & 5 deletions couchdb/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CouchDB

![Version: 4.0.0](https://img.shields.io/badge/Version-4.0.0-informational?style=flat-square) ![AppVersion: 3.2.1](https://img.shields.io/badge/AppVersion-3.2.1-informational?style=flat-square)
![Version: 4.1.0](https://img.shields.io/badge/Version-4.1.0-informational?style=flat-square) ![AppVersion: 3.2.1](https://img.shields.io/badge/AppVersion-3.2.1-informational?style=flat-square)

Apache CouchDB is a database featuring seamless multi-master sync, that scales
from big data to mobile, with an intuitive HTTP/JSON API and designed for
Expand All @@ -18,7 +18,7 @@ storage volumes to each Pod in the Deployment.
```bash
$ helm repo add couchdb https://apache.github.io/couchdb-helm
$ helm install couchdb/couchdb \
--version=4.0.0 \
--version=4.1.0 \
--set allowAdminParty=true \
--set couchdbConfig.couchdb.uuid=$(curl https://www.uuidgenerator.net/api/version4 2>/dev/null | tr -d -)
```
Expand All @@ -44,7 +44,7 @@ Afterwards install the chart replacing the UUID
```bash
$ helm install \
--name my-release \
--version=4.0.0 \
--version=4.1.0 \
--set couchdbConfig.couchdb.uuid=decafbaddecafbaddecafbaddecafbad \
couchdb/couchdb
```
Expand Down Expand Up @@ -78,7 +78,7 @@ and then install the chart while overriding the `createAdminSecret` setting:
```bash
$ helm install \
--name my-release \
--version=4.0.0 \
--version=4.1.0 \
--set createAdminSecret=false \
--set couchdbConfig.couchdb.uuid=decafbaddecafbaddecafbaddecafbad \
couchdb/couchdb
Expand Down Expand Up @@ -133,7 +133,7 @@ version semantics. You can upgrade directly from `stable/couchdb` to this chart

```bash
$ helm repo add couchdb https://apache.github.io/couchdb-helm
$ helm upgrade my-release --version=4.0.0 couchdb/couchdb
$ helm upgrade my-release --version=4.1.0 couchdb/couchdb
```

## Configuration
Expand Down Expand Up @@ -193,6 +193,11 @@ A variety of other parameters are also configurable. See the comments in the
| `annotations` | |
| `tolerations` | |
| `resources` | |
| `autoSetup.enabled` | false (if set to true, must have `service.enabled` set to true and a correct `adminPassword` - deploy it with the `--wait` flag to avoid first jobs failure) |
| `autoSetup.image.repository` | alpine/curl |
| `autoSetup.image.tag` | latest |
| `autoSetup.image.pullPolicy` | Always |
| `autoSetup.defaultDatabases` | [`_global_changes`] |
| `service.annotations` | |
| `service.enabled` | true |
| `service.type` | ClusterIP |
Expand Down
7 changes: 6 additions & 1 deletion couchdb/README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,12 @@ A variety of other parameters are also configurable. See the comments in the
| `topologySpreadConstraints` | |
| `annotations` | |
| `tolerations` | |
| `resources` | | |
| `resources` | |
| `autoSetup.enabled` | false (if set to true, must have `service.enabled` set to true and a correct `adminPassword` - deploy it with the `--wait` flag to avoid first jobs failure) |
| `autoSetup.image.repository` | alpine/curl |
| `autoSetup.image.tag` | latest |
| `autoSetup.image.pullPolicy` | Always |
| `autoSetup.defaultDatabases` | [`_global_changes`] |
| `service.annotations` | |
| `service.enabled` | true |
| `service.type` | ClusterIP |
Expand Down
2 changes: 1 addition & 1 deletion couchdb/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Apache CouchDB is starting. Check the status of the Pods using:

kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "couchdb.name" . }},release={{ .Release.Name }}"

Once all of the Pods are fully Ready, execute the following command to create
Skip this step if autoSetup is enabled - Once all of the Pods are fully Ready, execute the following command to create
some required system databases:

kubectl exec --namespace {{ .Release.Namespace }} {{ if not .Values.allowAdminParty }}-it {{ end }}{{ template "couchdb.fullname" . }}-0 -c couchdb -- \
Expand Down
50 changes: 50 additions & 0 deletions couchdb/templates/job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{{- if .Values.autoSetup -}}
{{- if and .Values.autoSetup.enabled .Values.service.enabled -}}
apiVersion: batch/v1
kind: Job
metadata:
name: "{{ .Release.Name }}-post-install"
labels:
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
annotations:
"helm.sh/hook": post-install
spec:
template:
metadata:
name: "{{ .Release.Name }}-post-install"
labels:
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
spec:
restartPolicy: OnFailure
containers:
- name: cluster-setup
image: {{ .Values.autoSetup.image.repository }}:{{ .Values.autoSetup.image.tag }}
imagePullPolicy: {{ .Values.autoSetup.image.pullPolicy }}
command:
- 'sh'
- '-c'
- 'curl -s http://$COUCHDB_ADDRESS/_cluster_setup -X POST -H "Content-Type: application/json" -d "{\"action\": \"finish_cluster\"}" -u $COUCHDB_ADMIN:$COUCHDB_PASS && export IFS=","; for db_name in $DEFAULT_DBS; do curl -X PUT http://$COUCHDB_ADDRESS/$db_name -u $COUCHDB_ADMIN:$COUCHDB_PASS; done'
env:
- name: DEFAULT_DBS
value: {{ join "," .Values.autoSetup.defaultDatabases }}
- name: COUCHDB_ADDRESS
value: "{{ template "couchdb.svcname" . }}.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.service.externalPort}}"
- name: COUCHDB_ADMIN
valueFrom:
secretKeyRef:
name: {{ template "couchdb.fullname" . }}
key: adminUsername
- name: COUCHDB_PASS
valueFrom:
secretKeyRef:
name: {{ template "couchdb.fullname" . }}
key: adminPassword
backoffLimit: 2
ttlSecondsAfterFinished: 600
{{- end -}}
{{- end -}}
15 changes: 15 additions & 0 deletions couchdb/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ clusterSize: 3
# ref: https://kubernetes.io/docs/concepts/configuration/secret/
allowAdminParty: false

# Set it to true to automatically enable the cluster after installation.
# It will create a post-install job that will send the {"action": "finish_cluster"}
# message to CouchDB to finalize the cluster and add the defaultDatabases listed.
# Note that this job needs service.enabled to be set to true and if you use adminHash,
# a valid adminPassword in the secret. Also set the --wait flag when you install to
# avoid first jobs failure (helm install --wait ...)
autoSetup:
enabled: false
image:
repository: alpine/curl
tag: latest
pullPolicy: Always
defaultDatabases:
- _global_changes

# -- If createAdminSecret is enabled a Secret called <ReleaseName>-couchdb will
# be created containing auto-generated credentials. Users who prefer to set
# these values themselves have a couple of options:
Expand Down

0 comments on commit 7b52f9f

Please sign in to comment.