Skip to content

Commit 891315a

Browse files
author
jmccormick2001
committed
fix pgbackrest env var processing and remove pgbackrest.conf references
1 parent 89e66b1 commit 891315a

File tree

9 files changed

+55
-35
lines changed

9 files changed

+55
-35
lines changed

conf/postgres-operator/cluster/1/cluster-deployment-1.json

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,7 @@
6565
"name": "PGDATA_PATH_OVERRIDE",
6666
"value": "{{.DataPathOverride}}"
6767
}, {
68-
"name": "PGBACKREST_STANZA",
69-
"value": "{{.PgbackrestStanza}}"
70-
}, {
71-
"name": "PGBACKREST_DB_PATH",
72-
"value": "{{.PgbackrestDBPath}}"
73-
}, {
74-
"name": "PGBACKREST_REPO_PATH",
75-
"value": "{{.PgbackrestRepoPath}}"
76-
}, {
77-
"name": "PGBACKREST_LOG_PATH",
78-
"value": "/tmp"
79-
}, {
68+
{{.PgbackrestEnvVars}}
8069
"name": "PG_DATABASE",
8170
"value": "{{.Database}}"
8271
}, {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"name": "PGBACKREST_STANZA",
2+
"value": "{{.PgbackrestStanza}}"
3+
}, {
4+
"name": "PGBACKREST_DB_PATH",
5+
"value": "{{.PgbackrestDBPath}}"
6+
}, {
7+
"name": "PGBACKREST_REPO_PATH",
8+
"value": "{{.PgbackrestRepoPath}}"
9+
}, {
10+
"name": "PGBACKREST_LOG_PATH",
11+
"value": "/tmp"
12+
}, {

conf/postgres-operator/pgo.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Cluster:
44
CCPImagePrefix: crunchydata
55
Metrics: false
66
Badger: false
7-
CCPImageTag: centos7-10.6-2.2.0
7+
CCPImageTag: rhel7-10.6-2.2.0-rc8
88
Port: 5432
99
User: testuser
1010
Database: userdb
@@ -19,9 +19,9 @@ Cluster:
1919
Autofail: false
2020
LogStatement: none
2121
LogMinDurationStatement: 60000
22-
PrimaryStorage: hostpathstorage
23-
BackupStorage: hostpathstorage
24-
ReplicaStorage: hostpathstorage
22+
PrimaryStorage: nfsstorage
23+
BackupStorage: nfsstorage
24+
ReplicaStorage: nfsstorage
2525
Storage:
2626
hostpathstorage:
2727
AccessMode: ReadWriteMany
@@ -62,4 +62,4 @@ Pgo:
6262
LSPVCTemplate: /pgo-config/pgo.lspvc-template.json
6363
LoadTemplate: /pgo-config/pgo.load-template.json
6464
COImagePrefix: crunchydata
65-
COImageTag: centos7-3.4.0
65+
COImageTag: rhel7-3.4.0

deploy/cleanup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ if [ "$CO_UI" = "true" ]; then
2323
$CO_CMD $NS delete configmap pgo-ui-conf
2424
fi
2525

26-
$CO_CMD $NS delete configmap pgo-pgbackrest-config
26+
#$CO_CMD $NS delete configmap pgo-pgbackrest-config
2727

2828
$CO_CMD $NS delete secret pgo-auth-secret
2929
$CO_CMD $NS delete configmap pgo-config

deploy/deploy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ then
2929
exit
3030
fi
3131

32-
$CO_CMD create configmap pgo-pgbackrest-config --from-file=$DIR/pgbackrest.conf
32+
#$CO_CMD create configmap pgo-pgbackrest-config --from-file=$DIR/pgbackrest.conf
3333

3434
$CO_CMD $NS create secret generic pgo-auth-secret \
3535
--from-file=server.crt=$COROOT/conf/postgres-operator/server.crt \

examples/custom-config/pgbackrest.conf

Lines changed: 0 additions & 6 deletions
This file was deleted.

operator/cluster/cluster.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,13 @@ type DeploymentTemplateFields struct {
8686
ConfVolume string
8787
CollectAddon string
8888
BadgerAddon string
89+
PgbackrestEnvVars string
8990
//next 2 are for the replica deployment only
9091
Replicas string
9192
PrimaryHost string
92-
//next are for pgbackrest
93+
}
94+
95+
type PgbackrestEnvVarsTemplateFields struct {
9396
PgbackrestStanza string
9497
PgbackrestDBPath string
9598
PgbackrestRepoPath string

operator/cluster/cluster_strategy_1.go

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ func (r Strategy1) AddCluster(clientset *kubernetes.Clientset, client *rest.REST
154154
ConfVolume: GetConfVolume(clientset, cl, namespace),
155155
CollectAddon: GetCollectAddon(clientset, namespace, &cl.Spec),
156156
BadgerAddon: GetBadgerAddon(clientset, namespace, &cl.Spec),
157-
PgbackrestStanza: "db",
158-
PgbackrestDBPath: "/pgdata/" + cl.Spec.Name,
159-
PgbackrestRepoPath: "/backrestrepo/" + backrestRepoTarget + "-backups",
157+
PgbackrestEnvVars: GetPgbackrestEnvVars(cl.Spec.UserLabels[util.LABEL_BACKREST], "db",
158+
"/pgdata/"+cl.Spec.Name,
159+
"/backrestrepo/"+backrestRepoTarget+"-backups"),
160160
}
161161

162162
log.Debug("collectaddon value is [" + deploymentFields.CollectAddon + "]")
@@ -349,9 +349,7 @@ func (r Strategy1) CreateReplica(serviceName string, clientset *kubernetes.Clien
349349
ContainerResources: config.GetContainerResourcesJSON(&cl.Spec.ContainerResources),
350350
UserSecretName: cl.Spec.UserSecretName,
351351
NodeSelector: GetAffinity(cl.Spec.UserLabels["NodeLabelKey"], cl.Spec.UserLabels["NodeLabelValue"], "NotIn"),
352-
PgbackrestStanza: "db",
353-
PgbackrestDBPath: "/pgdata/" + depName,
354-
PgbackrestRepoPath: "/backrestrepo/" + depName + "-backups",
352+
PgbackrestEnvVars: GetPgbackrestEnvVars(cl.Spec.UserLabels[util.LABEL_BACKREST], "db", "/pgdata/"+depName, "/backrestrepo/"+depName+"-backups"),
355353
}
356354

357355
switch cl.Spec.ReplicaStorage.StorageType {
@@ -510,6 +508,7 @@ func GetConfVolume(clientset *kubernetes.Clientset, cl *crv1.Pgcluster, namespac
510508
}
511509

512510
//check for pgbackrest global config
511+
/**
513512
if cl.Spec.UserLabels[util.LABEL_BACKREST] != "" {
514513
_, found = kubeapi.GetConfigMap(clientset, util.GLOBAL_PGBACKREST_CUSTOM_CONFIGMAP, namespace)
515514
if !found {
@@ -518,6 +517,7 @@ func GetConfVolume(clientset *kubernetes.Clientset, cl *crv1.Pgcluster, namespac
518517
return "\"configMap\": { \"name\": \"pgo-pgbackrest-config\" }"
519518
}
520519
}
520+
*/
521521

522522
//the default situation
523523
return "\"emptyDir\": { \"medium\": \"Memory\" }"
@@ -603,9 +603,8 @@ func (r Strategy1) Scale(clientset *kubernetes.Clientset, client *rest.RESTClien
603603
NodeSelector: GetReplicaAffinity(cluster.Spec.UserLabels, replica.Spec.UserLabels),
604604
CollectAddon: GetCollectAddon(clientset, namespace, &cluster.Spec),
605605
BadgerAddon: GetBadgerAddon(clientset, namespace, &cluster.Spec),
606-
PgbackrestStanza: "db",
607-
PgbackrestDBPath: "/pgdata/" + replica.Spec.Name,
608-
PgbackrestRepoPath: "/backrestrepo/" + replica.Spec.Name + "-backups",
606+
PgbackrestEnvVars: GetPgbackrestEnvVars(cluster.Spec.UserLabels[util.LABEL_BACKREST], "db", "/pgdata/"+replica.Spec.Name,
607+
"/backrestrepo/"+replica.Spec.Name+"-backups"),
609608
}
610609

611610
switch replica.Spec.ReplicaStorage.StorageType {
@@ -684,3 +683,23 @@ func GetBadgerAddon(clientset *kubernetes.Clientset, namespace string, spec *crv
684683
}
685684
return ""
686685
}
686+
687+
func GetPgbackrestEnvVars(backrestEnabled, stanza, dbpath, repopath string) string {
688+
if backrestEnabled == "true" {
689+
fields := PgbackrestEnvVarsTemplateFields{
690+
PgbackrestStanza: stanza,
691+
PgbackrestDBPath: dbpath,
692+
PgbackrestRepoPath: repopath,
693+
}
694+
695+
var doc bytes.Buffer
696+
err := operator.PgbackrestEnvVarsTemplate.Execute(&doc, fields)
697+
if err != nil {
698+
log.Error(err.Error())
699+
return ""
700+
}
701+
return doc.String()
702+
}
703+
return ""
704+
705+
}

operator/common.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
var CRUNCHY_DEBUG bool
2727
var NAMESPACE string
2828

29+
const pgbackrestEnvVarsPath = "/pgo-config/pgbackrest-env-vars.json"
2930
const PgpoolTemplatePath = "/pgo-config/pgpool-template.json"
3031
const PgpoolConfTemplatePath = "/pgo-config/pgpool.conf"
3132
const PgpoolPasswdTemplatePath = "/pgo-config/pool_passwd"
@@ -55,6 +56,7 @@ const BadgerTemplate1Path = "/pgo-config/pgbadger.json"
5556
const AffinityTemplate1Path = "/pgo-config/affinity.json"
5657
const ContainerResourcesTemplate1Path = "/pgo-config/container-resources.json"
5758

59+
var PgbackrestEnvVarsTemplate *template.Template
5860
var JobTemplate *template.Template
5961
var UpgradeJobTemplate1 *template.Template
6062
var PgpoolTemplate *template.Template
@@ -104,6 +106,7 @@ func Initialize() {
104106
panic("NAMESPACE env var not set")
105107
}
106108

109+
PgbackrestEnvVarsTemplate = util.LoadTemplate(pgbackrestEnvVarsPath)
107110
JobTemplate = util.LoadTemplate(jobPath)
108111
PgpoolTemplate = util.LoadTemplate(PgpoolTemplatePath)
109112
PgpoolConfTemplate = util.LoadTemplate(PgpoolConfTemplatePath)

0 commit comments

Comments
 (0)