diff --git a/charts/postgres-cluster/Chart.yaml b/charts/postgres-cluster/Chart.yaml index 2b4fcce..e73f81f 100644 --- a/charts/postgres-cluster/Chart.yaml +++ b/charts/postgres-cluster/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: postgres-cluster -version: 1.0.0 +version: 1.1.0 description: Chart for cloudnative-pg cluster keywords: - database diff --git a/charts/postgres-cluster/templates/_boostrap.tpl b/charts/postgres-cluster/templates/_bootstrap.tpl similarity index 64% rename from charts/postgres-cluster/templates/_boostrap.tpl rename to charts/postgres-cluster/templates/_bootstrap.tpl index 8ab054f..bbfdd29 100644 --- a/charts/postgres-cluster/templates/_boostrap.tpl +++ b/charts/postgres-cluster/templates/_bootstrap.tpl @@ -19,8 +19,39 @@ bootstrap: {{- with .Values.cluster.initdb }} {{- range .postInitApplicationSQL }} {{- printf "- %s" . | nindent 6 }} - {{- end -}} - {{- end -}} + {{- end }} + {{- end }} +{{- else if eq .Values.mode "replica" }} + initdb: + import: + type: {{ .Values.replica.importType }} + databases: + {{- if and (len .Values.replica.importDatabases gt 1) (.Values.replica.importType eq "microservice") }} + {{ fail "Too many databases in import type of microservice!" }} + {{- else}} + {{- with .Values.replica.importDatabases }} + {{- . | toYaml | nindent 8 }} + {{- end }} + {{- end }} + {{- if .Values.replica.importType eq "monolith" }} + roles: + {{- with .Values.replica.importRoles }} + {{- . | toYaml | nindent 8 }} + {{- end }} + {{- end }} + {{- if and (.Values.replica.postImportApplicationSQL) (.Values.replica.importType eq "microservice") }} + postImportApplicationSQL: + {{- with .Values.replica.postImportApplicationSQL }} + {{- . | toYaml | nindent 8 }} + {{- end }} + {{- end }} + source: + externalCluster: "postgresql-{{ .Release.Name }}-cluster" +externalClusters: + - name: "postgresql-{{ .Release.Name }}-cluster" + {{- with .Values.replica.externalCluster }} + {{- . | toYaml | nindent 4 }} + {{- end }} {{- else if eq .Values.mode "recovery" }} recovery: {{- with .Values.recovery.pitrTarget.time }} @@ -46,7 +77,7 @@ externalClusters: key: ACCESS_KEY_ID secretAccessKey: name: {{ include "cluster.recovery.credentials" . }} - key: ACCESS_SECRET_KEY + key: ACCESS_SECRET_KEY wal: compression: {{ .Values.recovery.wal.compression }} encryption: {{ .Values.recovery.wal.encryption }} @@ -54,7 +85,7 @@ externalClusters: data: compression: {{ .Values.recovery.data.compression }} encryption: {{ .Values.recovery.data.encryption }} - jobs: {{ .Values.recovery.data.jobs }} + jobs: {{ .Values.recovery.data.jobs }} {{- else }} {{ fail "Invalid cluster mode!" }} {{- end }} diff --git a/charts/postgres-cluster/values.yaml b/charts/postgres-cluster/values.yaml index 76a838b..93ff6f0 100644 --- a/charts/postgres-cluster/values.yaml +++ b/charts/postgres-cluster/values.yaml @@ -12,8 +12,9 @@ type: postgresql ### # Cluster mode of operation. Available modes: -# * `standalone` - default mode. Creates new or updates an existing CNPG cluster. +# * `standalone` - Default mode. Creates new or updates an existing CNPG cluster. # * `recovery` - Same as standalone but creates a cluster from a backup, object store or via pg_basebackup +# * `replica` - Create database as a replica from another CNPG cluster mode: standalone # Generates bucket name and path for recovery and backup, creates: //postgresql/{{ .Release.Name }} @@ -126,6 +127,32 @@ recovery: # Number of data files to be archived or restored in parallel. jobs: 2 +replica: + # See https://cloudnative-pg.io/documentation/current/database_import/ + # * `microservice` - Single database import as expected from cnpg clusters + # * `monolith` - Import multiple databases and roles + importType: microservice + + # If type microservice only one database is allowed, default is app as standard in cnpg clusters + importDatabases: + - app + + # If type microservice no roles are imported and ignored + importRoles: [] + + # If import type is monolith postImportApplicationSQL is not supported and ignored + postImportApplicationSQL: [] + + # External cluster connection, password specifies a secret name and the key containing the password value + externalCluster: + connectionParameters: + host: postgresql + user: app + dbname: app + password: + name: postgresql + key: password + backup: enabled: false