From 828c3d414e4afd72507ba8f6324a145ef22278c5 Mon Sep 17 00:00:00 2001 From: Fabian Fischer Date: Tue, 14 Dec 2021 10:39:49 +0100 Subject: [PATCH 1/2] Fix backupcommand for builtin postgres DB * Switch to annotation on pod instead of on StS * Add both `k8up.io` and `k8up.syn.tools` annotation to support k8up 2.0 * Add file-extention annotation * Add `--clean` flag for a conistent restore --- class/defaults.yml | 7 +++++-- .../charts/postgresql/templates/statefulset.yaml | 11 ++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/class/defaults.yml b/class/defaults.yml index 95a174a7..28a2498d 100644 --- a/class/defaults.yml +++ b/class/defaults.yml @@ -252,8 +252,11 @@ parameters: registry: quay.io # TODO: Rename master to primary when upgrading to Postgres 11 https://github.com/bitnami/charts/commit/7eabc85fd4fae43127228a22829c7ce3fe85c389 master: - annotations: - k8up.syn.tools/backupcommand: sh -c 'PGDATABASE="$POSTGRES_DB" PGUSER="$POSTGRES_USER" PGPASSWORD="$POSTGRES_PASSWORD" pg_dump' + podAnnotations: + k8up.syn.tools/backupcommand: sh -c 'PGDATABASE="$POSTGRES_DB" PGUSER="$POSTGRES_USER" PGPASSWORD="$POSTGRES_PASSWORD" pg_dump --clean' + k8up.syn.tools/file-extension: .sql + k8up.io/backupcommand: sh -c 'PGDATABASE="$POSTGRES_DB" PGUSER="$POSTGRES_USER" PGPASSWORD="$POSTGRES_PASSWORD" pg_dump --clean' + k8up.io/file-extension: .sql labels: ${keycloak:labels} volumePermissions: enabled: ${keycloak:database:tls:enabled} diff --git a/tests/golden/builtin/builtin/builtin/01_keycloak_helmchart/keycloak/charts/postgresql/templates/statefulset.yaml b/tests/golden/builtin/builtin/builtin/01_keycloak_helmchart/keycloak/charts/postgresql/templates/statefulset.yaml index 6592ce5e..6bda1377 100644 --- a/tests/golden/builtin/builtin/builtin/01_keycloak_helmchart/keycloak/charts/postgresql/templates/statefulset.yaml +++ b/tests/golden/builtin/builtin/builtin/01_keycloak_helmchart/keycloak/charts/postgresql/templates/statefulset.yaml @@ -1,9 +1,7 @@ apiVersion: apps/v1 kind: StatefulSet metadata: - annotations: - k8up.syn.tools/backupcommand: sh -c 'PGDATABASE="$POSTGRES_DB" PGUSER="$POSTGRES_USER" - PGPASSWORD="$POSTGRES_PASSWORD" pg_dump' + annotations: null labels: app.kubernetes.io/component: keycloak app.kubernetes.io/instance: builtin @@ -21,6 +19,13 @@ spec: serviceName: keycloak-postgresql-headless template: metadata: + annotations: + k8up.io/backupcommand: sh -c 'PGDATABASE="$POSTGRES_DB" PGUSER="$POSTGRES_USER" + PGPASSWORD="$POSTGRES_PASSWORD" pg_dump --clean' + k8up.io/file-extension: .sql + k8up.syn.tools/backupcommand: sh -c 'PGDATABASE="$POSTGRES_DB" PGUSER="$POSTGRES_USER" + PGPASSWORD="$POSTGRES_PASSWORD" pg_dump --clean' + k8up.syn.tools/file-extension: .sql labels: app.kubernetes.io/instance: keycloak app.kubernetes.io/managed-by: Helm From 38c04489a1ad88c2104edb1382af2e008dc32ebb Mon Sep 17 00:00:00 2001 From: Fabian Fischer <10788152+glrf@users.noreply.github.com> Date: Tue, 14 Dec 2021 12:44:22 +0100 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Chris --- class/defaults.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/class/defaults.yml b/class/defaults.yml index 28a2498d..50d0cd69 100644 --- a/class/defaults.yml +++ b/class/defaults.yml @@ -253,6 +253,7 @@ parameters: # TODO: Rename master to primary when upgrading to Postgres 11 https://github.com/bitnami/charts/commit/7eabc85fd4fae43127228a22829c7ce3fe85c389 master: podAnnotations: + # Annotations to support both K8up v1 and v2 k8up.syn.tools/backupcommand: sh -c 'PGDATABASE="$POSTGRES_DB" PGUSER="$POSTGRES_USER" PGPASSWORD="$POSTGRES_PASSWORD" pg_dump --clean' k8up.syn.tools/file-extension: .sql k8up.io/backupcommand: sh -c 'PGDATABASE="$POSTGRES_DB" PGUSER="$POSTGRES_USER" PGPASSWORD="$POSTGRES_PASSWORD" pg_dump --clean'