Skip to content

K8SPG-611: official postgres image support #1212

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions build/postgres-operator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ COPY --from=go_builder /usr/local/bin/extension-installer /usr/local/bin
COPY --from=go_builder /usr/local/bin/pgbackrest /usr/local/bin/
COPY --from=go_builder /licenses /licenses
COPY build/postgres-operator/install-extensions.sh /usr/local/bin
COPY build/postgres-operator/relocate-extensions.sh /usr/local/bin
COPY build/postgres-operator/init-entrypoint.sh /usr/local/bin
COPY build/postgres-operator/postgres-entrypoint.sh /usr/local/bin
COPY build/postgres-operator/postgres-liveness-check.sh /usr/local/bin
Expand Down
1 change: 1 addition & 0 deletions build/postgres-operator/init-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ install -o "$(id -u)" -g "$(id -g)" -m 0755 -D "/usr/local/bin/pgbackrest" "${CR
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D "/usr/local/bin/postgres-entrypoint.sh" "${CRUNCHY_BINDIR}/bin/postgres-entrypoint.sh"
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D "/usr/local/bin/postgres-liveness-check.sh" "${CRUNCHY_BINDIR}/bin/postgres-liveness-check.sh"
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D "/usr/local/bin/postgres-readiness-check.sh" "${CRUNCHY_BINDIR}/bin/postgres-readiness-check.sh"
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D "/usr/local/bin/relocate-extensions.sh" "${CRUNCHY_BINDIR}/bin/relocate-extensions.sh"
14 changes: 14 additions & 0 deletions build/postgres-operator/relocate-extensions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -e

PG_EXTENSIONS_DIR=/usr/pgsql-${PG_VERSION}/share/extension
PG_LIB_DIR=/usr/pgsql-${PG_VERSION}/lib

PGDATA_EXTENSIONS_DIR=/pgdata/extension/${PG_VERSION}/usr/pgsql-${PG_VERSION}/share/extension
PGDATA_LIB_DIR=/pgdata/extension/${PG_VERSION}/usr/pgsql-${PG_VERSION}/lib

mkdir -p "${PGDATA_EXTENSIONS_DIR}"
mkdir -p "${PGDATA_LIB_DIR}"

