Skip to content

Commit 4f1a350

Browse files
committed
chore(postgresql-cluster):organize code structure
1 parent 9891e10 commit 4f1a350

13 files changed

Lines changed: 311 additions & 22 deletions

File tree

addons/postgresql-cluster/15/chart/postgresql/templates/_helpers.tpl

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ Create the name of the service account to use.
4343
{{- end -}}
4444

4545
{{/*
46-
Return true if a configmap object should be created for MySQL Secondary
46+
Return true if a configmap object should be created for Postgresql HA patroni
4747
*/}}
4848
{{- define "patroni.createConfigmap" -}}
49-
{{- if and .Values.configuration }}
49+
{{- if and .Values.preInitScript }}
5050
{{- true -}}
5151
{{- else -}}
5252
{{- end -}}
@@ -90,6 +90,13 @@ Create patroni envs.
9090
secretKeyRef:
9191
name: {{ template "patroni.fullname" . }}
9292
key: password-replication
93+
- name: PATRONI_REWIND_USERNAME
94+
value: rewinder
95+
- name: PATRONI_REWIND_PASSWORD
96+
valueFrom:
97+
secretKeyRef:
98+
name: {{ template "patroni.fullname" . }}
99+
key: password-rewind
93100
- name: PATRONI_SCOPE
94101
value: {{ template "patroni.fullname" . }}
95102
- name: PATRONI_NAME
@@ -104,6 +111,23 @@ Create patroni envs.
104111
value: '0.0.0.0:5432'
105112
- name: PATRONI_RESTAPI_LISTEN
106113
value: '0.0.0.0:8008'
114+
115+
- name: DATABASE_NAME
116+
valueFrom:
117+
secretKeyRef:
118+
name: {{ template "patroni.fullname" . }}
119+
key: data-name
120+
- name: DATABASE_USER
121+
valueFrom:
122+
secretKeyRef:
123+
name: {{ template "patroni.fullname" . }}
124+
key: data-user
125+
- name: DATABASE_PASSWORD
126+
valueFrom:
127+
secretKeyRef:
128+
name: {{ template "patroni.fullname" . }}
129+
key: data-password
130+
107131
{{- end -}}
108132

