Skip to content

Commit

Permalink
Merge pull request #6573 from sapcc/postgres-ng-cron
Browse files Browse the repository at this point in the history
postgres-ng: add support for running periodic tasks via cron
  • Loading branch information
majewsky authored May 27, 2024
2 parents a8d5605 + 3b31691 commit 432616d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion common/postgresql-ng/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: postgresql-ng
version: 1.0.28 # this version number is SemVer as it gets used to auto bump
version: 1.0.29 # this version number is SemVer as it gets used to auto bump
description: Chart for PostgreSQL
keywords:
- postgresql
Expand Down
10 changes: 10 additions & 0 deletions common/postgresql-ng/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
{{- if .Values.crontab }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "postgres.fullname" . }}-crontab
data:
root: |
{{ .Values.crontab }}
{{- end }}
---
apiVersion: v1
kind: ConfigMap
Expand Down
20 changes: 19 additions & 1 deletion common/postgresql-ng/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,19 @@ spec:
- name: dev-shm
mountPath: /dev/shm
{{- end }}
{{- if .Values.crontab }}
- name: cron
image: "{{ include "preferredRegistry" . }}/shared-app-images/alpine-psql:3.20-latest"
command:
- /bin/sh
- -c
- |
/usr/bin/crontab /crontab/root
exec crond -f -d8
volumeMounts:
- name: crontab
mountPath: /crontab
{{- end }}
serviceAccountName: {{ template "postgres.fullname" . }}
volumes:
- name: postgres-etc
Expand All @@ -143,7 +156,12 @@ spec:
{{- else }}
emptyDir: {}
{{- end }}
{{- if .Values.sqlOnCreate }}
{{- if .Values.crontab }}
- name: crontab
configMap:
name: {{ template "postgres.fullname" . }}-crontab
{{- end }}
{{- if .Values.sqlOnCreate }}
- name: sql-on-create
configMap:
name: {{ template "postgres.fullname" . }}-sql-on-create
Expand Down
5 changes: 5 additions & 0 deletions common/postgresql-ng/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ users:

createMetricsUser: true

# crontab to run in a side container to execute routine maintenance tasks
# example:
# 42 23 * * * psql -tAd acme-db -c "VACUUM ANALYZE"
crontab: ""

# Persist data to a persistent volume
persistence:
enabled: true
Expand Down
2 changes: 2 additions & 0 deletions openstack/keppel/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ postgresql:
# We previously had 128, which should technically be enough for 6 API pods and 1 janitor pod (with max. 16 conns each)
# as well as the pgmetrics and pgbackup pods with 1-2 conns each, but we still had a "too many clients already" issue regardless.
max_connections: 160
crontab: |
30 14 * * 1,2,3,4,5 psql -tAd keppel -c "VACUUM ANALYZE"
persistence:
enabled: true
accessMode: ReadWriteOnce # compatibility to allow easy upgrades
Expand Down

0 comments on commit 432616d

Please sign in to comment.