Skip to content

Commit 15e26e1

Browse files
committed
add sync rule and debug to cluster.go. also adding monitoring to test check
1 parent 69a5ac8 commit 15e26e1

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

pkg/cluster/cluster.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,13 +1455,16 @@ func (c *Cluster) initSystemUsers() error {
14551455

14561456
// if the monitor object has been created, a monitoring user is required.
14571457
if c.Spec.Monitoring != nil {
1458+
14581459
MonitoringUser := spec.PgUser{
14591460
Origin: spec.RoleMonitoring,
14601461
Name: constants.MonitoringUserKeyName,
14611462
Namespace: c.Namespace,
14621463
Flags: []string{constants.RoleFlagLogin},
14631464
Password: util.RandomPassword(constants.PasswordLength),
14641465
}
1466+
c.logger.Debugf("Create cpo_monitoring user with password: %s",
1467+
MonitoringUser.Password)
14651468

14661469
if _, exists := c.systemUsers[constants.MonitoringUserKeyName]; !exists {
14671470
c.systemUsers[constants.MonitoringUserKeyName] = MonitoringUser

pkg/cluster/cluster_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import (
77
"strings"
88
"testing"
99

10-
"github.com/sirupsen/logrus"
11-
"github.com/stretchr/testify/assert"
1210
cpov1 "github.com/cybertec-postgresql/cybertec-pg-operator/pkg/apis/cpo.opensource.cybertec.at/v1"
1311
fakecpov1 "github.com/cybertec-postgresql/cybertec-pg-operator/pkg/generated/clientset/versioned/fake"
1412
"github.com/cybertec-postgresql/cybertec-pg-operator/pkg/spec"
@@ -17,6 +15,8 @@ import (
1715
"github.com/cybertec-postgresql/cybertec-pg-operator/pkg/util/constants"
1816
"github.com/cybertec-postgresql/cybertec-pg-operator/pkg/util/k8sutil"
1917
"github.com/cybertec-postgresql/cybertec-pg-operator/pkg/util/teams"
18+
"github.com/sirupsen/logrus"
19+
"github.com/stretchr/testify/assert"
2020
v1 "k8s.io/api/core/v1"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2222
"k8s.io/client-go/kubernetes/fake"
@@ -944,16 +944,20 @@ func TestServiceAnnotations(t *testing.T) {
944944
}
945945

946946
func TestInitSystemUsers(t *testing.T) {
947-
// reset system users, pooler and stream section
947+
// reset system users, pooler, monitoring and stream section
948948
cl.systemUsers = make(map[string]spec.PgUser)
949949
cl.Spec.EnableConnectionPooler = boolToPointer(false)
950+
cl.Spec.Monitoring = nil
950951
cl.Spec.Streams = []cpov1.Stream{}
951952

952-
// default cluster without connection pooler and event streams
953+
// default cluster without connection pooler, monitoring and event streams
953954
cl.initSystemUsers()
954955
if _, exist := cl.systemUsers[constants.ConnectionPoolerUserKeyName]; exist {
955956
t.Errorf("%s, connection pooler user is present", t.Name())
956957
}
958+
if _, exist := cl.systemUsers[constants.MonitoringUserKeyName]; exist {
959+
t.Errorf("%s, Monitoring user is present", t.Name())
960+
}
957961
if _, exist := cl.systemUsers[constants.EventStreamUserKeyName]; exist {
958962
t.Errorf("%s, stream user is present", t.Name())
959963
}

pkg/cluster/sync.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,13 @@ func (c *Cluster) updateSecret(
10321032
userMap = c.systemUsers
10331033
}
10341034
}
1035+
// use system user when Monitoring is enabled and Monitoring user is specfied in manifest
1036+
if _, exists := c.systemUsers[constants.MonitoringUserKeyName]; exists {
1037+
if secretUsername == c.systemUsers[constants.MonitoringUserKeyName].Name {
1038+
userKey = constants.MonitoringUserKeyName
1039+
userMap = c.systemUsers
1040+
}
1041+
}
10351042
// use system user when streams are defined and fes_user is specfied in manifest
10361043
if _, exists := c.systemUsers[constants.EventStreamUserKeyName]; exists {
10371044
if secretUsername == c.systemUsers[constants.EventStreamUserKeyName].Name {

0 commit comments

Comments
 (0)