Skip to content

Commit fc88395

Browse files
inelpandzichors
andauthored
K8SPG-459: Support tablespaces (#736)
* Add tablespaceVolumes. * gitignore * Generate CRDs. * Add e2e test. * Register tablespaces test. * Update test. * Test only tablespaces. * Add RANDOM. * Fix e2e test. --------- Co-authored-by: Viacheslav Sarzhan <[email protected]>
1 parent 1f15683 commit fc88395

31 files changed

+1739
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/.vscode
2+
/.idea
23

34
.DS_Store
45
/vendor/

build/crd/percona/generated/pgv2.percona.com_perconapgclusters.yaml

+246
Large diffs are not rendered by default.

cmd/postgres-operator/main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ func main() {
7575
assertNoError(err)
7676
// Needed for PMM
7777
err = util.DefaultMutableFeatureGate.SetFromMap(map[string]bool{
78-
string(util.InstanceSidecars): true,
78+
string(util.InstanceSidecars): true,
79+
string(util.TablespaceVolumes): true,
7980
})
8081
assertNoError(err)
8182

config/crd/bases/pgv2.percona.com_perconapgclusters.yaml

+246
Large diffs are not rendered by default.

deploy/bundle.yaml

+246
Large diffs are not rendered by default.

deploy/cr.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ spec:
153153
resources:
154154
requests:
155155
storage: 1Gi
156+
# tablespaceVolumes:
157+
# - name: user
158+
# dataVolumeClaimSpec:
159+
# accessModes:
160+
# - 'ReadWriteOnce'
161+
# resources:
162+
# requests:
163+
# storage: 1Gi
156164

157165
proxy:
158166
pgBouncer:

deploy/crd.yaml

+246
Large diffs are not rendered by default.

deploy/cw-bundle.yaml

+246
Large diffs are not rendered by default.

e2e-tests/run-pr.csv

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ scaling
77
scheduled-backup
88
self-healing
99
start-from-backup
10+
tablespaces
1011
telemetry-transfer
1112
upgrade-minor
1213
users

e2e-tests/run-release.csv

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ scaling
88
scheduled-backup
99
self-healing
1010
start-from-backup
11+
tablespaces
1112
telemetry-transfer
1213
upgrade-minor
1314
users
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestAssert
3+
timeout: 120
4+
---
5+
apiVersion: apiextensions.k8s.io/v1
6+
kind: CustomResourceDefinition
7+
metadata:
8+
name: perconapgclusters.pgv2.percona.com
9+
spec:
10+
group: pgv2.percona.com
11+
names:
12+
kind: PerconaPGCluster
13+
listKind: PerconaPGClusterList
14+
plural: perconapgclusters
15+
singular: perconapgcluster
16+
scope: Namespaced
17+
---
18+
apiVersion: kuttl.dev/v1beta1
19+
kind: TestAssert
20+
metadata:
21+
name: check-operator-deploy-status
22+
timeout: 120
23+
commands:
24+
- script: kubectl assert exist-enhanced deployment percona-postgresql-operator -n ${OPERATOR_NS:-$NAMESPACE} --field-selector status.readyReplicas=1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestStep
3+
timeout: 10
4+
commands:
5+
- script: |-
6+
set -o errexit
7+
set -o xtrace
8+
9+
source ../../functions
10+
init_temp_dir # do this only in the first TestStep
11+
12+
deploy_operator
13+
deploy_client
14+
deploy_s3_secrets
+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestAssert
3+
timeout: 900
4+
---
5+
kind: StatefulSet
6+
apiVersion: apps/v1
7+
metadata:
8+
labels:
9+
postgres-operator.crunchydata.com/cluster: tablespaces
10+
postgres-operator.crunchydata.com/data: postgres
11+
postgres-operator.crunchydata.com/instance-set: instance1
12+
ownerReferences:
13+
- apiVersion: postgres-operator.crunchydata.com/v1beta1
14+
kind: PostgresCluster
15+
name: tablespaces
16+
controller: true
17+
blockOwnerDeletion: true
18+
status:
19+
observedGeneration: 1
20+
replicas: 1
21+
readyReplicas: 1
22+
currentReplicas: 1
23+
updatedReplicas: 1
24+
collisionCount: 0
25+
---
26+
kind: Deployment
27+
apiVersion: apps/v1
28+
metadata:
29+
name: tablespaces-pgbouncer
30+
labels:
31+
postgres-operator.crunchydata.com/cluster: tablespaces
32+
postgres-operator.crunchydata.com/role: pgbouncer
33+
annotations:
34+
deployment.kubernetes.io/revision: '1'
35+
ownerReferences:
36+
- apiVersion: postgres-operator.crunchydata.com/v1beta1
37+
kind: PostgresCluster
38+
name: tablespaces
39+
controller: true
40+
blockOwnerDeletion: true
41+
status:
42+
observedGeneration: 1
43+
replicas: 3
44+
updatedReplicas: 3
45+
readyReplicas: 3
46+
---
47+
kind: Job
48+
apiVersion: batch/v1
49+
metadata:
50+
labels:
51+
postgres-operator.crunchydata.com/cluster: tablespaces
52+
postgres-operator.crunchydata.com/pgbackrest: ''
53+
postgres-operator.crunchydata.com/pgbackrest-backup: replica-create
54+
postgres-operator.crunchydata.com/pgbackrest-repo: repo1
55+
annotations:
56+
postgres-operator.crunchydata.com/pgbackrest-config: pgbackrest
57+
ownerReferences:
58+
- apiVersion: pgv2.percona.com/v2
59+
kind: PerconaPGBackup
60+
controller: true
61+
blockOwnerDeletion: true
62+
status:
63+
succeeded: 1
64+
---
65+
apiVersion: postgres-operator.crunchydata.com/v1beta1
66+
kind: PostgresCluster
67+
metadata:
68+
name: tablespaces
69+
ownerReferences:
70+
- apiVersion: pgv2.percona.com/v2
71+
kind: PerconaPGCluster
72+
name: tablespaces
73+
controller: true
74+
blockOwnerDeletion: true
75+
finalizers:
76+
- postgres-operator.crunchydata.com/finalizer
77+
status:
78+
instances:
79+
- name: instance1
80+
readyReplicas: 3
81+
replicas: 3
82+
updatedReplicas: 3
83+
observedGeneration: 1
84+
pgbackrest:
85+
repos:
86+
- name: repo1
87+
stanzaCreated: true
88+
proxy:
89+
pgBouncer:
90+
readyReplicas: 3
91+
replicas: 3
92+
---
93+
apiVersion: pgv2.percona.com/v2
94+
kind: PerconaPGCluster
95+
metadata:
96+
name: tablespaces
97+
status:
98+
pgbouncer:
99+
ready: 3
100+
size: 3
101+
postgres:
102+
instances:
103+
- name: instance1
104+
ready: 3
105+
size: 3
106+
ready: 3
107+
size: 3
108+
state: ready
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestStep
3+
timeout: 10
4+
commands:
5+
- script: |-
6+
set -o errexit
7+
set -o xtrace
8+
9+
source ../../functions
10+
11+
get_cr ${RANDOM} \
12+
| yq eval '
13+
.spec.instances[].tablespaceVolumes[0].name="myts" |
14+
.spec.instances[].tablespaceVolumes[0].dataVolumeClaimSpec.accessModes[0]="ReadWriteOnce" |
15+
.spec.instances[].tablespaceVolumes[0].dataVolumeClaimSpec.resources.requests.storage="1Gi"' - \
16+
| kubectl -n "${NAMESPACE}" apply -f -
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestAssert
3+
timeout: 30
4+
---
5+
kind: ConfigMap
6+
apiVersion: v1
7+
metadata:
8+
name: 02-ts-path-1
9+
data:
10+
path: '/tablespaces/myts'
11+
---
12+
kind: ConfigMap
13+
apiVersion: v1
14+
metadata:
15+
name: 02-ts-path-2
16+
data:
17+
path: '/tablespaces/myts'
18+
---
19+
kind: ConfigMap
20+
apiVersion: v1
21+
metadata:
22+
name: 02-ts-path-3
23+
data:
24+
path: '/tablespaces/myts'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestStep
3+
timeout: 30
4+
commands:
5+
- script: |-
6+
set -o errexit
7+
set -o xtrace
8+
9+
source ../../functions
10+
11+
pods=$(get_instance_set_pods instance1)
12+
i=1
13+
for pod in $pods; do
14+
path=$(kubectl -n ${NAMESPACE} exec ${pod} -c database -- ls /tablespaces)
15+
kubectl create configmap -n "${NAMESPACE}" 02-ts-path-${i} --from-literal=path="/tablespaces/${path}"
16+
i=$((i+1))
17+
done
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestStep
3+
commands:
4+
- script: |-
5+
set -o errexit
6+
set -o xtrace
7+
8+
source ../../functions
9+
10+
run_psql_local \
11+
"CREATE TABLESPACE myts LOCATION '\''/tablespaces/myts/data'\'';" \
12+
"postgres:$(get_psql_user_pass tablespaces-pguser-postgres)@$(get_psql_user_host tablespaces-pguser-postgres)"
13+
14+
run_psql_local \
15+
'CREATE DATABASE myapp; \c myapp \\\ CREATE TABLE IF NOT EXISTS myApp (id int PRIMARY KEY) TABLESPACE myts;' \
16+
"postgres:$(get_psql_user_pass tablespaces-pguser-postgres)@$(get_psql_user_host tablespaces-pguser-postgres)"
17+
18+
run_psql_local \
19+
'\c myapp \\\ INSERT INTO myApp (id) VALUES (100500)' \
20+
"postgres:$(get_psql_user_pass tablespaces-pguser-postgres)@$(get_psql_user_host tablespaces-pguser-postgres)"
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestAssert
3+
timeout: 30
4+
---
5+
kind: ConfigMap
6+
apiVersion: v1
7+
metadata:
8+
name: 04-check-tablespace
9+
data:
10+
data: ' /tablespaces/myts/data'
11+
---
12+
kind: ConfigMap
13+
apiVersion: v1
14+
metadata:
15+
name: 04-check-table-in-tablespace
16+
data:
17+
data: ' myts'
18+
---
19+
kind: ConfigMap
20+
apiVersion: v1
21+
metadata:
22+
name: 04-read-from-primary
23+
data:
24+
data: ' 100500'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestStep
3+
timeout: 30
4+
commands:
5+
- script: |-
6+
set -o errexit
7+
set -o xtrace
8+
9+
source ../../functions
10+
11+
data=$(run_psql_local \
12+
"select pg_tablespace_location(oid) from pg_tablespace where spcname = '\''myts'\'';" \
13+
"postgres:$(get_psql_user_pass tablespaces-pguser-postgres)@$(get_psql_user_host tablespaces-pguser-postgres)")
14+
kubectl create configmap -n "${NAMESPACE}" 04-check-tablespace --from-literal=data="${data}"
15+
16+
data=$(run_psql_local \
17+
"\c myapp \\\\\ SELECT ts.spcname AS tablespace_name FROM pg_class t JOIN pg_tablespace ts ON t.reltablespace = ts.oid WHERE t.relname = '\''myapp'\'';" \
18+
"postgres:$(get_psql_user_pass tablespaces-pguser-postgres)@$(get_psql_user_host tablespaces-pguser-postgres)")
19+
kubectl create configmap -n "${NAMESPACE}" 04-check-table-in-tablespace --from-literal=data="${data}"
20+
21+
data=$(run_psql_local '\c myapp \\\ SELECT * from myApp;' "postgres:$(get_psql_user_pass tablespaces-pguser-postgres)@$(get_psql_user_host tablespaces-pguser-postgres)")
22+
kubectl create configmap -n "${NAMESPACE}" 04-read-from-primary --from-literal=data="${data}"
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestAssert
3+
timeout: 560
4+
---
5+
kind: Job
6+
apiVersion: batch/v1
7+
metadata:
8+
annotations:
9+
postgres-operator.crunchydata.com/pgbackrest-backup: tablespaces-full
10+
labels:
11+
postgres-operator.crunchydata.com/pgbackrest-backup: manual
12+
postgres-operator.crunchydata.com/pgbackrest-repo: repo1
13+
ownerReferences:
14+
- apiVersion: pgv2.percona.com/v2
15+
kind: PerconaPGBackup
16+
controller: true
17+
blockOwnerDeletion: true
18+
status:
19+
succeeded: 1
20+
---
21+
apiVersion: pgv2.percona.com/v2
22+
kind: PerconaPGBackup
23+
metadata:
24+
name: tablespaces-full
25+
spec:
26+
pgCluster: tablespaces
27+
repoName: repo1
28+
options:
29+
- --type=full
30+
status:
31+
state: Succeeded
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: pgv2.percona.com/v2
2+
kind: PerconaPGBackup
3+
metadata:
4+
name: tablespaces-full
5+
spec:
6+
pgCluster: tablespaces
7+
repoName: repo1
8+
options:
9+
- --type=full
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestStep
3+
commands:
4+
- script: |-
5+
set -o errexit
6+
set -o xtrace
7+
8+
source ../../functions
9+
10+
check_passwords_leak
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestStep
3+
commands:
4+
- script: |-
5+
set -o errexit
6+
set -o xtrace
7+
8+
source ../../functions
9+
10+
run_psql_local \
11+
'\c myapp \\\ TRUNCATE TABLE myApp' \
12+
"postgres:$(get_psql_user_pass tablespaces-pguser-postgres)@$(get_psql_user_host tablespaces-pguser-postgres)"

0 commit comments

Comments
 (0)