Skip to content
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 cnpg-cluster-helm-chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ dependencies:
- name: prometheus-postgres-exporter
repository: https://prometheus-community.github.io/helm-charts
version: 4.4.4
condition: prometheus-postgres-exporter.enabled


8 changes: 5 additions & 3 deletions cnpg-cluster-helm-chart/templates/backup/bucket.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if ne .Values.backup.type "none" }}
apiVersion: s3.advatys.com/v1alpha1
kind: Bucket
metadata:
Expand All @@ -22,9 +23,10 @@ spec:

subjects:
- type: KubernetesServiceAccount
cluster: {{ .Values.kubeClusterName }}
authPath: {{ .Values.kubeClusterName }}
name: {{ include "cnpg-cluster.fullname" . }}-backup
namespace: {{ .Release.Namespace }}
authPath: jwt
effect: Allow
name: {{ include "cnpg-cluster.fullname" . }}-backup-creator
{{- if eq .Values.bootstrap.type "physical" }}
Expand All @@ -40,7 +42,7 @@ spec:

subjects:
- type: KubernetesServiceAccount
cluster: {{ .Values.kubeClusterName }}
authPathr: {{ .Values.kubeClusterName }}
name: {{ include "cnpg-cluster.fullname" . }}-restore
namespace: {{ .Release.Namespace }}
effect: Allow
Expand Down Expand Up @@ -181,4 +183,4 @@ subjects:
- kind: ServiceAccount
name: {{ include "cnpg-cluster.fullname" . }}-backup
namespace: {{ .Release.Namespace }}

{{- end }}
14 changes: 14 additions & 0 deletions cnpg-cluster-helm-chart/templates/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ spec:

{{- if not (eq .Values.bootstrap.type "none") }}
bootstrap:
{{- if eq .Values.bootstrap.type "initdb" }}
initdb:
database: {{ .Values.bootstrap.initdb.database }}
owner: {{ .Values.bootstrap.initdb.databaseOwner }}
secret:
name: {{ .Release.Name }}-app-secret
{{- if .Values.bootstrap.initdb.configmapSQL }}
postInitApplicationSQLRefs:
configMapRefs:
- name: {{ .Release.Name }}-sql
key: script.sql

{{- end }}
{{- end -}}
{{- if eq .Values.bootstrap.type "physical" }}
recovery:
source: {{ .Values.bootstrap.sourceClusterName }}
Expand Down
10 changes: 10 additions & 0 deletions cnpg-cluster-helm-chart/templates/initdb/configmap-sql.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{- if .Values.bootstrap.initdb.configmapSQL }}
apiVersion: v1
data:
{{ toYaml .Values.bootstrap.initdb.configmapSQL | nindent 2}}
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-sql


{{- end }}
10 changes: 10 additions & 0 deletions cnpg-cluster-helm-chart/templates/initdb/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{- if eq .Values.bootstrap.initdb.secret.type "kubernetes" }}
apiVersion: v1
stringData:
username: {{ .Values.bootstrap.initdb.secret.kuberentes.username }}
password: {{ .Values.bootstrap.initdb.secret.kuberentes.password }}
kind: Secret
metadata:
name: {{ .Release.Name }}-app-secret
type: kubernetes.io/basic-auth
{{- end }}
51 changes: 51 additions & 0 deletions cnpg-cluster-helm-chart/templates/initdb/vault-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{{- if eq .Values.bootstrap.initdb.secret.type "vault" }}
apiVersion: generators.external-secrets.io/v1alpha1
kind: VaultDynamicSecret
metadata:
name: "{{ include "cnpg-cluster.fullname" . }}-init-user"
spec:
path: {{ .Values.bootstrap.initdb.secret.vault.path }}
method: "GET"
provider:
server: "{{ .Values.bootstrap.initdb.secret.vault.address }}"
auth:
jwt:
path: "{{ .Values.bootstrap.initdb.secret.vault.authPath }}"
role: "{{ .Values.bootstrap.initdb.secret.vault.autRole }}"

# ... or retrieve a Kubernetes service account token via the `TokenRequest` API
kubernetesServiceAccountToken:
serviceAccountRef:
name: "{{ include "cnpg-cluster.fullname" . }}-init-user"
# `audiences` defaults to `["vault"]` it not supplied
audiences:
- "{{ .Values.bootstrap.initdb.secret.vault.address }}"
# `expirationSeconds` defaults to 10 minutes if not supplied
expirationSeconds: 600
---
apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
name: "{{ include "cnpg-cluster.fullname" . }}-init-user"
spec:
refreshInterval: "1h"
target:
name: "{{ include "cnpg-cluster.fullname" . }}-init-user"
template:
engineVersion: v2
data:
username: "{{ `{{ .username }}` }}"
password: "{{ `{{ .password }}` }}"
dataFrom:
- sourceRef:
generatorRef:
apiVersion: generators.external-secrets.io/v1alpha1
kind: VaultDynamicSecret
name: "{{ include "cnpg-cluster.fullname" . }}-init-user"
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "cnpg-cluster.fullname" . }}-init-user

{{- end }}
27 changes: 25 additions & 2 deletions cnpg-cluster-helm-chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ nameOverride: ""
fullnameOverride: ""

prometheus-postgres-exporter:
enabled: false
config:
datasource:
host: grafana-psql-pgcluster-r.grafana.svc
Expand Down Expand Up @@ -62,14 +63,36 @@ backup:
address: "https://vault.vault.svc.cluster.local:8200"

bootstrap:
# Options:
# Options:
# - none
# - empty-db
# - offline-logical
# - physical
# - streaming-replication
# - online-logical
type: "none"
# - initdb
type: "initdb"

initdb:
database: app
databaseOwner: app
secret:
type: "kubernetes" # Options - "kubernetes, vault-dynamic"
kuberentes:
username: "app"
password: "app"
vault:
path: "secret/kv"
address: "http://vault:8200"
authPath: "jwt-hub"
authRole: "default"
# configmapSQL:
# script.sql: |
# -- SQL Plain Text Here
#




# Reovery target for PITR. Only works for type: physical
# recoveryTarget:
Expand Down