Skip to content

Commit 66f6a51

Browse files
authored
K8SPSMDB-1245 Telemetry ClusterWideEnabled not handling multiple comma-separated namespaces (#1829)
* K8SPSMDB-1245 Telemetry ClusterWideEnabled not handling multiple comma-separated namespaces * update condition * update ClusterWideEnabled * delete unused logs * update unit test * add more testcases * add more testcases * check CWenabled when cw is false * fixed PR comments
1 parent df43914 commit 66f6a51

File tree

2 files changed

+52
-12
lines changed

2 files changed

+52
-12
lines changed

pkg/controller/perconaservermongodb/version.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,13 @@ func (r *ReconcilePerconaServerMongoDB) getVersionMeta(ctx context.Context, cr *
264264
BackupVersion: cr.Status.BackupVersion,
265265
BackupsEnabled: cr.Spec.Backup.Enabled && len(cr.Spec.Backup.Storages) > 0,
266266
ShardingEnabled: cr.Spec.Sharding.Enabled,
267-
ClusterWideEnabled: len(watchNs) == 0,
267+
ClusterWideEnabled: len(watchNs) == 0 || len(strings.Split(watchNs, ",")) > 1,
268268
HashicorpVaultEnabled: len(cr.Spec.Secrets.Vault) > 0,
269269
RoleManagementEnabled: len(cr.Spec.Roles) > 0,
270270
UserManagementEnabled: len(cr.Spec.Users) > 0,
271271
VolumeExpansionEnabled: cr.Spec.VolumeExpansionEnabled,
272272
}
273+
273274
if cr.Spec.Platform != nil {
274275
vm.Platform = string(*cr.Spec.Platform)
275276
}

pkg/controller/perconaservermongodb/version_test.go

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,13 @@ func Test_majorUpgradeRequested(t *testing.T) {
330330

331331
func TestVersionMeta(t *testing.T) {
332332
tests := []struct {
333-
name string
334-
cr api.PerconaServerMongoDB
335-
want VersionMeta
336-
clusterWide bool
337-
helmDeploy bool
333+
name string
334+
cr api.PerconaServerMongoDB
335+
want VersionMeta
336+
clusterWide bool
337+
helmDeploy bool
338+
namespace string
339+
watchNamespaces string
338340
}{
339341
{
340342
name: "Minimal CR",
@@ -361,6 +363,7 @@ func TestVersionMeta(t *testing.T) {
361363
Version: version.Version,
362364
ClusterSize: 3,
363365
},
366+
namespace: "test-namespace",
364367
},
365368
{
366369
name: "Full CR with old Version deployed with Helm",
@@ -433,9 +436,11 @@ func TestVersionMeta(t *testing.T) {
433436
PITREnabled: true,
434437
HelmDeployCR: true,
435438
PhysicalBackupScheduled: true,
439+
ClusterWideEnabled: false,
436440
},
437441
clusterWide: false,
438442
helmDeploy: false,
443+
namespace: "test-namespace",
439444
},
440445
{
441446
name: "Disabled Backup with storage",
@@ -469,6 +474,39 @@ func TestVersionMeta(t *testing.T) {
469474
ClusterSize: 3,
470475
BackupsEnabled: false,
471476
},
477+
namespace: "test-namespace",
478+
},
479+
{
480+
name: "Cluster-wide with specified namespaces and operator helm deploy",
481+
cr: api.PerconaServerMongoDB{
482+
ObjectMeta: metav1.ObjectMeta{
483+
Name: "some-name",
484+
},
485+
Spec: api.PerconaServerMongoDBSpec{
486+
Image: "percona/percona-server-mongodb:5.0.11-10",
487+
Replsets: []*api.ReplsetSpec{
488+
{
489+
Name: "rs0",
490+
Size: 3,
491+
VolumeSpec: fakeVolumeSpec(t),
492+
},
493+
},
494+
},
495+
Status: api.PerconaServerMongoDBStatus{
496+
Size: 4,
497+
},
498+
},
499+
want: VersionMeta{
500+
Apply: "disabled",
501+
Version: version.Version,
502+
HelmDeployOperator: true,
503+
ClusterWideEnabled: true,
504+
ClusterSize: 4,
505+
},
506+
clusterWide: true,
507+
helmDeploy: true,
508+
namespace: "test-namespace",
509+
watchNamespaces: "test-namespace,another-namespace",
472510
},
473511
{
474512
name: "Cluster-wide and operator helm deploy",
@@ -497,17 +535,18 @@ func TestVersionMeta(t *testing.T) {
497535
ClusterWideEnabled: true,
498536
ClusterSize: 4,
499537
},
500-
clusterWide: true,
501-
helmDeploy: true,
538+
clusterWide: true,
539+
helmDeploy: true,
540+
namespace: "test-namespace",
541+
watchNamespaces: "",
502542
},
503543
}
504-
currentNs := "test-namespace"
505544
size := int32(1)
506545
operatorName := "percona-server-mongodb-operator"
507546
operatorDepl := appsv1.Deployment{
508547
ObjectMeta: metav1.ObjectMeta{
509548
Name: operatorName,
510-
Namespace: currentNs,
549+
Namespace: "",
511550
Labels: make(map[string]string),
512551
},
513552
Spec: appsv1.DeploymentSpec{
@@ -537,9 +576,9 @@ func TestVersionMeta(t *testing.T) {
537576

538577
for _, tt := range tests {
539578
t.Run(tt.name, func(t *testing.T) {
540-
t.Setenv(k8s.WatchNamespaceEnvVar, currentNs)
579+
t.Setenv(k8s.WatchNamespaceEnvVar, tt.namespace)
541580
if tt.clusterWide {
542-
t.Setenv(k8s.WatchNamespaceEnvVar, "")
581+
t.Setenv(k8s.WatchNamespaceEnvVar, tt.watchNamespaces)
543582
}
544583
if tt.helmDeploy {
545584
operatorDepl.Labels["helm.sh/chart"] = operatorName

0 commit comments

Comments
 (0)