Skip to content

Commit 8812ad3

Browse files
author
jmccormick2001
committed
add PgmonitorPassword setting to pgo.yaml, update cluster deployment template to only add pgmonitor env var if metrics is specified, update docs, update pgo show config
1 parent 657b0ed commit 8812ad3

File tree

11 files changed

+45
-11
lines changed

11 files changed

+45
-11
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"name": "PGMONITOR_PASSWORD",
2+
"value": "{{.PgmonitorPassword}}"
3+
}, {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,10 @@
6868
"name": "PGDATA_PATH_OVERRIDE",
6969
"value": "{{.DataPathOverride}}"
7070
}, {
71+
{{.PgmonitorEnvVars}}
7172
{{.PgbackrestEnvVars}}
7273
"name": "PG_DATABASE",
7374
"value": "{{.Database}}"
74-
}, {
75-
"name": "PGMONITOR_PASSWORD",
76-
"value": "password"
7775
}, {
7876
"name": "ARCHIVE_MODE",
7977
"value": "{{.ArchiveMode}}"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"name": "PGMONITOR_PASSWORD",
2+
"value": "{{.PgmonitorPassword}}"
3+
}, {

conf/postgres-operator/pgo.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Cluster:
2121
AutofailReplaceReplica: false
2222
LogStatement: none
2323
LogMinDurationStatement: 60000
24+
PgmonitorPassword: password
2425
PrimaryStorage: hostpathstorage
2526
XlogStorage: hostpathstorage
2627
BackupStorage: hostpathstorage

config/pgoconfig.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type ClusterStruct struct {
4949
Backrest bool `yaml:"Backrest"`
5050
Autofail bool `yaml:"Autofail"`
5151
AutofailReplaceReplica bool `yaml:"AutofailReplaceReplica"`
52+
PgmonitorPassword string `yaml:"PgmonitorPassword"`
5253
}
5354

5455
type StorageStruct struct {

hugo/content/Configuration/pgo-yaml-configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The *pgo.yaml* file is broken into major sections as described below:
2424
|User | the PostgreSQL normal user name
2525
|Strategy | sets the deployment strategy to be used for deploying a cluster, currently there is only strategy *1*
2626
|Replicas | the number of cluster replicas to create for newly created clusters
27+
|PgmonitorPassword | the password to use for pgmonitor metrics collection if you specify --metrics when creating a PG cluster
2728
|Metrics | boolean, if set to true will cause each new cluster to include crunchy-collect as a sidecar container for metrics collection, if set to false (default), users can still add metrics on a cluster-by-cluster basis using the pgo command flag --metrics
2829
|Badger | boolean, if set to true will cause each new cluster to include crunchy-pgbadger as a sidecar container for static log analysis, if set to false (default), users can still add pgbadger on a cluster-by-cluster basis using the pgo create cluster command flag --pgbadger
2930
|Policies | optional, list of policies to apply to a newly created cluster, comma separated, must be valid policies in the catalog

operator/cluster/cluster.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,13 @@ type DeploymentTemplateFields struct {
8686
ConfVolume string
8787
CollectAddon string
8888
BadgerAddon string
89+
PgmonitorEnvVars string
8990
PgbackrestEnvVars string
9091
//next 2 are for the replica deployment only
9192
Replicas string
9293
PrimaryHost string
9394
}
9495

95-
type PgbackrestEnvVarsTemplateFields struct {
96-
PgbackrestStanza string
97-
PgbackrestDBPath string
98-
PgbackrestRepo1Path string
99-
PgbackrestRepo1Host string
100-
}
101-
10296
// ReplicaSuffix ...
10397
const ReplicaSuffix = "-replica"
10498

operator/cluster/cluster_strategy_1.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ func (r Strategy1) AddCluster(clientset *kubernetes.Clientset, client *rest.REST
128128
CollectAddon: operator.GetCollectAddon(clientset, namespace, &cl.Spec),
129129
BadgerAddon: operator.GetBadgerAddon(clientset, namespace, &cl.Spec),
130130
PgbackrestEnvVars: operator.GetPgbackrestEnvVars(cl.Spec.UserLabels[util.LABEL_BACKREST], cl.Spec.Name, cl.Spec.Name),
131+
PgmonitorEnvVars: operator.GetPgmonitorEnvVars(cl.Spec.UserLabels[util.LABEL_COLLECT]),
131132
}
132133

133134
log.Debug("collectaddon value is [" + deploymentFields.CollectAddon + "]")
@@ -382,6 +383,7 @@ func (r Strategy1) Scale(clientset *kubernetes.Clientset, client *rest.RESTClien
382383
CollectAddon: operator.GetCollectAddon(clientset, namespace, &cluster.Spec),
383384
BadgerAddon: operator.GetBadgerAddon(clientset, namespace, &cluster.Spec),
384385
PgbackrestEnvVars: operator.GetPgbackrestEnvVars(cluster.Spec.UserLabels[util.LABEL_BACKREST], replica.Spec.ClusterName, replica.Spec.Name),
386+
PgmonitorEnvVars: operator.GetPgmonitorEnvVars(cluster.Spec.UserLabels[util.LABEL_COLLECT]),
385387
}
386388

387389
switch replica.Spec.ReplicaStorage.StorageType {

operator/clusterutilties.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,17 @@ type badgerTemplateFields struct {
5353
ContainerResources string
5454
}
5555

56-
// consolidate with cluster.PgbackrestEnvVarsTemplateFields
5756
type PgbackrestEnvVarsTemplateFields struct {
5857
PgbackrestStanza string
5958
PgbackrestDBPath string
6059
PgbackrestRepo1Path string
6160
PgbackrestRepo1Host string
6261
}
6362

63+
type PgmonitorEnvVarsTemplateFields struct {
64+
PgmonitorPassword string
65+
}
66+
6467
// needs to be consolidated with cluster.DeploymentTemplateFields
6568
// DeploymentTemplateFields ...
6669
type DeploymentTemplateFields struct {
@@ -304,3 +307,21 @@ func GetReplicaAffinity(clusterLabels, replicaLabels map[string]string) string {
304307
}
305308
return GetAffinity(key, value, operator)
306309
}
310+
311+
func GetPgmonitorEnvVars(metricsEnabled string) string {
312+
if metricsEnabled == "true" {
313+
fields := PgmonitorEnvVarsTemplateFields{
314+
PgmonitorPassword: Pgo.Cluster.PgmonitorPassword,
315+
}
316+
317+
var doc bytes.Buffer
318+
err := PgmonitorEnvVarsTemplate.Execute(&doc, fields)
319+
if err != nil {
320+
log.Error(err.Error())
321+
return ""
322+
}
323+
return doc.String()
324+
}
325+
return ""
326+
327+
}

operator/common.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var NAMESPACE string
3030

3131
const pgoBackrestRepoTemplatePath = "/pgo-config/pgo-backrest-repo-template.json"
3232
const pgoBackrestRepoServiceTemplatePath = "/pgo-config/pgo-backrest-repo-service-template.json"
33+
const pgmonitorEnvVarsPath = "/pgo-config/pgmonitor-env-vars.json"
3334
const pgbackrestEnvVarsPath = "/pgo-config/pgbackrest-env-vars.json"
3435
const PgpoolTemplatePath = "/pgo-config/pgpool-template.json"
3536
const PgpoolConfTemplatePath = "/pgo-config/pgpool.conf"
@@ -58,6 +59,7 @@ const ContainerResourcesTemplate1Path = "/pgo-config/container-resources.json"
5859

5960
var PgoBackrestRepoServiceTemplate *template.Template
6061
var PgoBackrestRepoTemplate *template.Template
62+
var PgmonitorEnvVarsTemplate *template.Template
6163
var PgbackrestEnvVarsTemplate *template.Template
6264
var JobTemplate *template.Template
6365
var UpgradeJobTemplate1 *template.Template
@@ -113,6 +115,7 @@ func Initialize() {
113115

114116
PgoBackrestRepoTemplate = util.LoadTemplate(pgoBackrestRepoTemplatePath)
115117
PgoBackrestRepoServiceTemplate = util.LoadTemplate(pgoBackrestRepoServiceTemplatePath)
118+
PgmonitorEnvVarsTemplate = util.LoadTemplate(pgmonitorEnvVarsPath)
116119
PgbackrestEnvVarsTemplate = util.LoadTemplate(pgbackrestEnvVarsPath)
117120
JobTemplate = util.LoadTemplate(jobPath)
118121
PgpoolTemplate = util.LoadTemplate(PgpoolTemplatePath)
@@ -161,6 +164,12 @@ func Initialize() {
161164
} else {
162165
log.Debugf("COImagePrefix set, using %s", Pgo.Pgo.COImagePrefix)
163166
}
167+
168+
if Pgo.Cluster.PgmonitorPassword == "" {
169+
log.Debug("pgo.yaml PgmonitorPassword not set, using default")
170+
Pgo.Cluster.PgmonitorPassword = "password"
171+
}
172+
164173
if Pgo.Pgo.COImageTag == "" {
165174
log.Error("pgo.yaml COImageTag not set, required ")
166175
panic("pgo.yaml COImageTag env var not set")

0 commit comments

Comments
 (0)