Skip to content

Commit 24ef3df

Browse files
committed
K8SPG-750 add cluster name to pmm
1 parent 94252cc commit 24ef3df

File tree

11 files changed

+52
-9
lines changed

11 files changed

+52
-9
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
@@ -13422,6 +13422,8 @@ spec:
1342213422
pmm:
1342313423
description: The specification of PMM sidecars.
1342413424
properties:
13425+
clusterName:
13426+
type: string
1342513427
containerSecurityContext:
1342613428
description: |-
1342713429
SecurityContext holds security configuration that will be applied to a container.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13827,6 +13827,8 @@ spec:
1382713827
pmm:
1382813828
description: The specification of PMM sidecars.
1382913829
properties:
13830+
clusterName:
13831+
type: string
1383013832
containerSecurityContext:
1383113833
description: |-
1383213834
SecurityContext holds security configuration that will be applied to a container.

deploy/bundle.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14120,6 +14120,8 @@ spec:
1412014120
pmm:
1412114121
description: The specification of PMM sidecars.
1412214122
properties:
14123+
clusterName:
14124+
type: string
1412314125
containerSecurityContext:
1412414126
description: |-
1412514127
SecurityContext holds security configuration that will be applied to a container.

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+
# clusterName: "<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
@@ -14120,6 +14120,8 @@ spec:
1412014120
pmm:
1412114121
description: The specification of PMM sidecars.
1412214122
properties:
14123+
clusterName:
14124+
type: string
1412314125
containerSecurityContext:
1412414126
description: |-
1412514127
SecurityContext holds security configuration that will be applied to a container.

deploy/cw-bundle.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14120,6 +14120,8 @@ spec:
1412014120
pmm:
1412114121
description: The specification of PMM sidecars.
1412214122
properties:
14123+
clusterName:
14124+
type: string
1412314125
containerSecurityContext:
1412414126
description: |-
1412514127
SecurityContext holds security configuration that will be applied to a container.

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.clusterName = "'${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+
clusterName: 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+
clusterName: monitoring-pmm-custom-name
4243
port: 5432
4344
proxy:
4445
pgBouncer:

percona/pmm/pmm.go

Lines changed: 34 additions & 8 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.ClusterName != "" {
239+
clusterName = pgc.Spec.PMM.ClusterName
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,7 @@ func sidecarContainerV3(pgc *v2.PerconaPGCluster) corev1.Container {
249257
}
250258

251259
pmmSpec := pgc.Spec.PMM
252-
253-
return corev1.Container{
260+
container := corev1.Container{
254261
Name: "pmm-client",
255262
Image: pmmSpec.Image,
256263
ImagePullPolicy: pmmSpec.ImagePullPolicy,
@@ -412,17 +419,30 @@ func sidecarContainerV3(pgc *v2.PerconaPGCluster) corev1.Container {
412419
},
413420
{
414421
Name: "PMM_AGENT_PRERUN_SCRIPT",
415-
Value: agentPrerunScript(pgc.Spec.PMM.QuerySource),
422+
Value: agentPrerunScript(pgc.Spec.PMM.QuerySource, pgc),
416423
},
417424
{
418425
Name: "PMM_AGENT_PATHS_TEMPDIR",
419426
Value: "/tmp",
420427
},
421428
},
422429
}
430+
431+
if pgc.CompareVersion("2.7.0") >= 0 {
432+
clusterName := pgc.Name
433+
if pgc.Spec.PMM.ClusterName != "" {
434+
clusterName = pgc.Spec.PMM.ClusterName
435+
}
436+
container.Env = append(container.Env, corev1.EnvVar{
437+
Name: "CLUSTER_NAME",
438+
Value: clusterName,
439+
})
440+
}
441+
442+
return container
423443
}
424444

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

@@ -440,6 +460,12 @@ func agentPrerunScript(querySource v2.PMMQuerySource) string {
440460
"--service-name=$(PMM_AGENT_SETUP_NODE_NAME)",
441461
fmt.Sprintf("--query-source=%s", querySource),
442462
}
463+
464+
if pgc.CompareVersion("2.7.0") >= 0 {
465+
addServiceArgs = append(addServiceArgs,
466+
"--cluster=$(CLUSTER_NAME)",
467+
)
468+
}
443469
addService := fmt.Sprintf("pmm-admin add postgresql %s", strings.Join(addServiceArgs, " "))
444470

445471
return wait + "; " + addService + "; " + annotate

0 commit comments

Comments
 (0)