Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postgres-ng: add support for running periodic tasks via cron #6573

Merged
merged 2 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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