Skip to content

Commit db9480c

Browse files
committed
This commit integrates the 'crunchy-postgres-ha'
container into the PGO. Now when clusters are created, as well as when additional replicas are added to existing clusters, the 'crunchy-postgres-ha' container is utilized instead of the 'crunchy-postgres' container. This effectively introduces integrates Patroni into the PGO architecture, which will be leveraged to bootstrap, manage and ensure the availability of any PG databases and clusters created by the PGO. With the introduction of the 'crunchy-postgres-ha' container, an additional service account named 'pgo-pg' is now created and utilized by any PG deployments, with any permissions required by Patroni to create and modify the various artifacts in Kubernetes required to support the Patroni solution. Also, Patroni environment variables are utilized to configure the 'crunchy-postgres-ha' container, along with a Patroni configuration file and applicable Kubernetes secrets. Being that this change represents a major change to the PGO architecture, this is considered a breaking change that will not be backwards compatible with an PG clusters previously created by the PGO. Please note that this commit also does not yet deprecate or update any failover logic, as required to fully leverage the HA capabilities provided by Patroni in the 'crunchy-postgres-ha' container (these updates will be provided in a subsequent commit).
1 parent ee21e61 commit db9480c

File tree

13 files changed

+555
-193
lines changed

13 files changed

+555
-193
lines changed

apiserver/clusterservice/clusterimpl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ func getClusterParams(request *msgs.CreateClusterRequest, name string, userLabel
859859
spec.CCPImage = request.CCPImage
860860
log.Debugf("user is overriding CCPImage from command line %s", request.CCPImage)
861861
} else {
862-
spec.CCPImage = "crunchy-postgres"
862+
spec.CCPImage = "crunchy-postgres-ha"
863863
}
864864
spec.Namespace = ns
865865
spec.Name = name

