Skip to content

Commit

Permalink
feat(initcontainers): add support for external db
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoreiradj committed Aug 1, 2024
1 parent 2f8c7c6 commit c2b1808
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 8 deletions.
6 changes: 3 additions & 3 deletions charts/xwiki/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ Command for the database init container
{{- define "xwiki.initContainer.database.command" -}}
{{- if .Values.initContainers.database.command }}
{{ .Values.initContainers.database.command }}
{{- else if or .Values.mysql.enabled .Values.mariadb.enabled }}
mysqladmin ping -h $DB_HOST -u $DB_USER -d $DB_DATABASE -p$DB_PASSWORD
{{- else if or .Values.postgresql.enabled }}
{{- else if or .Values.mysql.enabled .Values.mariadb.enabled (eq .Values.externalDB.type "mysql") (eq .Values.externalDB.type "mariadb") }}
mysqladmin ping -h $DB_HOST -u $DB_USER -p$DB_PASSWORD
{{- else if or .Values.postgresql.enabled (eq .Values.externalDB.type "postgresql") }}
PGPASSWORD=$DB_PASSWORD pg_isready -h $DB_HOST -U $DB_USER -d $DB_DATABASE
{{- end }}
{{- end }}
Expand Down
48 changes: 45 additions & 3 deletions charts/xwiki/tests/__snapshot__/xwiki_test.yaml.snap
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ should create a mariadb init container:
key: DB_DATABASE
name: RELEASE-NAME-xwiki
- name: CHECK_DB
value: mysqladmin ping -h $DB_HOST -u $DB_USER -d $DB_DATABASE -p$DB_PASSWORD
value: mysqladmin ping -h $DB_HOST -u $DB_USER -p$DB_PASSWORD
image: mariadb:latest
name: wait-for-db
should create a mysql init container:
Expand Down Expand Up @@ -79,7 +79,7 @@ should create a mysql init container:
key: DB_DATABASE
name: RELEASE-NAME-xwiki
- name: CHECK_DB
value: mysqladmin ping -h $DB_HOST -u $DB_USER -d $DB_DATABASE -p$DB_PASSWORD
value: mysqladmin ping -h $DB_HOST -u $DB_USER -p$DB_PASSWORD
image: mysql:latest
name: wait-for-db
should create a postgres init container:
Expand Down Expand Up @@ -148,13 +148,55 @@ should create a solr init container:
name: RELEASE-NAME-xwiki
image: alpine/curl:8.9.0
name: wait-for-solr
should create an external db init container for mysql:
1: |
- args:
- |
for i in $(seq 1 30); do
if eval $CHECK_DB; then
echo "Database is ready!"
exit 0
fi
echo "Waiting for database..."
sleep 1
done
echo "Database is not ready!"
exit 1
command:
- /bin/sh
- -ec
env:
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
key: custom-key
name: custom-secret
- name: DB_HOST
valueFrom:
configMapKeyRef:
key: DB_HOST
name: RELEASE-NAME-xwiki
- name: DB_USER
valueFrom:
configMapKeyRef:
key: DB_USER
name: RELEASE-NAME-xwiki
- name: DB_DATABASE
valueFrom:
configMapKeyRef:
key: DB_DATABASE
name: RELEASE-NAME-xwiki
- name: CHECK_DB
value: mysqladmin ping -h $DB_HOST -u $DB_USER -p$DB_PASSWORD
image: mysql:latest
name: wait-for-db
should use custom DB password secret:
1: |
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
key: custom-key
name: custom-secreat
name: custom-secret
- name: DB_HOST
valueFrom:
configMapKeyRef:
Expand Down
14 changes: 13 additions & 1 deletion charts/xwiki/tests/xwiki_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ tests:
- it: should use custom DB password secret
set:
externalDB.customKeyRef.enabled: true
externalDB.customKeyRef.name: "custom-secreat"
externalDB.customKeyRef.name: "custom-secret"
externalDB.customKeyRef.key: "custom-key"
asserts:
- matchSnapshot:
Expand Down Expand Up @@ -160,3 +160,15 @@ tests:
- matchSnapshot:
path: spec.template.spec.initContainers
template: xwiki.yaml
- it: should create an external db init container for mysql
set:
externalDB.customKeyRef.enabled: true
externalDB.customKeyRef.name: "custom-secret"
externalDB.customKeyRef.key: "custom-key"
externalDB.type: "mysql"
initContainers.database.enabled: true
initContainers.database.image: "mysql:latest"
asserts:
- matchSnapshot:
path: spec.template.spec.initContainers
template: xwiki.yaml
8 changes: 7 additions & 1 deletion charts/xwiki/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ externalDB:
user: ''
database: ''
host: ''
# If set to true default secret will not be created, use custom secret
# To set if database init containers are enabled, supported values are mysql, postgresql, mariadb
type: ''
# If set to true default secret will not be created, use custom secret
customKeyRef:
enabled: false
name: ''
Expand Down Expand Up @@ -350,6 +352,10 @@ properties:
initContainers:
database:
enabled: false
# Custom command to be executed in the init container
# command: ''
# To set when using externalDB
# image: "mysql:latest"
containerSecurityContext:
enabled: false
runAsUser: 0
Expand Down

0 comments on commit c2b1808

Please sign in to comment.