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 5 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 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: 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
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
25 changes: 18 additions & 7 deletions percona/extensions/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

corev1 "k8s.io/api/core/v1"

"github.com/percona/percona-postgresql-operator/percona/naming"
pgv2 "github.com/percona/percona-postgresql-operator/pkg/apis/pgv2.percona.com/v2"
)

Expand All @@ -16,28 +17,38 @@ func GetExtensionKey(pgMajor int, name, version string) string {
// ExtensionRelocatorContainer returns a container that will relocate extensions from the base image (i.e. pg_stat_monitor, pg_audit)
// to the data directory so we don't lose them when user adds a custom extension.
func ExtensionRelocatorContainer(cr *pgv2.PerconaPGCluster, image string, imagePullPolicy corev1.PullPolicy, postgresVersion int) corev1.Container {
mounts := []corev1.VolumeMount{
{
Name: "postgres-data",
MountPath: "/pgdata",
},
}
containerName := "extension-relocator"
if cr.CompareVersion("2.4.0") >= 0 {
containerName = fmt.Sprintf("extension-relocator-%d", postgresVersion)
}

command := "/usr/local/bin/relocate-extensions.sh"

if cr.CompareVersion("2.8.0") >= 0 {
command = "/opt/crunchy/bin/relocate-extensions.sh"
mounts = append(mounts, corev1.VolumeMount{
Name: naming.CrunchyBinVolumeName,
MountPath: naming.CrunchyBinVolumePath,
})
}
return corev1.Container{
Name: containerName,
Image: image,
ImagePullPolicy: imagePullPolicy,
Command: []string{"/usr/local/bin/relocate-extensions.sh"},
Command: []string{command},
Env: []corev1.EnvVar{
{
Name: "PG_VERSION",
Value: strconv.Itoa(postgresVersion),
},
},
VolumeMounts: []corev1.VolumeMount{
{
Name: "postgres-data",
MountPath: "/pgdata",
},
},
VolumeMounts: mounts,
}
}

Expand Down