conf/postgres-operator/cluster-deployment.json

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"spec": {
2828

2929
{{.SecurityContext }}
30-
30+
"serviceAccountName": "pgo-pg",
3131
"containers": [
3232

3333

@@ -37,7 +37,7 @@
3737
"readinessProbe": {
3838
"exec": {
3939
"command": [
40-
"/opt/cpm/bin/readiness.sh"
40+
"/opt/cpm/bin/readiness/readiness.sh"
4141
]
4242
},
4343
"initialDelaySeconds": 15,
@@ -47,39 +47,51 @@
4747
{{.ContainerResources }}
4848

4949
"env": [{
50-
"name": "PG_PRIMARY_PORT",
50+
"name": "PGHA_PG_PORT",
5151
"value": "{{.Port}}"
5252
}, {
53-
"name": "PG_MODE",
54-
"value": "{{.PgMode}}"
55-
}, {
56-
"name": "PG_USER",
53+
"name": "PGHA_USER",
5754
"value": "postgres"
5855
}, {
59-
"name": "PG_PRIMARY_HOST",
60-
"value": "{{.PrimaryHost}}"
61-
}, {
62-
"name": "LOG_STATEMENT",
63-
"value": "{{.LogStatement}}"
64-
}, {
65-
"name": "LOG_MIN_DURATION_STATEMENT",
66-
"value": "{{.LogMinDurationStatement}}"
67-
}, {
68-
"name": "PG_LOCALE",
69-
"value": "en_US.UTF8"
70-
}, {
71-
"name": "PGDATA_PATH_OVERRIDE",
72-
"value": "{{.DataPathOverride}}"
56+
"name": "PATRONI_POSTGRESQL_DATA_DIR",
57+
"value": "/pgdata/{{.Name}}"
7358
}, {
7459
{{.PgmonitorEnvVars}}
7560
{{.PgbackrestEnvVars}}
7661
{{.PgbackrestS3EnvVars}}
77-
"name": "PG_DATABASE",
62+
"name": "PGHA_DATABASE",
7863
"value": "{{.Database}}"
79-
},{
80-
"name": "ARCHIVE_TIMEOUT",
81-
"value": "{{.ArchiveTimeout}}"
82-
},{
64+
}, {
65+
"name": "PATRONI_KUBERNETES_NAMESPACE",
66+
"valueFrom": {
67+
"fieldRef": {
68+
"fieldPath": "metadata.namespace"
69+
}
70+
}
71+
}, {
72+
"name": "PATRONI_NAME",
73+
"valueFrom": {
74+
"fieldRef": {
75+
"fieldPath": "metadata.name"
76+
}
77+
}
78+
}, {
79+
"name": "PATRONI_SCOPE",
80+
"valueFrom": {
81+
"fieldRef": {
82+
"fieldPath": "metadata.labels['pg-cluster']"
83+
}
84+
}
85+
}, {
86+
"name": "PATRONI_KUBERNETES_LABELS",
87+
"value": "{vendor: \"crunchydata\"}"
88+
}, {
89+
"name": "PATRONI_KUBERNETES_SCOPE_LABEL",
90+
"value": "{{.ScopeLabel}}"
91+
}, {
92+
"name": "PATRONI_LOG_LEVEL",
93+
"value": "INFO"
94+
}, {
8395
"name": "PGHOST",
8496
"value": "/tmp"
8597
}],
@@ -93,13 +105,13 @@
93105
"mountPath": "/backrestrepo",
94106
"name": "backrestrepo"
95107
}, {
96-
"mountPath": "/pguser",
108+
"mountPath": "/pgconf/pguser",
97109
"name": "user-volume"
98110
}, {
99-
"mountPath": "/pgprimary",
111+
"mountPath": "/pgconf/pgreplicator",
100112
"name": "primary-volume"
101113
}, {
102-
"mountPath": "/pgroot",
114+
"mountPath": "/pgconf/pgsuper",
103115
"name": "root-volume"
104116
}, {
105117
"mountPath": "/pgwal",
@@ -115,7 +127,7 @@
115127
"mountPath": "/recover",
116128
"name": "recover-volume"
117129
}
118-
130+
119131
],
120132

121133
"ports": [{
@@ -172,7 +184,23 @@
172184
"emptyDir": { "medium": "Memory" }
173185
}, {
174186
"name": "pgconf-volume",
175-
{{.ConfVolume}}
187+
"projected": {
188+
"sources": [
189+
{{if .ConfVolume}}
190+
{
191+
"configMap": {
192+
"name": {{.ConfVolume}}
193+
}
194+
},
195+
{{end}}
196+
{
197+
"configMap": {
198+
"name": "pgo-pgha-default-config",
199+
"optional": true
200+
}
201+
}
202+
]
203+
}
176204
}
177205

178206
],

conf/postgres-operator/pgbackrest-env-vars.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
}, {
2222
"name": "PGBACKREST_LOG_PATH",
2323
"value": "/tmp"
24+
}, {
25+
"name": "PGBACKREST_PG1_SOCKET_PATH",
26+
"value": "/tmp"
2427
}, {
2528
"name": "PGBACKREST_PG1_PORT",
2629
"value": "{{.PgbackrestPGPort}}"

conf/postgres-operator/pgo-backrest-repo-template.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
}, {
6363
"name": "PGBACKREST_LOG_PATH",
6464
"value": "/tmp"
65+
}, {
66+
"name": "PGBACKREST_PG1_SOCKET_PATH",
67+
"value": "/tmp"
6568
}, {
6669
"name": "PGBACKREST_DB_HOST",
6770
"value": "{{.PGbackrestDBHost}}"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"apiVersion":"rbac.authorization.k8s.io/v1",
3+
"kind":"RoleBinding",
4+
"metadata":{
5+
"name":"pgo-pg-role-binding",
6+
"namespace":"{{.TargetNamespace}}",
7+
"labels":{
8+
"vendor":"crunchydata"
9+
}
10+
},
11+
"roleRef":{
12+
"apiGroup":"rbac.authorization.k8s.io",
13+
"kind":"Role",
14+
"name":"pgo-pg-role"
15+
},
16+
"subjects":[
17+
{
18+
"kind":"ServiceAccount",
19+
"name":"pgo-pg"
20+
}
21+
]
22+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"apiVersion":"rbac.authorization.k8s.io/v1",
3+
"kind":"Role",
4+
"metadata":{
5+
"name":"pgo-pg-role",
6+
"namespace":"{{.TargetNamespace}}",
7+
"labels":{
8+
"vendor":"crunchydata"
9+
}
10+
},
11+
"rules":[
12+
{
13+
"apiGroups":[
14+
""
15+
],
16+
"resources":[
17+
"configmaps"
18+
],
19+
"verbs":[
20+
"create",
21+
"get",
22+
"list",
23+
"patch",
24+
"update",
25+
"watch",
26+
"delete",
27+
"deletecollection"
28+
]
29+
},
30+
{
31+
"apiGroups":[
32+
""
33+
],
34+
"resources":[
35+
"pods"
36+
],
37+
"verbs":[
38+
"get",
39+
"list",
40+
"patch",
41+
"update",
42+
"watch"
43+
]
44+
}
45+
]
46+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"apiVersion":"v1",
3+
"kind":"ServiceAccount",
4+
"metadata":{
5+
"name":"pgo-pg",
6+
"namespace":"{{.TargetNamespace}}",
7+
"labels":{
8+
"vendor":"crunchydata"
9+
}
10+
}
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
bootstrap:
3+
dcs:
4+
postgresql:
5+
parameters:
6+
archive_timeout: {{.ArchiveTimeout}}
7+
log_min_duration_statement: {{.LogMinDurationStatement}}
8+
log_statement: {{.LogStatement}}
9+
initdb:
10+
- encoding: UTF8

config/pgoconfig.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ var PgoTargetRoleTemplate *template.Template
6161

6262
const PGOTargetRolePath = "pgo-target-role.json"
6363

64+
var PgoPgServiceAccountTemplate *template.Template
65+
66+
const PGOPgServiceAccountPath = "pgo-pg-sa.json"
67+
68+
var PgoPgRoleTemplate *template.Template
69+
70+
const PGOPgRolePath = "pgo-pg-role.json"
71+
72+
var PgoPgRoleBindingTemplate *template.Template
73+
74+
const PGOPgRoleBindingPath = "pgo-pg-role-binding.json"
75+
6476
var BenchmarkJobTemplate *template.Template
6577

6678
const benchmarkJobPath = "pgbench-job.json"
@@ -193,6 +205,10 @@ var DeploymentTemplate *template.Template
193205

194206
const deploymentTemplatePath = "cluster-deployment.json"
195207

208+
var PostgresHaTemplate *template.Template
209+
210+
const PostgresHaTemplatePath = "postgres-ha.yaml"
211+
196212
type ClusterStruct struct {
197213
CCPImagePrefix string `yaml:"CCPImagePrefix"`
198214
CCPImageTag string `yaml:"CCPImageTag"`
@@ -635,6 +651,18 @@ func (c *PgoConfig) GetConfig(clientset *kubernetes.Clientset, namespace string)
635651
if err != nil {
636652
return err
637653
}
654+
PgoPgServiceAccountTemplate, err = c.LoadTemplate(cMap, rootPath, PGOPgServiceAccountPath)
655+
if err != nil {
656+
return err
657+
}
658+
PgoPgRoleTemplate, err = c.LoadTemplate(cMap, rootPath, PGOPgRolePath)
659+
if err != nil {
660+
return err
661+
}
662+
PgoPgRoleBindingTemplate, err = c.LoadTemplate(cMap, rootPath, PGOPgRoleBindingPath)
663+
if err != nil {
664+
return err
665+
}
638666

639667
BenchmarkJobTemplate, err = c.LoadTemplate(cMap, rootPath, benchmarkJobPath)
640668
if err != nil {
@@ -802,7 +830,16 @@ func (c *PgoConfig) GetConfig(clientset *kubernetes.Clientset, namespace string)
802830
}
803831

804832
DeploymentTemplate, err = c.LoadTemplate(cMap, rootPath, deploymentTemplatePath)
805-
return err
833+
if err != nil {
834+
return err
835+
}
836+
837+
PostgresHaTemplate, err = c.LoadTemplate(cMap, rootPath, PostgresHaTemplatePath)
838+
if err != nil {
839+
return err
840+
}
841+
842+
return nil
806843
}
807844

808845
func getRootPath(clientset *kubernetes.Clientset, namespace string) (*v1.ConfigMap, string) {

0 commit comments

Comments
 (0)