Skip to content

Commit

Permalink
feat: ✨ handle cnpg replication mode
Browse files Browse the repository at this point in the history
  • Loading branch information
this-is-tobi committed Jul 9, 2024
1 parent 1e9737f commit 837fcee
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 4 deletions.
2 changes: 1 addition & 1 deletion charts/dso-console/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: cpn-console
description: A Helm chart to deploy Cloud Pi Native Console
type: application
version: 1.4.7
version: 1.5.7
appVersion: 8.7.1
keywords: []
home: https://cloud-pi-native.fr
Expand Down
7 changes: 6 additions & 1 deletion charts/dso-console/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# cpn-console

![Version: 1.4.7](https://img.shields.io/badge/Version-1.4.7-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 8.7.1](https://img.shields.io/badge/AppVersion-8.7.1-informational?style=flat-square)
![Version: 1.5.7](https://img.shields.io/badge/Version-1.5.7-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 8.7.1](https://img.shields.io/badge/AppVersion-8.7.1-informational?style=flat-square)

A Helm chart to deploy Cloud Pi Native Console

Expand Down Expand Up @@ -98,10 +98,15 @@ A Helm chart to deploy Cloud Pi Native Console
| cnpg.dbName | string | `"dso-console-db"` | Name of the database. |
| cnpg.enableSuperuserAccess | bool | `true` | Enable superuser access. |
| cnpg.enabled | bool | `false` | Whether or not cnpg cluster deployment should be enabled. |
| cnpg.exposed | bool | `false` | Whether or not a NodePort service should be created to exposed the database. |
| cnpg.instances | int | `3` | Number of instances to spawn in the cluster. |
| cnpg.mode | string | `"primary"` | Mode used to deploy the cnpg cluster, it should be `primary` or `replica`. |
| cnpg.nameOverride | string | `""` | Provide a name in place of the default cnpg cluster name. |
| cnpg.nodePort | string | `nil` | Port used for NodePort service. Needs `exposed` tu be true. |
| cnpg.primaryUpdateStrategy | string | `"unsupervised"` | Rolling update strategy used : unsupervised: automated update of the primary once all replicas have been upgraded (default) supervised: requires manual supervision to perform the switchover of the primary |
| cnpg.pvcSize | string | `"10Gi"` | Size of the PVC used by each cnpg instance. |
| cnpg.replica.host | string | `nil` | Primary cnpg cluster host used for replica mode. |
| cnpg.replica.port | string | `nil` | Primary cnpg cluster port used for replica mode. |
| cnpg.username | string | `"dso"` | Username of the database user. |
| config.create | bool | `false` | Whether or not helm should create the console config. |
| config.name | string | `"dso-config"` | Name of the genrated config. |
Expand Down
42 changes: 40 additions & 2 deletions charts/dso-console/templates/cnpg/pg-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,53 @@ spec:
max_worker_processes: "60"
pg_hba:
- {{ printf "%s %s %s %s %s" "host" .Values.cnpg.dbName .Values.cnpg.username "all" "md5" }}
- {{ printf "%s %s %s %s %s" "host" .Values.cnpg.dbName "streaming_replica" "all" "md5" }}
bootstrap:
{{- if eq .Values.cnpg.mode "primary" }}
initdb:
database: {{ .Values.cnpg.dbName }}
owner: {{ .Values.cnpg.username }}
{{- else if eq .Values.cnpg.mode "replica" }}
recovery:
source: cluster-primary
replica:
enabled: true
source: cluster-primary
externalClusters:
- name: cluster-primary
barmanObjectStore:
destinationPath: {{ .Values.cnpg.backup.destinationPath }}
endpointURL: {{ .Values.cnpg.backup.endpointURL }}
endpointCA:
name: {{ .Values.cnpg.backup.endpointCA.name }}
key: {{ .Values.cnpg.backup.endpointCA.key }}
s3Credentials:
accessKeyId:
name: {{ .Values.cnpg.backup.s3Credentials.name | default (printf "%s-%s" (include "cpnConsole.fullname" .) "pg-cluster") }}
key: {{ .Values.cnpg.backup.s3Credentials.accessKeyId.key }}
secretAccessKey:
name: {{ .Values.cnpg.backup.s3Credentials.name | default (printf "%s-%s" (include "cpnConsole.fullname" .) "pg-cluster") }}
key: {{ .Values.cnpg.backup.s3Credentials.secretAccessKey.key }}
connectionParameters:
host: {{ .Values.cnpg.replica.host }}
port: {{ .Values.cnpg.replica.port }}
dbname: {{ .Values.cnpg.dbName }}
sslmode: prefer
sslKey:
name: {{ (printf "%s-%s" .Values.cnpg.nameOverride "replication") | default (printf "%s-%s-%s" (include "cpnConsole.fullname" .) "pg-cluster" "replication") }}
key: tls.key
sslCert:
name: {{ (printf "%s-%s" .Values.cnpg.nameOverride "replication") | default (printf "%s-%s-%s" (include "cpnConsole.fullname" .) "pg-cluster" "replication") }}
key: tls.crt
sslRootCert:
name: {{ (printf "%s-%s" .Values.cnpg.nameOverride "ca") | default (printf "%s-%s-%s" (include "cpnConsole.fullname" .) "pg-cluster" "ca") }}
key: ca.crt
{{- end }}
enableSuperuserAccess: {{ .Values.cnpg.enableSuperuserAccess }}
primaryUpdateStrategy: {{ .Values.cnpg.primaryUpdateStrategy }}
storage:
size: {{ .Values.cnpg.pvcSize }}
{{- if .Values.cnpg.backup.enabled }}
{{- if .Values.cnpg.backup.enabled }}
backup:
barmanObjectStore:
destinationPath: {{ .Values.cnpg.backup.destinationPath }}
Expand All @@ -46,5 +84,5 @@ spec:
name: {{ .Values.cnpg.backup.s3Credentials.name | default (printf "%s-%s" (include "cpnConsole.fullname" .) "pg-cluster") }}
key: {{ .Values.cnpg.backup.s3Credentials.secretAccessKey.key }}
retentionPolicy: {{ .Values.cnpg.backup.retentionPolicy }}
{{- end }}
{{- end }}
{{- end }}
22 changes: 22 additions & 0 deletions charts/dso-console/templates/cnpg/service-nodeport.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{- if and .Values.cnpg.enabled .Values.cnpg.exposed }}
apiVersion: v1
kind: Service
metadata:
name: {{ (printf "%s-%s" .Values.cnpg.nameOverride "rw-nodeport") | default (printf "%s-%s" (include "cpnConsole.fullname" .) "pg-cluster") }}
labels:
{{- include "cpnConsole.common.labels" . | nindent 4 }}
annotations:
{{- with .Values.cnpg.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
ports:
- name: postgres
port: 5432
protocol: TCP
nodePort: {{ .Values.cnpg.nodePort }}
selector:
cnpg.io/cluster: {{ .Values.cnpg.nameOverride | default (printf "%s-%s" (include "cpnConsole.fullname" .) "pg-cluster") }}
role: primary
type: NodePort
{{- end }}
11 changes: 11 additions & 0 deletions charts/dso-console/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,17 @@ cnpg:
pvcSize: "10Gi"
# -- Additional cnpg cluster annotations.
annotations: {}
# -- Whether or not a NodePort service should be created to exposed the database.
exposed: false
# -- Port used for NodePort service. Needs `exposed` tu be true.
nodePort:
# -- Mode used to deploy the cnpg cluster, it should be `primary` or `replica`.
mode: "primary"
replica:
# -- Primary cnpg cluster host used for replica mode.
host:
# -- Primary cnpg cluster port used for replica mode.
port:
backup:
# -- Whether or not cnpg cluster deployment should be enabled.
enabled: false
Expand Down

0 comments on commit 837fcee

Please sign in to comment.