@@ -973,11 +973,14 @@ func (c *Cluster) Update(oldSpec, newSpec *cpov1.Postgresql) error {
973973 // only when disabled in oldSpec and enabled in newSpec
974974 needPoolerUser := c .needConnectionPoolerUser (& oldSpec .Spec , & newSpec .Spec )
975975
976+ // Check if Monitor-User needs to be created
977+ needMonitoring := newSpec .Spec .Monitoring != nil && oldSpec .Spec .Monitoring == nil
978+
976979 // streams new replication user created who is initialized in initUsers
977980 // only when streams were not specified in oldSpec but in newSpec
978981 needStreamUser := len (oldSpec .Spec .Streams ) == 0 && len (newSpec .Spec .Streams ) > 0
979982
980- if ! sameUsers || ! sameRotatedUsers || needPoolerUser || needStreamUser {
983+ if ! sameUsers || ! sameRotatedUsers || needPoolerUser || needMonitoring || needStreamUser {
981984 c .logger .Debugf ("initialize users" )
982985 if err := c .initUsers (); err != nil {
983986 c .logger .Errorf ("could not init users - skipping sync of secrets and databases: %v" , err )
@@ -1443,6 +1446,22 @@ func (c *Cluster) initSystemUsers() error {
14431446 }
14441447 }
14451448
1449+ // if the monitor object has been created, a monitoring user is required.
1450+ if c .Spec .Monitoring != nil {
1451+ c .logger .Debugf ("MONITOR: Create cpo_monitoring user" )
1452+ connectionPoolerUser := spec.PgUser {
1453+ Origin : spec .RoleMonitoring ,
1454+ Name : constants .MonitoringUserKeyName ,
1455+ Namespace : c .Namespace ,
1456+ Flags : []string {constants .RoleFlagLogin },
1457+ Password : util .RandomPassword (constants .PasswordLength ),
1458+ }
1459+
1460+ if _ , exists := c .systemUsers [constants .MonitoringUserKeyName ]; ! exists {
1461+ c .systemUsers [constants .ConnectionPoolerUserKeyName ] = connectionPoolerUser
1462+ }
1463+ }
1464+
14461465 // replication users for event streams are another exception
14471466 // the operator will create one replication user for all streams
14481467 if len (c .Spec .Streams ) > 0 {
0 commit comments