Fix an issue when not assigning the merge result.
Add some tests.
This commit is contained in:
parent
831ebb1f32
commit
611cfe96d6
|
|
@ -610,12 +610,12 @@ func (c *Cluster) initSystemUsers() {
|
||||||
func (c *Cluster) initRobotUsers() error {
|
func (c *Cluster) initRobotUsers() error {
|
||||||
for username, userFlags := range c.Spec.Users {
|
for username, userFlags := range c.Spec.Users {
|
||||||
if !isValidUsername(username) {
|
if !isValidUsername(username) {
|
||||||
return fmt.Errorf("invalid username: '%v'", username)
|
return fmt.Errorf("invalid username: %q", username)
|
||||||
}
|
}
|
||||||
|
|
||||||
flags, err := normalizeUserFlags(userFlags)
|
flags, err := normalizeUserFlags(userFlags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid flags for user '%v': %v", username, err)
|
return fmt.Errorf("invalid flags for user %q: %v", username, err)
|
||||||
}
|
}
|
||||||
if _, present := c.pgUsers[username]; !present {
|
if _, present := c.pgUsers[username]; !present {
|
||||||
c.pgUsers[username] = spec.PgUser{
|
c.pgUsers[username] = spec.PgUser{
|
||||||
|
|
@ -630,6 +630,7 @@ func (c *Cluster) initRobotUsers() error {
|
||||||
c.logger.Debugf("merging user %q data", username)
|
c.logger.Debugf("merging user %q data", username)
|
||||||
user := c.pgUsers[username]
|
user := c.pgUsers[username]
|
||||||
user.Flags = flags
|
user.Flags = flags
|
||||||
|
c.pgUsers[username] = user
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ import (
|
||||||
"github.com/zalando-incubator/postgres-operator/pkg/util"
|
"github.com/zalando-incubator/postgres-operator/pkg/util"
|
||||||
"github.com/zalando-incubator/postgres-operator/pkg/util/constants"
|
"github.com/zalando-incubator/postgres-operator/pkg/util/constants"
|
||||||
"github.com/zalando-incubator/postgres-operator/pkg/util/retryutil"
|
"github.com/zalando-incubator/postgres-operator/pkg/util/retryutil"
|
||||||
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
func isValidUsername(username string) bool {
|
func isValidUsername(username string) bool {
|
||||||
|
|
@ -77,7 +78,7 @@ func normalizeUserFlags(userFlags []string) ([]string, error) {
|
||||||
if addLogin {
|
if addLogin {
|
||||||
flags = append(flags, constants.RoleFlagLogin)
|
flags = append(flags, constants.RoleFlagLogin)
|
||||||
}
|
}
|
||||||
|
sort.Strings(flags)
|
||||||
return flags, nil
|
return flags, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ type CloneDescription struct {
|
||||||
EndTimestamp string `json:"timestamp,omitempty"`
|
EndTimestamp string `json:"timestamp,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type userFlags []string
|
type UserFlags []string
|
||||||
|
|
||||||
// PostgresStatus contains status of the PostgreSQL cluster (running, creation failed etc.)
|
// PostgresStatus contains status of the PostgreSQL cluster (running, creation failed etc.)
|
||||||
type PostgresStatus string
|
type PostgresStatus string
|
||||||
|
|
@ -99,7 +99,7 @@ type PostgresSpec struct {
|
||||||
UseLoadBalancer *bool `json:"useLoadBalancer,omitempty"`
|
UseLoadBalancer *bool `json:"useLoadBalancer,omitempty"`
|
||||||
ReplicaLoadBalancer bool `json:"replicaLoadBalancer,omitempty"`
|
ReplicaLoadBalancer bool `json:"replicaLoadBalancer,omitempty"`
|
||||||
NumberOfInstances int32 `json:"numberOfInstances"`
|
NumberOfInstances int32 `json:"numberOfInstances"`
|
||||||
Users map[string]userFlags `json:"users"`
|
Users map[string]UserFlags `json:"users"`
|
||||||
MaintenanceWindows []MaintenanceWindow `json:"maintenanceWindows,omitempty"`
|
MaintenanceWindows []MaintenanceWindow `json:"maintenanceWindows,omitempty"`
|
||||||
Clone CloneDescription `json:"clone"`
|
Clone CloneDescription `json:"clone"`
|
||||||
ClusterName string `json:"-"`
|
ClusterName string `json:"-"`
|
||||||
|
|
|
||||||
|
|
@ -226,7 +226,7 @@ var unmarshalCluster = []struct {
|
||||||
TeamID: "ACID",
|
TeamID: "ACID",
|
||||||
AllowedSourceRanges: []string{"127.0.0.1/32"},
|
AllowedSourceRanges: []string{"127.0.0.1/32"},
|
||||||
NumberOfInstances: 2,
|
NumberOfInstances: 2,
|
||||||
Users: map[string]userFlags{"zalando": {"superuser", "createdb"}},
|
Users: map[string]UserFlags{"zalando": {"superuser", "createdb"}},
|
||||||
MaintenanceWindows: []MaintenanceWindow{{
|
MaintenanceWindows: []MaintenanceWindow{{
|
||||||
Everyday: false,
|
Everyday: false,
|
||||||
Weekday: time.Monday,
|
Weekday: time.Monday,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue