feat(odoo): enhance staging environment setup and improve documentation

- Refactor staging database initialization with improved readiness checks and neutralization
- Copy filestore data during staging database clone process
- Update environment variables: replace `ODOO_DATABASE` with `DB_FILTER` in deployments
- Adjust PVC naming for clarity (`data-odoo` → `data-odoo-main`)
- Modify ingress configuration to properly enable staging ingress when enabled
- Update README installation steps for better clarity and ordering
- Add `forward-odoo-staging` task and update port-forward messages
- Grant CREATEDB privilege to CNPG owner user via postInitSQL
- Remove unused `PROXY_MODE` and `LIST_DB` from ConfigMap
This commit is contained in:
Janik von Rotz committed 2025-10-21 12:19:47 +02:00
1 parent ee886ca1a1
commit 4219ecdc70
7 files changed
+46 -52

No files matched your search

+6 -14
View File
@@ -98,6 +98,12 @@ Install the CloudNativePG chart:
task install-chart cnpg values/knd.local.yaml
```
Install ingress-nginx in the current cluster.
```bash
task install-chart ingress-nginx values/knd.local.yaml
```
Install the Odoo chart:
```bash
@@ -106,20 +112,6 @@ task install-chart odoo values/odoo.knd.local.yaml
The Odoo database will be initialized automatically.
Once the pod is ready, run this command to port forward the service:
```bash
task forward odoo
```
### Setup ingress nginx
Install ingress-nginx in the current cluster.
```bash
task install-chart ingress-nginx values/knd.local.yaml
```
Forward the ingress-nginx port.
```bash
+2 -3
View File
@@ -5,10 +5,9 @@ metadata:
labels:
app: odoo
data:
ODOO_DATABASE: {{ .Values.database }}
ADDONS_GIT_REPOS: {{ join "," .Values.addonsGitRepos | quote }}
ODOO_DATABASE: {{ .Values.database }}
ODOO_INIT_LANG: {{ .Values.initLang | quote }}
ODOO_INIT_LOGIN: {{ .Values.initLogin | quote }}
ODOO_INIT_PASSWORD: {{ .Values.initPassword | quote }}
PROXY_MODE: {{ .Values.proxyMode | quote }}
LIST_DB: {{ .Values.listDB | quote }}
DB_FILTER: {{ .Values.database }}
+2
View File
@@ -11,4 +11,6 @@ spec:
initdb:
database: {{ .Values.cnpg.database }}
owner: {{ .Values.cnpg.owner }}
postInitSQL:
- ALTER USER {{ .Values.cnpg.owner }} CREATEDB;
{{- end }}
+25 -30
View File
@@ -21,49 +21,44 @@ spec:
checksum/config: {{ include (print $.Template.BasePath "/cm.yaml") . | sha256sum }}
spec:
initContainers:
- name: wait-for-main-odoo
image: {{ .Values.image }}
imagePullPolicy: {{ .Values.imagePullPolicy }}
command:
- sh
- -c
- |
# Wait for main Odoo deployment pods to be running and ready
echo "Waiting for main Odoo deployment to be ready..."
until curl -sf http://{{ .Release.Name }}-odoo:8069/web/health > /dev/null 2>&1; do
echo "Waiting for main Odoo service to respond..."
sleep 5
done
echo "Main Odoo deployment is ready!"
- name: post-init
- name: init
image: {{ .Values.image }}
imagePullPolicy: {{ .Values.imagePullPolicy }}
command:
- /bin/bash
- -c
- |
echo "Creating staging database from template..."
echo "Waiting for main Odoo deployment to be ready..."
until curl -f http://odoo:8069/web/health > /dev/null 2>&1; do
echo "Waiting for main Odoo service to respond..."
sleep 5
done
echo "Main Odoo deployment is ready!"
# First, try to terminate any active connections to the source database
PGPASSWORD=$(cat /etc/secrets/postgresql-app/password) psql -h {{ .Release.Name }}-postgresql-rw.{{ .Release.Namespace }}.svc.cluster.local -U {{ .Values.cnpg.owner }} -d postgres -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '{{ .Values.cnpg.database }}' AND pid <> pg_backend_pid();" || true
# Check if staging database already exists and drop it
DB_EXISTS=$(PGPASSWORD=$(cat /etc/secrets/postgresql-app/password) psql -h {{ .Release.Name }}-postgresql-rw.{{ .Release.Namespace }}.svc.cluster.local -U {{ .Values.cnpg.owner }} -tAc "SELECT 1 FROM pg_database WHERE datname='{{ .Values.database }}-{{ .Values.staging.name }}';" 2>/dev/null)
echo "Clone and neutralize Odoo staging database from main database..."
echo "Check if staging database already exists and drop it..."
DB_EXISTS=$(PGPASSWORD=$PGPASSWORD psql -h $PGHOST -U $PGUSER -d postgres -tAc "SELECT 1 FROM pg_database WHERE datname='{{ .Values.database }}-{{ .Values.staging.name }}';" 2>/dev/null)
if [ "$DB_EXISTS" = "1" ]; then
echo "Terminating connections to existing staging database..."
PGPASSWORD=$(cat /etc/secrets/postgresql-app/password) psql -h {{ .Release.Name }}-postgresql-rw.{{ .Release.Namespace }}.svc.cluster.local -U {{ .Values.cnpg.owner }} -d postgres -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '{{ .Values.database }}-{{ .Values.staging.name }}' AND pid <> pg_backend_pid();" || true
PGPASSWORD=$PGPASSWORD psql -h $PGHOST -U $PGUSER -d postgres -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '{{ .Values.database }}-{{ .Values.staging.name }}' AND pid <> pg_backend_pid();" || true
echo "Dropping existing staging database..."
PGPASSWORD=$(cat /etc/secrets/postgresql-app/password) psql -h {{ .Release.Name }}-postgresql-rw.{{ .Release.Namespace }}.svc.cluster.local -U {{ .Values.cnpg.owner }} -c "DROP DATABASE {{ .Values.database }}-{{ .Values.staging.name }};"
PGPASSWORD=$PGPASSWORD psql -h $PGHOST -U $PGUSER -d postgres -c "DROP DATABASE {{ .Values.database }}-{{ .Values.staging.name }};"
fi
# Create staging database from template (much faster than dump/restore)
echo "Creating database from template..."
PGPASSWORD=$(cat /etc/secrets/postgresql-app/password) psql -h {{ .Release.Name }}-postgresql-rw.{{ .Release.Namespace }}.svc.cluster.local -U {{ .Values.cnpg.owner }} -c "CREATE DATABASE \"{{ .Values.database }}-{{ .Values.staging.name }}\" WITH TEMPLATE \"{{ .Values.cnpg.database }}\";"
echo "Terminate any active connections to the source database..."
PGPASSWORD=$PGPASSWORD psql -h $PGHOST -U $PGUSER -d postgres -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '{{ .Values.cnpg.database }}' AND pid <> pg_backend_pid();" || true
echo "Copying staging database with template..."
PGPASSWORD=$PGPASSWORD psql -h $PGHOST -U $PGUSER -d postgres -c "CREATE DATABASE \"{{ .Values.database }}-{{ .Values.staging.name }}\" WITH TEMPLATE \"{{ .Values.cnpg.database }}\";"
# Neutralize the staging database using Odoo's neutralize command
echo "Neutralizing staging database with Odoo neutralize command..."
odoo -d {{ .Values.database }}-{{ .Values.staging.name }} --neutralize --stop-after-init
echo "Database creation from template and neutralization completed for {{ .Values.staging.name }}."
odoo neutralize -d {{ .Values.database }}-{{ .Values.staging.name }} --stop-after-init
echo "Copy filestore from /main-data/ to /staging-data ..."
mkdir -p /staging-data/filestore
cp -r /main-data/filestore/{{ .Values.database }} /staging-data/filestore/{{ .Values.database }}-{{ .Values.staging.name }}
echo "Clone and and neutralization staging database completed for {{ .Values.staging.name }}."
envFrom:
- configMapRef:
name: {{ .Release.Name }}-configmap
@@ -154,7 +149,7 @@ spec:
- configMapRef:
name: {{ .Release.Name }}-configmap
env:
- name: ODOO_DATABASE
- name: DB_FILTER
value: {{ .Values.database }}-{{ .Values.staging.name }}
{{- if .Values.cnpg.enabled }}
- name: PGHOST
+2 -2
View File
@@ -74,8 +74,7 @@ spec:
{{- end }}
secretName: odoo-tls
{{- end }}
{{- end }}
{{- if and .Values.staging.enabled .Values.ingress.enabled }}
{{- if and .Values.staging.enabled }}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
@@ -115,4 +114,5 @@ spec:
- {{ .Values.staging.name }}.{{ .Values.ingress.host }}
secretName: odoo-{{ .Values.staging.name }}-tls
{{- end }}
{{- end }}
{{- end }}
+1 -1
View File
@@ -1,7 +1,7 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data-odoo
name: data-odoo-main
spec:
accessModes:
- ReadWriteOnce
+8 -2
View File
@@ -307,14 +307,20 @@ function forward-postgres() {
}
function forward-odoo() {
PORT=8069
PORT=8080
echo "Open http://localhost:$PORT url in your browser."
kubectl port-forward service/odoo $PORT:8069
}
function forward-odoo-staging() {
PORT=8080
echo "Open http://localhost:$PORT url in your browser."
kubectl port-forward service/odoo-staging $PORT:8069
}
function forward-ingress-nginx() {
PORT=8080
echo "Open http://odoo.knd.local:$PORT or http://odoo.local:$PORT url in your browser."
echo "Open http://staging.odoo.knd.local:$PORT or http://odoo.knd.local:$PORT or http://odoo.local:$PORT url in your browser."
kubectl port-forward -n ingress-nginx svc/ingress-nginx-controller $PORT:80
}