109133
{{/*

addons/postgresql-cluster/15/chart/postgresql/templates/configmap.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ metadata:
1313
annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
1414
{{- end }}
1515
data:
16-
patroni.sh: |-
17-
{{- include "common.tplvalues.render" ( dict "value" .Values.configuration "context" $ ) | nindent 4 }}
18-
{{- end -}}
19-
16+
pre_init.sh: |-
17+
{{- include "common.tplvalues.render" ( dict "value" .Values.preInitScript "context" $ ) | nindent 4 }}
18+
post_init.sh: |-
19+
{{- include "common.tplvalues.render" ( dict "value" .Values.postInitScript "context" $ ) | nindent 4 }}
20+
{{- end -}}

addons/postgresql-cluster/15/chart/postgresql/templates/sec.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ metadata:
1212
type: Opaque
1313
data:
1414
password-superuser: {{ .Values.credentials.superuser | b64enc }}
15-
password-admin: {{ .Values.credentials.admin | b64enc }}
16-
password-replication: {{ .Values.credentials.standby | b64enc }}
15+
password-rewind: {{ .Values.credentials.rewind | b64enc }}
16+
password-replication: {{ .Values.credentials.replication | b64enc }}
17+
data-user: {{ .Values.dataname.username | b64enc }}
18+
data-name: {{ .Values.dataname.dbname | b64enc }}
19+
data-password: {{ .Values.dataname.password | b64enc }}

addons/postgresql-cluster/15/chart/postgresql/templates/statefulset.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ spec:
8585
volumeMounts:
8686
- name: storage-volume
8787
mountPath: "{{ .Values.persistentVolume.mountPath }}"
88-
- mountPath: "/opt/drycc/scripts/patroni/"
88+
- mountPath: "/opt/drycc/postgresql/scripts/"
8989
name: patroni-config
9090
# readOnly: true
9191
{{- if .Values.walE.enable }}

addons/postgresql-cluster/15/chart/postgresql/values.yaml

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@ replicaCount: 3
33
image:
44
# Image was built from registry.drycc.cc/drycc-addons/patroni:3.2
55
# https://github.com/zalando/spilo/tree/master/postgres-appliance
6-
repository: registry.drycc.cc/drycc-addons/patroni
7-
tag: 3.2
6+
repository: registry.drycc.cc/drycc-addons/postgresql-patroni
7+
tag: 15
88
# IfNotPresent , Always
99
pullPolicy: 'IfNotPresent'
1010

11-
# Credentials used by Patroni
11+
# Credentials used by Patroni , passwd
1212
# https://github.com/zalando/patroni/blob/master/docs/SETTINGS.rst#postgresql
1313
# https://github.com/zalando/spilo/blob/master/ENVIRONMENT.rst
1414
credentials:
1515
superuser: tea
16-
admin: cola
17-
standby: reppasswd
16+
rewind: cola
17+
replication: reppasswd
18+
19+
dataname:
20+
dbname: db1
21+
username: us1
22+
password: 111w
1823

1924
# Distribution Configuration stores
2025
# Please note that only one of the following stores should be enabled.
@@ -30,8 +35,8 @@ env: {}
3035
#
3136
#custom patroni.yaml used by patroni boot
3237
# configuration: {}
33-
configuration: |
34-
cat > /home/postgres/patroni.yml <<__EOF__
38+
preInitScript: |
39+
cat > /opt/drycc/postgresql/patroni.yml <<__EOF__
3540
log:
3641
level: DEBUG
3742
bootstrap:
@@ -40,12 +45,13 @@ configuration: |
4045
use_pg_rewind: true
4146
use_slots: true
4247
pg_hba:
48+
- local all all peer
4349
- host all all 0.0.0.0/0 scram-sha-256
4450
- host replication ${PATRONI_REPLICATION_USERNAME} 0.0.0.0/0 scram-sha-256
4551
parameters:
4652
wal_level: hot_standby
4753
hot_standby: "on"
48-
max_connections: 1000
54+
max_connections: 1005
4955
max_worker_processes: 8
5056
wal_keep_segments: 8
5157
max_wal_senders: 10
@@ -56,23 +62,52 @@ configuration: |
5662
track_commit_timestamp: "off"
5763
archive_mode: "on"
5864
archive_timeout: 1800s
65+
archive_command: /bin/true
66+
# timescaledb.license: 'timescale'
67+
shared_preload_libraries: 'auto_explain,pg_stat_statements'
5968
initdb:
60-
- auth-host: scram-sha-256
61-
- auth-local: trust
62-
- encoding: UTF8
63-
- locale: en_US.UTF-8
64-
- data-checksums
69+
- auth-host: scram-sha-256
70+
- auth-local: trust
71+
- encoding: UTF8
72+
- locale: en_US.UTF-8
73+
- data-checksums
74+
post_bootstrap: sh /opt/drycc/postgresql/scripts/post_init.sh
6575
restapi:
6676
connect_address: '${PATRONI_KUBERNETES_POD_IP}:8008'
6777
postgresql:
6878
connect_address: '${PATRONI_KUBERNETES_POD_IP}:5432'
6979
authentication:
7080
superuser:
81+
username: postgres
7182
password: '${PATRONI_SUPERUSER_PASSWORD}'
7283
replication:
84+
username: standby
7385
password: '${PATRONI_REPLICATION_PASSWORD}'
86+
rewind: # Has no effect on postgres 10 and lower
87+
username: rewinder
88+
password: '${PATRONI_REWIND_USERNAME}'
89+
watchdog:
90+
mode: off
7491
__EOF__
7592
93+
postInitScript: |
94+
#!/bin/bash
95+
set -Eeu
96+
# Create monitor user
97+
psql -w -c "CREATE USER tea_mon WITH ROLE pg_monitor"
98+
# Create init database & user
99+
if [[( -n "$DATABASE_USER") && ( -n "$DATABASE_PASSWORD") && ( -n "$DATABASE_NAME")]]; then
100+
echo "Creating user ${DATABASE_USER}"
101+
psql -w -c "create user ${DATABASE_USER} WITH LOGIN ENCRYPTED PASSWORD '${DATABASE_PASSWORD}'"
102+
echo "Creating database ${DATABASE_NAME} "
103+
psql -w -c "CREATE DATABASE ${DATABASE_NAME} OWNER ${DATABASE_USER} CONNECTION LIMIT 1000"
104+
psql -w -d ${DATABASE_NAME} -c "create extension postgis"
105+
psql -w -c "CHECKPOINT;CHECKPOINT;"
106+
else
107+
echo "Skipping user creation"
108+
echo "Skipping database creation"
109+
fi
110+
76111
walE:
77112
# Specifies whether Wal-E should be enabled
78113
enable: false
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
credential:
2+
{{- if (eq .Values.router.service.type "LoadBalancer") }}
3+
- name: host
4+
valueFrom:
5+
secretKeyRef:
6+
name: {{ template "common.names.fullname" . }}-svcbind-custom-user
7+
jsonpath: '{ .data.host }'
8+
- name: database
9+
valueFrom:
10+
secretKeyRef:
11+
name: {{ template "common.names.fullname" . }}-svcbind-custom-user
12+
jsonpath: '{ .data.database }'
13+
- name: password
14+
valueFrom:
15+
secretKeyRef:
16+
name: {{ template "common.names.fullname" . }}-svcbind-custom-user
17+
jsonpath: '{ .data.password }'
18+
- name: username
19+
valueFrom:
20+
secretKeyRef:
21+
name: {{ template "common.names.fullname" . }}-svcbind-custom-user
22+
jsonpath: '{ .data.username }'
23+
- name: portro
24+
valueFrom:
25+
secretKeyRef:
26+
name: {{ template "common.names.fullname" . }}-svcbind-custom-user
27+
jsonpath: '{ .data.portro }'
28+
- name: portrw
29+
valueFrom:
30+
secretKeyRef:
31+
name: {{ template "common.names.fullname" . }}-svcbind-custom-user
32+
jsonpath: '{ .data.portrw }'
33+
{{- end }}
34+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"type": "object",
4+
"properties": {
5+
"imagePullPolicy": {
6+
"type": "string",
7+
"enum": ["Always", "IfNotPresent", "Never"],
8+
"default": "IfNotPresent",
9+
"title": "Image pull policy"
10+
}
11+
}
12+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: "standard-10"
2+
id: 2b455154-8725-482a-95b2-a193c180d9b5
3+
description: "Mysql Cluster standard-10 plan: Disk 10Gi ,vCPUs 1 , RAM 2G , DB MAX Connection 600"
4+
displayName: "standard-10"
5+
bindable: true
6+
maximum_polling_duration: 1800
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
## @param fullnameOverride String to fully override common.names.fullname template
2+
##
3+
fullnameOverride: hb-mysql-cluster-standard-10
4+
5+
## MinIO&reg; containers' resource requests and limits
6+
## ref: https://kubernetes.io/docs/user-guide/compute-resources/
7+
## We usually recommend not to specify default resources and to leave this as a conscious
8+
## choice for the user. This also increases chances charts run on environments with little
9+
## resources, such as Minikube. If you do want to specify resources, uncomment the following
10+
## lines, adjust them as necessary, and remove the curly braces after 'resources:'.
11+
## @param resources.limits The resources limits for the MinIO&reg; container
12+
## @param resources.requests The requested resources for the MinIO&reg; container
13+
##
14+
primary:
15+
maxConnectionLimit: 600
16+
resources:
17+
limits:
18+
cpu: 1000m
19+
memory: 1024Mi
20+
requests:
21+
cpu: 1000m
22+
memory: 1024Mi
23+
24+
25+
## @section Persistence parameters
26+
27+
## Enable persistence using Persistent Volume Claims
28+
## ref: https://kubernetes.io/docs/user-guide/persistent-volumes/
29+
##
30+
persistence:
31+
## @param primary.persistence.enabled Enable persistence on MySQL primary replicas using a `PersistentVolumeClaim`. If false, use emptyDir
32+
##
33+
enabled: true
34+
## @param primary.persistence.existingClaim Name of an existing `PersistentVolumeClaim` for MySQL primary replicas
35+
## NOTE: When it's set the rest of persistence parameters are ignored
36+
##
37+
existingClaim: ""
38+
## @param primary.persistence.storageClass MySQL primary persistent volume storage Class
39+
## If defined, storageClassName: <storageClass>
40+
## If set to "-", storageClassName: "", which disables dynamic provisioning
41+
## If undefined (the default) or set to null, no storageClassName spec is
42+
## set, choosing the default provisioner. (gp2 on AWS, standard on
43+
## GKE, AWS & OpenStack)
44+
##
45+
storageClass: ""
46+
## @param primary.persistence.annotations MySQL primary persistent volume claim annotations
47+
##
48+
annotations: {}
49+
## @param primary.persistence.accessModes MySQL primary persistent volume access Modes
50+
##
51+
accessModes:
52+
- ReadWriteOnce
53+
## @param primary.persistence.size MySQL primary persistent volume size
54+
##
55+
size: 10Gi
56+
## @param primary.persistence.selector Selector to match an existing Persistent Volume
57+
## selector:
58+
## matchLabels:
59+
## app: my-app
60+
##
61+
selector: {}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
credential:
2+
{{- if (eq .Values.router.service.type "LoadBalancer") }}
3+
- name: host
4+
valueFrom:
5+
secretKeyRef:
6+
name: {{ template "common.names.fullname" . }}-svcbind-custom-user
7+
jsonpath: '{ .data.host }'
8+
- name: database
9+
valueFrom:
10+
secretKeyRef:
11+
name: {{ template "common.names.fullname" . }}-svcbind-custom-user
12+
jsonpath: '{ .data.database }'
13+
- name: password
14+
valueFrom:
15+
secretKeyRef:
16+
name: {{ template "common.names.fullname" . }}-svcbind-custom-user
17+
jsonpath: '{ .data.username }'
18+
- name: username
19+
valueFrom:
20+
secretKeyRef:
21+
name: {{ template "common.names.fullname" . }}-svcbind-custom-user
22+
jsonpath: '{ .data.username }'
23+
- name: portro
24+
valueFrom:
25+
secretKeyRef:
26+
name: {{ template "common.names.fullname" . }}-svcbind-custom-user
27+
jsonpath: '{ .data.portro }'
28+
- name: portrw
29+
valueFrom:
30+
secretKeyRef:
31+
name: {{ template "common.names.fullname" . }}-svcbind-custom-user
32+
jsonpath: '{ .data.portrw }'
33+
{{- end }}
34+

0 commit comments

Comments
 (0)