Skip to content

Commit b165e84

Browse files
committed
Be consistent about adding monitoring user to spec
Ideally we should be using the same approach as other system users, but for a quick fix try just being consistent about how it is created.
1 parent a9a0f78 commit b165e84

File tree

2 files changed

+12
-21
lines changed

2 files changed

+12
-21
lines changed

pkg/apis/cpo.opensource.cybertec.at/v1/util.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package v1
22

33
import (
44
"fmt"
5+
"github.com/cybertec-postgresql/cybertec-pg-operator/pkg/util/constants"
56
"regexp"
67
"strings"
78
"time"
@@ -120,3 +121,10 @@ func (b *Backup) GetRestoreID() string {
120121
}
121122
return b.Pgbackrest.Restore.ID
122123
}
124+
125+
func (p *Postgresql) AddMonitoringUser(monitorUsername string) {
126+
if p.Spec.Users == nil {
127+
p.Spec.Users = make(map[string]UserFlags)
128+
}
129+
p.Spec.Users[monitorUsername] = UserFlags{constants.RoleFlagLogin}
130+
}

pkg/cluster/cluster.go

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,7 @@ func New(cfg Config, kubeClient k8sutil.KubernetesClient, pgSpec cpov1.Postgresq
128128
passwordEncryption = "scram-sha-256"
129129
}
130130
if pgSpec.Spec.Monitoring != nil {
131-
flg := cpov1.UserFlags{constants.RoleFlagLogin}
132-
if pgSpec.Spec.Users != nil {
133-
pgSpec.Spec.Users[monitorUsername] = flg
134-
} else {
135-
users := make(map[string]cpov1.UserFlags)
136-
pgSpec.Spec.Users = users
137-
pgSpec.Spec.Users[monitorUsername] = flg
138-
}
131+
pgSpec.AddMonitoringUser(monitorUsername)
139132
}
140133
cluster := &Cluster{
141134
Config: cfg,
@@ -961,22 +954,12 @@ func (c *Cluster) Update(oldSpec, newSpec *cpov1.Postgresql) error {
961954
updateFailed = true
962955
}
963956
}
964-
//Add monitoring user if required
965-
if newSpec.Spec.Monitoring != nil {
966-
flags := []string{constants.RoleFlagLogin}
967-
monitorUser := map[string]spec.PgUser{
968-
monitorUsername: {
969-
Origin: spec.RoleOriginInfrastructure,
970-
Name: monitorUsername,
971-
Namespace: c.Namespace,
972-
Flags: flags,
973-
},
974-
}
975-
c.pgUsers[monitorUsername] = monitorUser[monitorUsername]
976-
}
977957
//Check if monitoring user is added in manifest
978958
if _, ok := newSpec.Spec.Users["cpo-exporter"]; ok {
979959
c.logger.Error("creating user of name cpo-exporter is not allowed as it is reserved for monitoring")
960+
updateFailed = true
961+
} else if newSpec.Spec.Monitoring != nil {
962+
newSpec.AddMonitoringUser(monitorUsername)
980963
}
981964

982965
// Users

0 commit comments

Comments
 (0)