cp -r "${PG_EXTENSIONS_DIR}"/* "${PGDATA_EXTENSIONS_DIR}/"
cp -r "${PG_LIB_DIR}"/* "${PGDATA_LIB_DIR}/"
2 changes: 1 addition & 1 deletion config/crd/patches/versionlabel_in_perconapgbackups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ kind: CustomResourceDefinition
metadata:
name: perconapgbackups.pgv2.percona.com
labels:
pgv2.percona.com/version: v2.7.0
pgv2.percona.com/version: v2.8.0
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ kind: CustomResourceDefinition
metadata:
name: perconapgclusters.pgv2.percona.com
labels:
pgv2.percona.com/version: v2.7.0
pgv2.percona.com/version: v2.8.0
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ kind: CustomResourceDefinition
metadata:
name: perconapgrestores.pgv2.percona.com
labels:
pgv2.percona.com/version: v2.7.0
pgv2.percona.com/version: v2.8.0
2 changes: 1 addition & 1 deletion config/crd/patches/versionlabel_in_perconapgupgrade.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ kind: CustomResourceDefinition
metadata:
name: perconapgupgrades.pgv2.percona.com
labels:
pgv2.percona.com/version: v2.7.0
pgv2.percona.com/version: v2.8.0
8 changes: 4 additions & 4 deletions deploy/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.5
labels:
pgv2.percona.com/version: v2.7.0
pgv2.percona.com/version: v2.8.0
name: perconapgbackups.pgv2.percona.com
spec:
group: pgv2.percona.com
Expand Down Expand Up @@ -707,7 +707,7 @@ metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.5
labels:
pgv2.percona.com/version: v2.7.0
pgv2.percona.com/version: v2.8.0
name: perconapgclusters.pgv2.percona.com
spec:
group: pgv2.percona.com
Expand Down Expand Up @@ -19138,7 +19138,7 @@ metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.5
labels:
pgv2.percona.com/version: v2.7.0
pgv2.percona.com/version: v2.8.0
name: perconapgrestores.pgv2.percona.com
spec:
group: pgv2.percona.com
Expand Down Expand Up @@ -19238,7 +19238,7 @@ metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.5
labels:
pgv2.percona.com/version: v2.7.0
pgv2.percona.com/version: v2.8.0
name: perconapgupgrades.pgv2.percona.com
spec:
group: pgv2.percona.com
Expand Down
2 changes: 1 addition & 1 deletion deploy/cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ metadata:
# - percona.com/delete-ssl
# - percona.com/delete-backups
spec:
crVersion: 2.7.0
crVersion: 2.8.0
# initContainer:
# image: perconalab/percona-postgresql-operator:main
# resources:
Expand Down
8 changes: 4 additions & 4 deletions deploy/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.5
labels:
pgv2.percona.com/version: v2.7.0
pgv2.percona.com/version: v2.8.0
name: perconapgbackups.pgv2.percona.com
spec:
group: pgv2.percona.com
Expand Down Expand Up @@ -707,7 +707,7 @@ metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.5
labels:
pgv2.percona.com/version: v2.7.0
pgv2.percona.com/version: v2.8.0
name: perconapgclusters.pgv2.percona.com
spec:
group: pgv2.percona.com
Expand Down Expand Up @@ -19138,7 +19138,7 @@ metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.5
labels:
pgv2.percona.com/version: v2.7.0
pgv2.percona.com/version: v2.8.0
name: perconapgrestores.pgv2.percona.com
spec:
group: pgv2.percona.com
Expand Down Expand Up @@ -19238,7 +19238,7 @@ metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.5
labels:
pgv2.percona.com/version: v2.7.0
pgv2.percona.com/version: v2.8.0
name: perconapgupgrades.pgv2.percona.com
spec:
group: pgv2.percona.com
Expand Down
8 changes: 4 additions & 4 deletions deploy/cw-bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.5
labels:
pgv2.percona.com/version: v2.7.0
pgv2.percona.com/version: v2.8.0
name: perconapgbackups.pgv2.percona.com
spec:
group: pgv2.percona.com
Expand Down Expand Up @@ -707,7 +707,7 @@ metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.5
labels:
pgv2.percona.com/version: v2.7.0
pgv2.percona.com/version: v2.8.0
name: perconapgclusters.pgv2.percona.com
spec:
group: pgv2.percona.com
Expand Down Expand Up @@ -19138,7 +19138,7 @@ metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.5
labels:
pgv2.percona.com/version: v2.7.0
pgv2.percona.com/version: v2.8.0
name: perconapgrestores.pgv2.percona.com
spec:
group: pgv2.percona.com
Expand Down Expand Up @@ -19238,7 +19238,7 @@ metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.5
labels:
pgv2.percona.com/version: v2.7.0
pgv2.percona.com/version: v2.8.0
name: perconapgupgrades.pgv2.percona.com
spec:
group: pgv2.percona.com
Expand Down
8 changes: 5 additions & 3 deletions e2e-tests/tests/custom-extensions/02-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ spec:
template:
spec:
initContainers:
- command:
- /usr/local/bin/init-entrypoint.sh
- name: postgres-startup
- command:
- /usr/local/bin/relocate-extensions.sh
- /opt/crunchy/bin/relocate-extensions.sh
resources: {}
volumeMounts:
- mountPath: /pgdata
name: postgres-data
- mountPath: /opt/crunchy
name: crunchy-bin
- mountPath: /tmp
name: tmp
- command:
Expand All @@ -52,8 +56,6 @@ spec:
- name: postgres-data
- mountPath: /tmp
name: tmp
- command:
- /usr/local/bin/init-entrypoint.sh
- name: nss-wrapper-init
status:
observedGeneration: 2
Expand Down
8 changes: 5 additions & 3 deletions e2e-tests/tests/custom-extensions/05-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ spec:
template:
spec:
initContainers:
- command:
- /usr/local/bin/init-entrypoint.sh
- name: postgres-startup
- command:
- /usr/local/bin/relocate-extensions.sh
- /opt/crunchy/bin/relocate-extensions.sh
resources: {}
volumeMounts:
- mountPath: /pgdata
name: postgres-data
- mountPath: /opt/crunchy
name: crunchy-bin
- mountPath: /tmp
name: tmp
- command:
Expand All @@ -52,8 +56,6 @@ spec:
- name: postgres-data
- mountPath: /tmp
name: tmp
- command:
- /usr/local/bin/init-entrypoint.sh
- name: nss-wrapper-init
status:
observedGeneration: 2
Expand Down
8 changes: 5 additions & 3 deletions e2e-tests/tests/custom-extensions/06-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ spec:
template:
spec:
initContainers:
- command:
- /usr/local/bin/init-entrypoint.sh
- name: postgres-startup
- command:
- /usr/local/bin/relocate-extensions.sh
- /opt/crunchy/bin/relocate-extensions.sh
env:
- name: PG_VERSION
resources: {}
volumeMounts:
- mountPath: /pgdata
name: postgres-data
- mountPath: /opt/crunchy
name: crunchy-bin
- mountPath: /tmp
name: tmp
- command:
Expand All @@ -54,8 +58,6 @@ spec:
- name: postgres-data
- mountPath: /tmp
name: tmp
- command:
- /usr/local/bin/init-entrypoint.sh
- name: nss-wrapper-init
status:
observedGeneration: 3
Expand Down
6 changes: 3 additions & 3 deletions e2e-tests/tests/custom-extensions/07-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ spec:
template:
spec:
initContainers:
- command:
- /usr/local/bin/init-entrypoint.sh
- name: postgres-startup
- command:
- /usr/local/bin/relocate-extensions.sh
- /opt/crunchy/bin/relocate-extensions.sh
- command:
- /usr/local/bin/install-extensions.sh
- command:
- /usr/local/bin/init-entrypoint.sh
- name: nss-wrapper-init
status:
observedGeneration: 3
Expand Down
12 changes: 6 additions & 6 deletions e2e-tests/tests/init-deploy/05-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ metadata:
app.kubernetes.io/managed-by: percona-postgresql-operator
app.kubernetes.io/name: percona-postgresql
app.kubernetes.io/part-of: percona-postgresql
pgv2.percona.com/version: 2.7.0
pgv2.percona.com/version: 2.8.0
postgres-operator.crunchydata.com/cluster: init-deploy
postgres-operator.crunchydata.com/pgbackrest: ""
postgres-operator.crunchydata.com/pgbackrest-config: ""
Expand Down Expand Up @@ -81,7 +81,7 @@ metadata:
app.kubernetes.io/managed-by: percona-postgresql-operator
app.kubernetes.io/name: percona-postgresql
app.kubernetes.io/part-of: percona-postgresql
pgv2.percona.com/version: 2.7.0
pgv2.percona.com/version: 2.8.0
postgres-operator.crunchydata.com/cluster: init-deploy
postgres-operator.crunchydata.com/role: pgbouncer
test-label: test
Expand Down Expand Up @@ -144,7 +144,7 @@ metadata:
app.kubernetes.io/managed-by: percona-postgresql-operator
app.kubernetes.io/name: percona-postgresql
app.kubernetes.io/part-of: percona-postgresql
pgv2.percona.com/version: 2.7.0
pgv2.percona.com/version: 2.8.0
postgres-operator.crunchydata.com/cluster: init-deploy
postgres-operator.crunchydata.com/pgbackrest: ""
postgres-operator.crunchydata.com/pgbackrest-config: ""
Expand All @@ -168,7 +168,7 @@ metadata:
app.kubernetes.io/managed-by: percona-postgresql-operator
app.kubernetes.io/name: percona-postgresql
app.kubernetes.io/part-of: percona-postgresql
pgv2.percona.com/version: 2.7.0
pgv2.percona.com/version: 2.8.0
postgres-operator.crunchydata.com/cluster: init-deploy
postgres-operator.crunchydata.com/role: pgbouncer
test-label: test
Expand All @@ -191,7 +191,7 @@ metadata:
app.kubernetes.io/managed-by: percona-postgresql-operator
app.kubernetes.io/name: percona-postgresql
app.kubernetes.io/part-of: percona-postgresql
pgv2.percona.com/version: 2.7.0
pgv2.percona.com/version: 2.8.0
postgres-operator.crunchydata.com/cluster: init-deploy
postgres-operator.crunchydata.com/data: pgbackrest
postgres-operator.crunchydata.com/pgbackrest: ""
Expand All @@ -214,7 +214,7 @@ spec:
app.kubernetes.io/managed-by: percona-postgresql-operator
app.kubernetes.io/name: percona-postgresql
app.kubernetes.io/part-of: percona-postgresql
pgv2.percona.com/version: 2.7.0
pgv2.percona.com/version: 2.8.0
postgres-operator.crunchydata.com/cluster: init-deploy
postgres-operator.crunchydata.com/data: pgbackrest
postgres-operator.crunchydata.com/pgbackrest: ""
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export IMAGE_BASE=${IMAGE_BASE:-"perconalab/percona-postgresql-operator"}
export IMAGE=${IMAGE:-"${IMAGE_BASE}:${VERSION}"}
export PG_VER="${PG_VER:-17}"
export IMAGE_PGBOUNCER=${IMAGE_PGBOUNCER:-"${IMAGE_BASE}:main-pgbouncer$PG_VER"}
export IMAGE_POSTGRESQL=${IMAGE_POSTGRESQL:-"${IMAGE_BASE}:main-ppg$PG_VER-postgres"}
export IMAGE_POSTGRESQL=${IMAGE_POSTGRESQL:-"ademajazzserve/postgres:11"} # TODO: replace it
export IMAGE_BACKREST=${IMAGE_BACKREST:-"${IMAGE_BASE}:main-pgbackrest$PG_VER"}
export IMAGE_UPGRADE=${IMAGE_UPGRADE:-"${IMAGE_BASE}:main-upgrade"}
export BUCKET=${BUCKET:-"pg-operator-testing"}
Expand Down
12 changes: 9 additions & 3 deletions internal/patroni/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,21 @@ func InstancePod(ctx context.Context,

// K8SPG-708 instanceInitContainer adds the instance init container
func instanceInitContainer(cluster *v1beta1.PostgresCluster, container *corev1.Container, instancePod *corev1.PodTemplateSpec, inInstanceSpec *v1beta1.PostgresInstanceSetSpec, initImage string) {
instancePod.Spec.InitContainers = append(instancePod.Spec.InitContainers, k8s.InitContainer(
initContainer := k8s.InitContainer(
cluster,
naming.ContainerDatabase,
initImage,
cluster.Spec.ImagePullPolicy,
initialize.RestrictedSecurityContext(true),
container.Resources,
inInstanceSpec))
inInstanceSpec)

if cluster.CompareVersion("2.8.0") >= 0 {
// The operator's init container must be the first one to run so that the other init containers can use the installed scripts.
instancePod.Spec.InitContainers = append([]corev1.Container{initContainer}, instancePod.Spec.InitContainers...)
} else {
instancePod.Spec.InitContainers = append(instancePod.Spec.InitContainers, initContainer)
}

instancePod.Spec.Volumes = append(instancePod.Spec.Volumes, corev1.Volume{
Name: pNaming.CrunchyBinVolumeName,
Expand All @@ -171,7 +178,6 @@ func instanceInitContainer(cluster *v1beta1.PostgresCluster, container *corev1.C

// instanceProbes adds Patroni liveness and readiness probes to container.
func instanceProbes(cluster *v1beta1.PostgresCluster, container *corev1.Container) {

// Patroni uses a watchdog to ensure that PostgreSQL does not accept commits
// after the leader lock expires, even if Patroni becomes unresponsive.
// - https://github.com/zalando/patroni/blob/v2.0.1/docs/watchdog.rst
Expand Down
Loading