Skip to content

Commit 9c47e72

Browse files
authored
Add documentRevisionLimit value to configure the number of document revisions stored in CouchDB (#98)
* feat: Add documentRevisionLimit value to configure the number of document revisions stored in CouchDB Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com> * fix: Add random alphanumeric characters suffix to the couchdb-setup job to avoid an error when upgrading the helm chart with a new revision limit Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com> * review: Turn couchdb-setup job into a Helm hook to avoid multiple jobs running at the same time Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com> * review: Add CouchDB docs to the documentRevisionLimit value Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com> --------- Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com>
1 parent e63e86b commit 9c47e72

2 files changed

Lines changed: 45 additions & 7 deletions

File tree

charts/ecosystem/templates/couchdb-setup-job.yaml

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ apiVersion: batch/v1
88
kind: Job
99
metadata:
1010
name: "{{ .Release.Name }}-couchdb-setup"
11+
annotations:
12+
"helm.sh/hook": post-install,post-upgrade
13+
"helm.sh/hook-weight": "0"
14+
"helm.sh/hook-delete-policy": hook-succeeded
1115
spec:
1216
ttlSecondsAfterFinished: 120
1317
backoffLimit: 1
@@ -35,21 +39,49 @@ spec:
3539
- --for=condition=Ready
3640
- --timeout=90s
3741
containers:
38-
- name: create-couchdb-users-database
42+
- name: create-couchdb-users-database-and-set-revision-limits
3943
image: {{ .Values.couchdbImage }}
4044
imagePullPolicy: {{ .Values.pullPolicy }}
4145
command:
4246
- /bin/bash
4347
- -ec
4448
- |
4549
auth_header="Authorization: Basic ${GALASA_RAS_TOKEN}"
46-
db_exists_code=$(curl --silent --output /dev/null -w "%{http_code}" --head -H "${auth_header}" http://{{ .Release.Name }}-couchdb:5984/_users)
4750
48-
if [[ ${db_exists_code} == "404" ]]; then
49-
curl --silent --show-error -X PUT -H "${auth_header}" http://{{ .Release.Name }}-couchdb:5984/_users
50-
else
51-
echo "Users database already exists - OK"
52-
fi
51+
# Sets the document revision limit for a given CouchDB database
52+
# Parameters:
53+
# $1 - The name of the database to update
54+
function set_revision_limit() {
55+
database="$1"
56+
new_limit="{{ .Values.couchdb.documentRevisionLimit }}"
57+
58+
echo "Setting revision limit for database ${database} to ${new_limit}"
59+
curl --silent --show-error -X PUT -d "${new_limit}" -H "${auth_header}" http://{{ .Release.Name }}-couchdb:5984/${database}/_revs_limit
60+
rc=$?
61+
if [[ "${rc}" != "0" ]]; then
62+
echo "Failed to set revision limit. rc=${rc}"
63+
else
64+
echo "Revision limit set - OK"
65+
fi
66+
}
67+
68+
# Creates the CouchDB _users database if it does not already exist
69+
function create_users_db() {
70+
db_exists_code=$(curl --silent --output /dev/null -w "%{http_code}" --head -H "${auth_header}" http://{{ .Release.Name }}-couchdb:5984/_users)
71+
if [[ ${db_exists_code} == "404" ]]; then
72+
curl --silent --show-error -X PUT -H "${auth_header}" http://{{ .Release.Name }}-couchdb:5984/_users
73+
else
74+
echo "Users database already exists - OK"
75+
fi
76+
}
77+
78+
create_users_db
79+
80+
set_revision_limit "galasa_artifacts"
81+
set_revision_limit "galasa_log"
82+
set_revision_limit "galasa_run"
83+
set_revision_limit "galasa_tokens"
84+
set_revision_limit "galasa_users"
5385
env:
5486
- name: GALASA_RAS_TOKEN
5587
valueFrom:

charts/ecosystem/values.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,12 @@ enginecontroller:
487487
# The couchdb component stores run history and records, user records and other
488488
# persistent storage objects.
489489
couchdb:
490+
# The number of document revisions that will be stored in CouchDB for each database used by the Galasa service.
491+
# A low value will reduce disk usage and make compaction faster as there are fewer revisions to compact.
492+
# However, a low value can also cause more conflicts when replicating databases.
493+
# See https://docs.couchdb.org/en/stable/replication/conflicts.html for details around CouchDB conflicts.
494+
documentRevisionLimit: 1
495+
490496
# Best practice is to set memory limits for each pod.
491497
# This section sets some limits which Dex should be happy working within.
492498
# Omitting this resources: section will cause no memory or cpi limits to be set.

0 commit comments

Comments
 (0)