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

ParadeDB Support #1

Merged
merged 10 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
3 changes: 2 additions & 1 deletion charts/cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ refer to the [CloudNativePG Documentation](https://cloudnative-pg.io/documentat
| recovery.s3.secretKey | string | `""` | |
| recovery.secret.create | bool | `true` | Whether to create a secret for the backup credentials |
| recovery.secret.name | string | `""` | Name of the backup credentials secret |
| type | string | `"postgresql"` | Type of the CNPG database. Available types: * `postgresql` * `postgis` * `timescaledb` |
| type | string | `"postgresql"` | Type of the CNPG database. Available types: * `postgresql` * `postgis` * `timescaledb` * `paradedb` |
| version.paradedb | string | `"0.9.3"` | If using ParadeDB, specify the version |
| version.postgis | string | `"3.4"` | If using PostGIS, specify the version |
| version.postgresql | string | `"16"` | PostgreSQL major version to use |
| version.timescaledb | string | `"2.15"` | If using TimescaleDB, specify the version |
Expand Down
2 changes: 2 additions & 0 deletions charts/cluster/README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ Cluster Configuration
Currently the chart supports two database types. These are configured via the `type` parameter. These are:
* `postgresql` - A standard PostgreSQL database.
* `postgis` - A PostgreSQL database with the PostGIS extension installed.
* `timescaledb` - A PostgreSQL database with the TimescaleDB extension installed.
* `paradedb` - A PostgreSQL database with the ParadeDB extension installed.
philippemnoel marked this conversation as resolved.
Show resolved Hide resolved

Depending on the type the chart will use a different Docker image and fill in some initial setup, like extension installation.

Expand Down
29 changes: 25 additions & 4 deletions charts/cluster/templates/_bootstrap.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
bootstrap:
initdb:
{{- with .Values.cluster.initdb }}
{{- with (omit . "postInitApplicationSQL") }}
{{- with (omit . "postInitApplicationSQL" "postInitTemplateSQL") }}
{{- . | toYaml | nindent 4 }}
{{- end }}
{{- end }}
Expand All @@ -15,11 +15,32 @@ bootstrap:
- CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder;
{{- else if eq .Values.type "timescaledb" }}
- CREATE EXTENSION IF NOT EXISTS timescaledb;
{{- else if eq .Values.type "paradedb" }}
- CREATE EXTENSION IF NOT EXISTS pg_search;
- CREATE EXTENSION IF NOT EXISTS pg_analytics;
- CREATE EXTENSION IF NOT EXISTS pg_ivm;
- CREATE EXTENSION IF NOT EXISTS vector;
- CREATE EXTENSION IF NOT EXISTS vectorscale;
- ALTER DATABASE "{{ default "app" .Values.cluster.initdb.database }}" SET search_path TO public,paradedb;
{{- end }}
{{- with .Values.cluster.initdb }}
{{- range .postInitApplicationSQL }}
{{- printf "- %s" . | nindent 6 }}
{{- end -}}
{{- range .postInitApplicationSQL }}
{{- printf "- %s" . | nindent 6 }}
{{- end -}}
{{- end }}
postInitTemplateSQL:
{{- if eq .Values.type "paradedb" }}
- CREATE EXTENSION IF NOT EXISTS pg_search;
- CREATE EXTENSION IF NOT EXISTS pg_analytics;
- CREATE EXTENSION IF NOT EXISTS pg_ivm;
- CREATE EXTENSION IF NOT EXISTS vector;
- CREATE EXTENSION IF NOT EXISTS vectorscale;
- ALTER DATABASE template1 SET search_path TO public,paradedb;
itay-grudev marked this conversation as resolved.
Show resolved Hide resolved
{{- end }}
{{- with .Values.cluster.initdb }}
{{- range .postInitTemplateSQL }}
{{- printf "- %s" . | nindent 6 }}
{{- end -}}
{{- end -}}
{{- else if eq .Values.mode "recovery" -}}
bootstrap:
Expand Down
2 changes: 2 additions & 0 deletions charts/cluster/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ If a custom imageName is available, use it, otherwise use the defaults based on
{{- printf "ghcr.io/cloudnative-pg/postgresql:%s" .Values.version.postgresql -}}
{{- else if eq .Values.type "postgis" -}}
{{- printf "ghcr.io/cloudnative-pg/postgis:%s-%s" .Values.version.postgresql .Values.version.postgis -}}
{{- else if eq .Values.type "paradedb" -}}
{{- printf "paradedb/paradedb:%s-v%s" .Values.version.postgresql .Values.version.paradedb -}}
{{- else -}}
{{ fail "Invalid cluster type!" }}
{{- end }}
Expand Down
4 changes: 4 additions & 0 deletions charts/cluster/templates/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ spec:
shared_preload_libraries:
{{- if eq .Values.type "timescaledb" }}
- timescaledb
{{- else if eq .Values.type "paradedb" }}
- pg_search
- pg_analytics
- pg_cron
{{- end }}
{{- with .Values.cluster.postgresql.shared_preload_libraries }}
{{- toYaml . | nindent 6 }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: batch/v1
kind: Job
metadata:
name: minio-cleanup
status:
succeeded: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: batch/v1
kind: Job
metadata:
name: minio-cleanup
spec:
template:
spec:
restartPolicy: OnFailure
containers:
- name: minio-cleanup
image: minio/mc
command: ['sh', '-c']
args:
- |
mc alias set myminio https://minio.minio.svc.cluster.local minio minio123
mc rm --recursive --force myminio/mybucket/paradedb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: paradedb-cluster
status:
readyInstances: 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
type: paradedb
mode: standalone
cluster:
instances: 2
storage:
size: 256Mi

backups:
enabled: true
provider: s3
endpointURL: "https://minio.minio.svc.cluster.local"
endpointCA:
name: kube-root-ca.crt
key: ca.crt
wal:
encryption: ""
data:
encryption: ""
s3:
bucket: "mybucket"
path: "/paradedb/v1"
accessKey: "minio"
secretKey: "minio123"
region: "local"
scheduledBackups: []
retentionPolicy: "30d"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: batch/v1
kind: Job
metadata:
name: paradedb-write
status:
succeeded: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: batch/v1
philippemnoel marked this conversation as resolved.
Show resolved Hide resolved
kind: Job
metadata:
name: paradedb-write
spec:
template:
spec:
restartPolicy: OnFailure
containers:
- name: data-write
env:
- name: DB_URI
valueFrom:
secretKeyRef:
name: paradedb-cluster-app
key: uri
image: alpine:3.19
command: ['sh', '-c']
args:
- |
apk --no-cache add postgresql-client
psql "$DB_URI" <<-EOSQL
CALL paradedb.create_bm25_test_table( schema_name => 'public', table_name => 'mock_items' );
CALL paradedb.create_bm25(
index_name => 'search_idx',
schema_name => 'public',
table_name => 'mock_items',
key_field => 'id',
text_fields => paradedb.field('description', tokenizer => paradedb.tokenizer('en_stem')) ||
paradedb.field('category'),
numeric_fields => paradedb.field('rating')
);
EOSQL


philippemnoel marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: batch/v1
kind: Job
metadata:
name: paradedb-test
status:
succeeded: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: batch/v1
kind: Job
metadata:
name: paradedb-test
spec:
template:
spec:
restartPolicy: OnFailure
containers:
- name: data-test
env:
- name: DB_URI
valueFrom:
secretKeyRef:
name: paradedb-cluster-app
key: uri
image: alpine:3.19
command: ['sh', '-c']
args:
- |
apk --no-cache add postgresql-client
RESULT=$(psql "$DB_URI" -t) <<-EOSQL
SELECT description
FROM search_idx.search('description:"bluetooth speaker"~1');
EOSQL
echo -$RESULT-
philippemnoel marked this conversation as resolved.
Show resolved Hide resolved
test "$RESULT" = " Bluetooth-enabled speaker"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: batch/v1
kind: Job
metadata:
name: data-write
status:
succeeded: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: configmap-creator-sa
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: configmap-creator
rules:
- apiGroups: [""]
resources: ["configmaps"]
verbs: ["create"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: configmap-creator-binding
subjects:
- kind: ServiceAccount
name: configmap-creator-sa
roleRef:
kind: Role
name: configmap-creator
apiGroup: rbac.authorization.k8s.io
---
apiVersion: batch/v1
kind: Job
metadata:
name: data-write
spec:
template:
spec:
serviceAccountName: configmap-creator-sa
restartPolicy: OnFailure
containers:
- name: data-write
env:
- name: DB_URI
valueFrom:
secretKeyRef:
name: paradedb-cluster-superuser
key: uri
image: alpine:3.19
command: ['sh', '-c']
args:
- |
apk --no-cache add postgresql-client kubectl coreutils
DB_URI=$(echo $DB_URI | sed "s|/\*|/|" )
psql "$DB_URI" -c "CREATE TABLE mygoodtable (id serial PRIMARY KEY);"
sleep 5
DATE_NO_BAD_TABLE=$(date --rfc-3339=ns)
kubectl create configmap date-no-bad-table --from-literal=date="$DATE_NO_BAD_TABLE"
sleep 5
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: postgresql.cnpg.io/v1
kind: Backup
metadata:
name: post-init-backup
spec:
method: barmanObjectStore
cluster:
name: paradedb-cluster
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: postgresql.cnpg.io/v1
kind: Backup
metadata:
name: post-init-backup
spec:
cluster:
name: paradedb-cluster
method: barmanObjectStore
status:
phase: completed
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: postgresql.cnpg.io/v1
kind: Backup
metadata:
name: post-init-backup
spec:
cluster:
name: paradedb-cluster
method: barmanObjectStore
status:
phase: running
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: batch/v1
kind: Job
metadata:
name: backup-checkpoint
spec:
template:
spec:
restartPolicy: OnFailure
containers:
- name: create-checkpoint
env:
- name: DB_URI
valueFrom:
secretKeyRef:
name: paradedb-cluster-superuser
key: uri
image: alpine:3.19
command: ['sh', '-c']
args:
- |
apk --no-cache add postgresql-client
DB_URI=$(echo $DB_URI | sed "s|/\*|/|" )
END_TIME=$(( $(date +%s) + 30 ))
while [ $(date +%s) -lt $END_TIME ]; do
psql "$DB_URI" -c "SELECT pg_switch_wal();CHECKPOINT;"
sleep 5
done
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: batch/v1
kind: Job
metadata:
name: data-write-post-backup
status:
succeeded: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: batch/v1
kind: Job
metadata:
name: data-write-post-backup
spec:
template:
spec:
restartPolicy: OnFailure
containers:
- name: data-write
env:
- name: DB_URI
valueFrom:
secretKeyRef:
name: paradedb-cluster-superuser
key: uri
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
image: alpine:3.19
command: ['sh', '-c']
args:
- |
apk --no-cache add postgresql-client
DB_URI=$(echo $DB_URI | sed "s|/\*|/|" )
psql "$DB_URI" -c "CREATE TABLE mybadtable (id serial PRIMARY KEY);"
philippemnoel marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: recovery-backup-pitr-cluster
status:
readyInstances: 2
Loading
Loading