Skip to content

Commit 2e39888

Browse files
authored
K8SPG-375: Merge extension installer image into operator (#573)
* K8SPG-375: Merge extension installer image into operator * fix tests * fix openshift * detect openshift * don't use hardcoded postgres version * don't use hardcoded postgres version
1 parent fafb018 commit 2e39888

23 files changed

+185
-378
lines changed

build/extension-installer/Dockerfile

-41
This file was deleted.

build/postgres-operator/Dockerfile

+8-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ RUN mkdir -p build/_output/bin \
1515
go build -ldflags "-w -s -X main.GitCommit=$GIT_COMMIT -X main.GitBranch=$GIT_BRANCH" \
1616
-o build/_output/bin/postgres-operator \
1717
./cmd/postgres-operator \
18-
&& cp -r build/_output/bin/postgres-operator /usr/local/bin/postgres-operator
18+
&& CGO_ENABLED=$CGO_ENABLED GOOS=$GOOS GO_LDFLAGS=$GO_LDFLAGS \
19+
go build -ldflags "-w -s -X main.GitCommit=$GIT_COMMIT -X main.GitBranch=$GIT_BRANCH" \
20+
-o build/_output/bin/extension-installer \
21+
./cmd/extension-installer \
22+
&& cp -r build/_output/bin/postgres-operator /usr/local/bin/postgres-operator \
23+
&& cp -r build/_output/bin/extension-installer /usr/local/bin/extension-installer
1924

2025

2126
RUN ./bin/license_aggregator.sh ./cmd/...; \
@@ -34,7 +39,9 @@ RUN microdnf update -y && microdnf clean all -y
3439
COPY licenses /licenses
3540

3641
COPY --from=go_builder /usr/local/bin/postgres-operator /usr/local/bin
42+
COPY --from=go_builder /usr/local/bin/extension-installer /usr/local/bin
3743
COPY --from=go_builder /licenses /licenses
44+
COPY build/postgres-operator/install-extensions.sh /usr/local/bin
3845

3946
USER 2
4047

cmd/postgres-operator/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ func addControllersToManager(ctx context.Context, mgr manager.Manager) error {
167167
Platform: detectPlatform(ctx, mgr.GetConfig()),
168168
KubeVersion: getServerVersion(ctx, mgr.GetConfig()),
169169
CrunchyController: cm.Controller(),
170+
IsOpenShift: isOpenshift(ctx, mgr.GetConfig()),
170171
}
171172
if err := pc.SetupWithManager(mgr); err != nil {
172173
return err

deploy/cr.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ spec:
283283
# work_mem: 2MB
284284

285285
# extensions:
286-
# image: perconalab/percona-postgresql-operator:main-ext-installer
286+
# image: perconalab/percona-postgresql-operator:main
287287
# imagePullPolicy: Always
288288
# storage:
289289
# type: s3

e2e-tests/functions

+1-3
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,7 @@ get_cr() {
154154
;;
155155
custom-extensions)
156156
yq eval '
157-
.spec.postgresVersion = 15
158-
| .spec.image = "'${IMAGE_BASE}:k8spg-375-ppg15-postgres'"
159-
| .spec.extensions.image = "'${IMAGE_EXT_INSTALLER}'"
157+
.spec.extensions.image = "'${IMAGE}'"
160158
| .spec.extensions.imagePullPolicy = "Always"
161159
| .spec.extensions.storage = {"type": "s3", "bucket": "pg-extensions", "region": "eu-central-1", "secret": {"name": "aws-s3-secret"}}
162160
' "${TEMP_DIR}/cr.yaml" \

e2e-tests/tests/custom-extensions/02-assert.yaml

+2-12
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ spec:
2222
- name: postgres-startup
2323
- command:
2424
- /usr/local/bin/relocate-extensions.sh
25-
env:
26-
- name: PG_VERSION
27-
value: "15"
2825
name: extension-relocator
2926
resources: {}
3027
volumeMounts:
@@ -42,11 +39,8 @@ spec:
4239
- name: STORAGE_BUCKET
4340
value: pg-extensions
4441
- name: INSTALL_EXTENSIONS
45-
value: pg_cron-pg15-1.6.1
4642
- name: PG_VERSION
47-
value: "15"
4843
- name: PGDATA_EXTENSIONS
49-
value: /pgdata/extension/15
5044
envFrom:
5145
- secretRef:
5246
name: aws-s3-secret
@@ -55,12 +49,8 @@ spec:
5549
volumeMounts:
5650
- mountPath: /pgdata
5751
name: postgres-data
58-
- mountPath: /usr/pgsql-15/share/extension
59-
name: postgres-data
60-
subPath: extension/15/usr/pgsql-15/share/extension
61-
- mountPath: /usr/pgsql-15/lib
62-
name: postgres-data
63-
subPath: extension/15/usr/pgsql-15/lib
52+
- name: postgres-data
53+
- name: postgres-data
6454
- mountPath: /tmp
6555
name: tmp
6656
- name: nss-wrapper-init

e2e-tests/tests/custom-extensions/04-assert.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ data:
4343
pg_cron
4444
pg_freespacemap
4545
pg_prewarm
46+
pg_repack
4647
pg_stat_monitor
4748
pg_stat_statements
4849
pg_surgery

e2e-tests/tests/custom-extensions/05-assert.yaml

+5-14
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ spec:
2222
- name: postgres-startup
2323
- command:
2424
- /usr/local/bin/relocate-extensions.sh
25-
env:
26-
- name: PG_VERSION
27-
value: "15"
2825
name: extension-relocator
2926
resources: {}
3027
volumeMounts:
@@ -42,11 +39,8 @@ spec:
4239
- name: STORAGE_BUCKET
4340
value: pg-extensions
4441
- name: INSTALL_EXTENSIONS
45-
value: pg_cron-pg15-1.6.1,timescaledb-pg15-2.11.2
4642
- name: PG_VERSION
47-
value: "15"
4843
- name: PGDATA_EXTENSIONS
49-
value: /pgdata/extension/15
5044
envFrom:
5145
- secretRef:
5246
name: aws-s3-secret
@@ -55,20 +49,17 @@ spec:
5549
volumeMounts:
5650
- mountPath: /pgdata
5751
name: postgres-data
58-
- mountPath: /usr/pgsql-15/share/extension
59-
name: postgres-data
60-
subPath: extension/15/usr/pgsql-15/share/extension
61-
- mountPath: /usr/pgsql-15/lib
62-
name: postgres-data
63-
subPath: extension/15/usr/pgsql-15/lib
52+
- name: postgres-data
53+
- name: postgres-data
6454
- mountPath: /tmp
6555
name: tmp
6656
- name: nss-wrapper-init
6757
status:
68-
observedGeneration: 3
58+
observedGeneration: 2
6959
replicas: 1
7060
updatedReplicas: 1
7161
readyReplicas: 1
62+
availableReplicas: 1
7263
---
7364
apiVersion: pgv2.percona.com/v2
7465
kind: PerconaPGCluster
@@ -85,4 +76,4 @@ status:
8576
size: 3
8677
ready: 3
8778
size: 3
88-
state: ready
79+
state: ready

e2e-tests/tests/custom-extensions/05-install-timescaledb.yaml

-15
This file was deleted.

e2e-tests/tests/custom-extensions/06-assert.yaml

+35-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,41 @@ spec:
2020
spec:
2121
initContainers:
2222
- name: postgres-startup
23-
- name: extension-relocator
24-
- name: extension-installer
23+
- command:
24+
- /usr/local/bin/relocate-extensions.sh
25+
env:
26+
- name: PG_VERSION
27+
name: extension-relocator
28+
resources: {}
29+
volumeMounts:
30+
- mountPath: /pgdata
31+
name: postgres-data
32+
- mountPath: /tmp
33+
name: tmp
34+
- command:
35+
- /usr/local/bin/install-extensions.sh
36+
env:
37+
- name: STORAGE_TYPE
38+
value: s3
39+
- name: STORAGE_REGION
40+
value: eu-central-1
41+
- name: STORAGE_BUCKET
42+
value: pg-extensions
43+
- name: INSTALL_EXTENSIONS
44+
- name: PG_VERSION
45+
- name: PGDATA_EXTENSIONS
46+
envFrom:
47+
- secretRef:
48+
name: aws-s3-secret
49+
name: extension-installer
50+
resources: {}
51+
volumeMounts:
52+
- mountPath: /pgdata
53+
name: postgres-data
54+
- name: postgres-data
55+
- name: postgres-data
56+
- mountPath: /tmp
57+
name: tmp
2558
- name: nss-wrapper-init
2659
status:
2760
observedGeneration: 3

e2e-tests/tests/custom-extensions/08-uninstall-timescaledb.yaml e2e-tests/tests/custom-extensions/06-uninstall-pg_cron.yaml

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ metadata:
44
name: custom-extensions
55
spec:
66
extensions:
7-
custom:
8-
- name: pg_cron
9-
version: 1.6.1
7+
custom: []
108
patroni:
119
dynamicConfiguration:
1210
postgresql:
13-
shared_preload_libraries: pg_cron
11+
parameters:
12+
shared_preload_libraries: ""
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,48 @@
11
apiVersion: kuttl.dev/v1beta1
22
kind: TestAssert
3-
timeout: 30
3+
timeout: 120
44
---
5-
kind: ConfigMap
6-
apiVersion: v1
5+
kind: StatefulSet
6+
apiVersion: apps/v1
77
metadata:
8-
name: 07-check-extensions
9-
data:
10-
data: |2-
11-
adminpack
12-
amcheck
13-
autoinc
14-
bloom
15-
btree_gin
16-
btree_gist
17-
citext
18-
cube
19-
dblink
20-
dict_int
21-
dict_xsyn
22-
earthdistance
23-
file_fdw
24-
fuzzystrmatch
25-
hstore
26-
hstore_plperl
27-
hstore_plperlu
28-
hstore_plpython3u
29-
insert_username
30-
intagg
31-
intarray
32-
isn
33-
jsonb_plperl
34-
jsonb_plperlu
35-
jsonb_plpython3u
36-
lo
37-
ltree
38-
ltree_plpython3u
39-
moddatetime
40-
old_snapshot
41-
pageinspect
42-
pg_buffercache
43-
pg_cron
44-
pg_freespacemap
45-
pg_prewarm
46-
pg_stat_monitor
47-
pg_stat_statements
48-
pg_surgery
49-
pg_trgm
50-
pg_visibility
51-
pg_walinspect
52-
pgaudit
53-
pgcrypto
54-
pgrowlocks
55-
pgstattuple
56-
plpgsql
57-
plpython3u
58-
postgres_fdw
59-
refint
60-
seg
61-
set_user
62-
sslinfo
63-
tablefunc
64-
tcn
65-
timescaledb
66-
tsm_system_rows
67-
tsm_system_time
68-
unaccent
69-
uuid-ossp
70-
xml2
8+
labels:
9+
postgres-operator.crunchydata.com/cluster: custom-extensions
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: custom-extensions
16+
controller: true
17+
blockOwnerDeletion: true
18+
spec:
19+
template:
20+
spec:
21+
initContainers:
22+
- name: postgres-startup
23+
- name: extension-relocator
24+
- name: extension-installer
25+
- name: nss-wrapper-init
26+
status:
27+
observedGeneration: 3
28+
replicas: 1
29+
updatedReplicas: 1
30+
readyReplicas: 1
31+
availableReplicas: 1
32+
---
33+
apiVersion: pgv2.percona.com/v2
34+
kind: PerconaPGCluster
35+
metadata:
36+
name: custom-extensions
37+
status:
38+
pgbouncer:
39+
ready: 3
40+
size: 3
41+
postgres:
42+
instances:
43+
- name: instance1
44+
ready: 3
45+
size: 3
46+
ready: 3
47+
size: 3
48+
state: ready

0 commit comments

Comments
 (0)