Skip to content

Commit 988cd8a

Browse files
authored
Merge pull request #1100 from percona/K8SPG-750_add_cluster_name_to_pmm
K8SPG-750 add cluster name to pmm
2 parents 25a8189 + 569bf57 commit 988cd8a

File tree

12 files changed

+56
-13
lines changed

12 files changed

+56
-13
lines changed

build/crd/percona/generated/pgv2.percona.com_perconapgclusters.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13617,6 +13617,8 @@ spec:
1361713617
type: string
1361813618
type: object
1361913619
type: object
13620+
customClusterName:
13621+
type: string
1362013622
enabled:
1362113623
type: boolean
1362213624
image:

config/crd/bases/pgv2.percona.com_perconapgclusters.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14022,6 +14022,8 @@ spec:
1402214022
type: string
1402314023
type: object
1402414024
type: object
14025+
customClusterName:
14026+
type: string
1402514027
enabled:
1402614028
type: boolean
1402714029
image:

deploy/bundle.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14315,6 +14315,8 @@ spec:
1431514315
type: string
1431614316
type: object
1431714317
type: object
14318+
customClusterName:
14319+
type: string
1431814320
enabled:
1431914321
type: boolean
1432014322
image:

deploy/cr.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ spec:
471471
# imagePullPolicy: IfNotPresent
472472
secret: cluster1-pmm-secret
473473
serverHost: monitoring-service
474+
# customClusterName: "<string>"
474475
# querySource: pgstatmonitor
475476
# patroni:
476477
# # Some values of the Liveness/Readiness probes of the patroni container are calculated using syncPeriodSeconds by the following formulas:

deploy/crd.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14315,6 +14315,8 @@ spec:
1431514315
type: string
1431614316
type: object
1431714317
type: object
14318+
customClusterName:
14319+
type: string
1431814320
enabled:
1431914321
type: boolean
1432014322
image:

deploy/cw-bundle.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14315,6 +14315,8 @@ spec:
1431514315
type: string
1431614316
type: object
1431714317
type: object
14318+
customClusterName:
14319+
type: string
1431814320
enabled:
1431914321
type: boolean
1432014322
image:

e2e-tests/functions

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ get_cr() {
181181
.spec.backups.pgbackrest.image = "'$IMAGE_BACKREST'" |
182182
.spec.proxy.pgBouncer.image = "'$IMAGE_PGBOUNCER'" |
183183
.spec.pmm.image = "'$IMAGE_PMM_CLIENT'" |
184-
.spec.pmm.secret = "'${cr_name}'-pmm-secret"
184+
.spec.pmm.secret = "'${cr_name}'-pmm-secret" |
185+
.spec.pmm.customClusterName = "'${cr_name}'-pmm-custom-name"
185186
' $DEPLOY_DIR/cr.yaml >$TEMP_DIR/cr.yaml
186187

187188
if [[ $OPENSHIFT ]]; then

e2e-tests/tests/monitoring-pmm3/03-assert.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ spec:
3939
enabled: true
4040
secret: monitoring-pmm3-pmm-secret
4141
serverHost: monitoring-service
42+
customClusterName: monitoring-pmm3-pmm-custom-name
4243
port: 5432
4344
proxy:
4445
pgBouncer:

e2e-tests/tests/monitoring/03-assert.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ spec:
3939
enabled: true
4040
secret: monitoring-pmm-secret
4141
serverHost: monitoring-service
42+
customClusterName: monitoring-pmm-custom-name
4243
port: 5432
4344
proxy:
4445
pgBouncer:

percona/pmm/pmm.go

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,23 @@ func sidecarContainerV2(pgc *v2.PerconaPGCluster) corev1.Container {
224224
},
225225
{
226226
Name: "PMM_AGENT_PRERUN_SCRIPT",
227-
Value: agentPrerunScript(pgc.Spec.PMM.QuerySource),
227+
Value: agentPrerunScript(pgc.Spec.PMM.QuerySource, pgc),
228+
},
229+
{
230+
Name: "PMM_AGENT_PATHS_TEMPDIR",
231+
Value: "/tmp",
228232
},
229233
},
230234
}
231235

232-
if pgc.CompareVersion("2.3.0") >= 0 {
236+
if pgc.CompareVersion("2.7.0") >= 0 {
237+
clusterName := pgc.Name
238+
if pgc.Spec.PMM.CustomClusterName != "" {
239+
clusterName = pgc.Spec.PMM.CustomClusterName
240+
}
233241
container.Env = append(container.Env, corev1.EnvVar{
234-
Name: "PMM_AGENT_PATHS_TEMPDIR",
235-
Value: "/tmp",
242+
Name: "CLUSTER_NAME",
243+
Value: clusterName,
236244
})
237245
}
238246

@@ -249,8 +257,12 @@ func sidecarContainerV3(pgc *v2.PerconaPGCluster) corev1.Container {
249257
}
250258

251259
pmmSpec := pgc.Spec.PMM
260+
clusterName := pgc.Name
261+
if pgc.Spec.PMM.CustomClusterName != "" {
262+
clusterName = pgc.Spec.PMM.CustomClusterName
263+
}
252264

253-
return corev1.Container{
265+
container := corev1.Container{
254266
Name: "pmm-client",
255267
Image: pmmSpec.Image,
256268
ImagePullPolicy: pmmSpec.ImagePullPolicy,
@@ -412,17 +424,23 @@ func sidecarContainerV3(pgc *v2.PerconaPGCluster) corev1.Container {
412424
},
413425
{
414426
Name: "PMM_AGENT_PRERUN_SCRIPT",
415-
Value: agentPrerunScript(pgc.Spec.PMM.QuerySource),
427+
Value: agentPrerunScript(pgc.Spec.PMM.QuerySource, pgc),
416428
},
417429
{
418430
Name: "PMM_AGENT_PATHS_TEMPDIR",
419431
Value: "/tmp",
420432
},
433+
{
434+
Name: "CLUSTER_NAME",
435+
Value: clusterName,
436+
},
421437
},
422438
}
439+
440+
return container
423441
}
424442

425-
func agentPrerunScript(querySource v2.PMMQuerySource) string {
443+
func agentPrerunScript(querySource v2.PMMQuerySource, pgc *v2.PerconaPGCluster) string {
426444
wait := "pmm-admin status --wait=10s"
427445
annotate := "pmm-admin annotate --service-name=$(PMM_AGENT_SETUP_NODE_NAME) 'Service restarted'"
428446

@@ -440,6 +458,12 @@ func agentPrerunScript(querySource v2.PMMQuerySource) string {
440458
"--service-name=$(PMM_AGENT_SETUP_NODE_NAME)",
441459
fmt.Sprintf("--query-source=%s", querySource),
442460
}
461+
462+
if pgc.CompareVersion("2.7.0") >= 0 {
463+
addServiceArgs = append(addServiceArgs,
464+
"--cluster=$(CLUSTER_NAME)",
465+
)
466+
}
443467
addService := fmt.Sprintf("pmm-admin add postgresql %s", strings.Join(addServiceArgs, " "))
444468

445469
return wait + "; " + addService + "; " + annotate

0 commit comments

Comments
 (0)