Skip to content

Commit 499d3c4

Browse files
committed
Add basic KUTTL test
Adds a basic KUTTL test for creating a cluster with tablespaces; Updates the github test to add the feature gate; Issue: [sc-17759]
1 parent fada90d commit 499d3c4

File tree

6 files changed

+132
-0
lines changed

6 files changed

+132
-0
lines changed

.github/workflows/test.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ jobs:
130130
--env 'RELATED_IMAGE_POSTGRES_13_GIS_3.1=registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi8-13.9-3.1-2' \
131131
--env 'RELATED_IMAGE_POSTGRES_14=registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi8-14.6-2' \
132132
--env 'RELATED_IMAGE_POSTGRES_14_GIS_3.1=registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi8-14.6-3.1-2' \
133+
--env 'PGO_FEATURE_GATES=TablespaceVolumes=true' \
133134
--name 'postgres-operator' ubuntu \
134135
postgres-operator
135136
- name: Install kuttl
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: tablespace-script
5+
data:
6+
script.sql: |
7+
CREATE TABLESPACE trial OWNER "tablespace-enabled" LOCATION '/tablespaces/library/data';
8+
CREATE TABLESPACE castle OWNER "tablespace-enabled" LOCATION '/tablespaces/user/data';
9+
---
10+
apiVersion: postgres-operator.crunchydata.com/v1beta1
11+
kind: PostgresCluster
12+
metadata:
13+
name: tablespace-enabled
14+
spec:
15+
databaseInitSQL:
16+
name: tablespace-script
17+
key: script.sql
18+
postgresVersion: ${KUTTL_PG_VERSION}
19+
instances:
20+
- name: instance1
21+
dataVolumeClaimSpec:
22+
accessModes:
23+
- "ReadWriteOnce"
24+
resources:
25+
requests:
26+
storage: 1Gi
27+
tablespaceVolumes:
28+
- name: user
29+
dataVolumeClaimSpec:
30+
accessModes:
31+
- "ReadWriteOnce"
32+
resources:
33+
requests:
34+
storage: 1Gi
35+
- name: library
36+
dataVolumeClaimSpec:
37+
accessModes:
38+
- "ReadWriteOnce"
39+
resources:
40+
requests:
41+
storage: 1Gi
42+
backups:
43+
pgbackrest:
44+
repos:
45+
- name: repo1
46+
volume:
47+
volumeClaimSpec:
48+
accessModes:
49+
- "ReadWriteOnce"
50+
resources:
51+
requests:
52+
storage: 1Gi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: postgres-operator.crunchydata.com/v1beta1
2+
kind: PostgresCluster
3+
metadata:
4+
name: tablespace-enabled
5+
status:
6+
instances:
7+
- name: instance1
8+
readyReplicas: 1
9+
replicas: 1
10+
updatedReplicas: 1
11+
---
12+
apiVersion: batch/v1
13+
kind: Job
14+
metadata:
15+
labels:
16+
postgres-operator.crunchydata.com/cluster: tablespace-enabled
17+
postgres-operator.crunchydata.com/pgbackrest-backup: replica-create
18+
status:
19+
succeeded: 1
20+
---
21+
apiVersion: v1
22+
kind: Service
23+
metadata:
24+
name: tablespace-enabled-primary
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: psql-connect
5+
spec:
6+
backoffLimit: 6
7+
template:
8+
spec:
9+
restartPolicy: Never
10+
containers:
11+
- name: psql
12+
image: ${KUTTL_PSQL_IMAGE}
13+
env:
14+
- name: PGURI
15+
valueFrom: { secretKeyRef: { name: tablespace-enabled-pguser-tablespace-enabled, key: uri } }
16+
17+
# Do not wait indefinitely.
18+
- { name: PGCONNECT_TIMEOUT, value: '5' }
19+
20+
# Note: the `$$$$` is reduced to `$$` by Kubernetes.
21+
# - https://kubernetes.io/docs/tasks/inject-data-application/
22+
command:
23+
- psql
24+
- $(PGURI)
25+
- --quiet
26+
- --echo-errors
27+
- --set=ON_ERROR_STOP=1
28+
- --command
29+
- |
30+
DO $$$$
31+
DECLARE
32+
tbsp_count integer;
33+
BEGIN
34+
SELECT COUNT(*) INTO tbsp_count FROM pg_tablespace WHERE spcname = 'trial';
35+
ASSERT tbsp_count = 1, 'tablespace not found';
36+
SELECT COUNT(*) INTO tbsp_count FROM pg_tablespace WHERE spcname = 'castle';
37+
ASSERT tbsp_count = 1, 'tablespace not found';
38+
END $$$$;
39+
- --command
40+
- |
41+
CREATE SCHEMA "tablespace-enabled";
42+
CREATE TABLE important (data) TABLESPACE trial AS VALUES ('treasure');
43+
CREATE TABLE also_important (data) TABLESPACE castle AS VALUES ('treasure');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: psql-connect
5+
status:
6+
succeeded: 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Tablespace Enabled
2+
3+
**Note**: This series of tests depends on PGO being deployed with the `TablespaceVolume` feature gate enabled.
4+
5+
00: Start a cluster with tablespace volumes and a configmap `databaseInitSQL` to create tablespaces with the non-superuser as owner
6+
01: Connect to the db, check that the tablespaces exist, and create tables in the tablespaces -- this would error out if the tablespace didn't exist

0 commit comments

Comments
 (0)