From ed6ef99bb783b4f0ea245609f507f3c76216dff4 Mon Sep 17 00:00:00 2001 From: Shahab Dogar Date: Sat, 6 Sep 2025 19:38:05 +0500 Subject: [PATCH] feat: add barman plugin into postgres cluster --- postgres/index.ts | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/postgres/index.ts b/postgres/index.ts index b597027..33776f8 100644 --- a/postgres/index.ts +++ b/postgres/index.ts @@ -17,6 +17,7 @@ type PostgresClusterOptions = { initSecretName: string; certManagerApiVersion: string; version: string; + backupR2EndpointURL: string; }; export class PostgresCluster extends Construct { @@ -34,6 +35,44 @@ export class PostgresCluster extends Construct { namespace: options.namespace, }); + const destinationPath = "s3://rihla-backups/"; + + const endpointURL = options.backupR2EndpointURL; + const barmanConfiguration = { + destinationPath, + endpointURL, + s3Credentials: { + accessKeyId: { + name: "cloudflare-r2-token", + key: "access_key", + }, + secretAccessKey: { + name: "cloudflare-r2-token", + key: "secret_key", + }, + }, + }; + + new Manifest(this, "r2-backup-store", { + provider: kubernetes, + manifest: { + apiVersion: "barmancloud.cnpg.io/v1", + kind: "ObjectStore", + metadata: { + namespace: options.namespace, + name: "r2-postgres-backup-store", + }, + spec: { + configuration: { + ...barmanConfiguration, + wal: { + compression: "gzip", + }, + }, + }, + }, + }); + const { certManagerApiVersion } = options; const certNames = { @@ -296,6 +335,15 @@ export class PostgresCluster extends Construct { "hostssl sameuser all all cert", ], }, + plugins: [ + { + name: "barman-cloud.cloudnative-pg.io", + isWALArchiver: true, + parameters: { + barmanObjectName: "r2-postgres-backup-store", + }, + }, + ], enableSuperuserAccess: false, bootstrap: { initdb: {