Skip to content

Commit 5b2049c

Browse files
authored
K8SPSMDB-1316: Allow customizing cluster name in PMM (#1885)
1 parent f0796c5 commit 5b2049c

File tree

8 files changed

+30
-19
lines changed

8 files changed

+30
-19
lines changed

config/crd/bases/psmdb.percona.com_perconaservermongodbs.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,8 @@ spec:
621621
type: string
622622
type: object
623623
type: object
624+
customClusterName:
625+
type: string
624626
enabled:
625627
type: boolean
626628
image:

deploy/bundle.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,8 @@ spec:
13191319
type: string
13201320
type: object
13211321
type: object
1322+
customClusterName:
1323+
type: string
13221324
enabled:
13231325
type: boolean
13241326
image:

deploy/cr.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ spec:
6262
image: perconalab/pmm-client:dev-latest
6363
serverHost: monitoring-service
6464
# containerSecurityContext: {}
65+
# customClusterName: mongo-cluster
6566
# mongodParams: --environment=ENVIRONMENT
6667
# mongosParams: --environment=ENVIRONMENT
6768
replsets:

deploy/crd.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,8 @@ spec:
13191319
type: string
13201320
type: object
13211321
type: object
1322+
customClusterName:
1323+
type: string
13221324
enabled:
13231325
type: boolean
13241326
image:

deploy/cw-bundle.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,8 @@ spec:
13191319
type: string
13201320
type: object
13211321
type: object
1322+
customClusterName:
1323+
type: string
13221324
enabled:
13231325
type: boolean
13241326
image:

e2e-tests/version-service/conf/crd.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,8 @@ spec:
13191319
type: string
13201320
type: object
13211321
type: object
1322+
customClusterName:
1323+
type: string
13221324
enabled:
13231325
type: boolean
13241326
image:

pkg/apis/psmdb/v1/psmdb_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,9 @@ type PMMSpec struct {
364364
ContainerSecurityContext *corev1.SecurityContext `json:"containerSecurityContext,omitempty"`
365365

366366
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
367+
368+
// PMM cluster name. If not set Operator uses cr.Name for PMM cluster name.
369+
CustomClusterName string `json:"customClusterName,omitempty"`
367370
}
368371

369372
func (pmm *PMMSpec) HasSecret(secret *corev1.Secret) bool {

pkg/psmdb/pmm.go

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func PMMContainer(cr *api.PerconaServerMongoDB, secret *corev1.Secret, dbPort in
102102
Name: "pmm-client",
103103
Image: spec.Image,
104104
ImagePullPolicy: cr.Spec.ImagePullPolicy,
105+
Resources: cr.Spec.PMM.Resources,
105106
Env: []corev1.EnvVar{
106107
{
107108
Name: "PMM_SERVER",
@@ -340,27 +341,23 @@ func AddPMMContainer(cr *api.PerconaServerMongoDB, secret *corev1.Secret, dbPort
340341
}
341342

342343
pmmC := PMMContainer(cr, secret, dbPort, customAdminParams)
343-
if cr.CompareVersion("1.2.0") >= 0 {
344-
pmmC.Resources = cr.Spec.PMM.Resources
344+
345+
clusterName := cr.Name
346+
if len(cr.Spec.PMM.CustomClusterName) > 0 {
347+
clusterName = cr.Spec.PMM.CustomClusterName
348+
345349
}
346-
if cr.CompareVersion("1.6.0") >= 0 {
347-
pmmC.Lifecycle = &corev1.Lifecycle{
348-
PreStop: &corev1.LifecycleHandler{
349-
Exec: &corev1.ExecAction{
350-
Command: []string{"bash", "-c", "pmm-admin inventory remove node --force $(pmm-admin status --json | python -c \"import sys, json; print(json.load(sys.stdin)['pmm_agent_status']['node_id'])\")"},
351-
},
352-
},
353-
}
354-
clusterPmmEnvs := []corev1.EnvVar{
355-
{
356-
Name: "CLUSTER_NAME",
357-
Value: cr.Name,
358-
},
359-
}
360-
pmmC.Env = append(pmmC.Env, clusterPmmEnvs...)
361-
pmmAgentScriptEnv := PMMAgentScript(cr)
362-
pmmC.Env = append(pmmC.Env, pmmAgentScriptEnv...)
350+
clusterPmmEnvs := []corev1.EnvVar{
351+
{
352+
Name: "CLUSTER_NAME",
353+
Value: clusterName,
354+
},
363355
}
356+
pmmC.Env = append(pmmC.Env, clusterPmmEnvs...)
357+
358+
pmmAgentScriptEnv := PMMAgentScript(cr)
359+
pmmC.Env = append(pmmC.Env, pmmAgentScriptEnv...)
360+
364361
if cr.CompareVersion("1.10.0") >= 0 {
365362
// PMM team added these flags which allows us to avoid
366363
// container crash, but just restart pmm-agent till it recovers

0 commit comments

Comments
 (0)