init error arrays correctly

This commit is contained in:
Felix Kunde 2021-11-23 15:27:22 +01:00
parent f9150aa6db
commit 3029421dc9
5 changed files with 10 additions and 19 deletions

View File

@ -496,17 +496,16 @@ func (c *Cluster) deleteEndpoint(role PostgresRole) error {
func (c *Cluster) deleteSecrets() error { func (c *Cluster) deleteSecrets() error {
c.setProcessName("deleting secrets") c.setProcessName("deleting secrets")
var errors []string errors := make([]string, 0)
errorCount := 0
for uid, secret := range c.Secrets { for uid, secret := range c.Secrets {
err := c.deleteSecret(uid, *secret) err := c.deleteSecret(uid, *secret)
if err != nil { if err != nil {
errors = append(errors, fmt.Sprintf("%v", err)) errors = append(errors, fmt.Sprintf("%v", err))
errorCount++
} }
} }
if errorCount > 0 { if len(errors) > 0 {
return fmt.Errorf("could not delete all secrets: %v", errors) return fmt.Errorf("could not delete all secrets: %v", errors)
} }

View File

@ -196,17 +196,15 @@ func TestCheckAndSetGlobalPostgreSQLConfiguration(t *testing.T) {
cluster.patroni = p cluster.patroni = p
mockPod := newMockPod("192.168.100.1") mockPod := newMockPod("192.168.100.1")
// simulate existing config that differs with cluster.Spec // simulate existing config that differs from cluster.Spec
tests := []struct { tests := []struct {
subtest string subtest string
pod *v1.Pod
patroni acidv1.Patroni patroni acidv1.Patroni
pgParams map[string]string pgParams map[string]string
restartMaster bool restartMaster bool
}{ }{
{ {
subtest: "Patroni and Postgresql.Parameters differ - restart replica first", subtest: "Patroni and Postgresql.Parameters differ - restart replica first",
pod: mockPod,
patroni: acidv1.Patroni{ patroni: acidv1.Patroni{
TTL: 30, // desired 20 TTL: 30, // desired 20
}, },
@ -218,7 +216,6 @@ func TestCheckAndSetGlobalPostgreSQLConfiguration(t *testing.T) {
}, },
{ {
subtest: "multiple Postgresql.Parameters differ - restart replica first", subtest: "multiple Postgresql.Parameters differ - restart replica first",
pod: mockPod,
patroni: acidv1.Patroni{ patroni: acidv1.Patroni{
TTL: 20, TTL: 20,
}, },
@ -230,7 +227,6 @@ func TestCheckAndSetGlobalPostgreSQLConfiguration(t *testing.T) {
}, },
{ {
subtest: "desired max_connections bigger - restart replica first", subtest: "desired max_connections bigger - restart replica first",
pod: mockPod,
patroni: acidv1.Patroni{ patroni: acidv1.Patroni{
TTL: 20, TTL: 20,
}, },
@ -242,7 +238,6 @@ func TestCheckAndSetGlobalPostgreSQLConfiguration(t *testing.T) {
}, },
{ {
subtest: "desired max_connections smaller - restart master first", subtest: "desired max_connections smaller - restart master first",
pod: mockPod,
patroni: acidv1.Patroni{ patroni: acidv1.Patroni{
TTL: 20, TTL: 20,
}, },
@ -255,7 +250,7 @@ func TestCheckAndSetGlobalPostgreSQLConfiguration(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
requireMasterRestart, err := cluster.checkAndSetGlobalPostgreSQLConfiguration(tt.pod, tt.patroni, tt.pgParams) requireMasterRestart, err := cluster.checkAndSetGlobalPostgreSQLConfiguration(mockPod, tt.patroni, tt.pgParams)
assert.NoError(t, err) assert.NoError(t, err)
if requireMasterRestart != tt.restartMaster { if requireMasterRestart != tt.restartMaster {
t.Errorf("%s - %s: unexpect master restart strategy, got %v, expected %v", testName, tt.subtest, requireMasterRestart, tt.restartMaster) t.Errorf("%s - %s: unexpect master restart strategy, got %v, expected %v", testName, tt.subtest, requireMasterRestart, tt.restartMaster)

View File

@ -88,7 +88,7 @@ func (c *Cluster) syncUnderlyingEBSVolume() error {
awsGp3 := aws.String("gp3") awsGp3 := aws.String("gp3")
awsIo2 := aws.String("io2") awsIo2 := aws.String("io2")
errors := []string{} errors := make([]string, 0)
for _, volume := range c.EBSVolumes { for _, volume := range c.EBSVolumes {
var modifyIops *int64 var modifyIops *int64

View File

@ -197,9 +197,8 @@ func (c *Controller) getInfrastructureRoles(
rolesSecrets []*config.InfrastructureRole) ( rolesSecrets []*config.InfrastructureRole) (
map[string]spec.PgUser, []error) { map[string]spec.PgUser, []error) {
var errors []error errors := make([]error, 0)
var noRolesProvided = true noRolesProvided := true
roles := []spec.PgUser{} roles := []spec.PgUser{}
uniqRoles := map[string]spec.PgUser{} uniqRoles := map[string]spec.PgUser{}
@ -230,9 +229,7 @@ func (c *Controller) getInfrastructureRoles(
continue continue
} }
for _, r := range infraRoles { roles = append(roles, infraRoles...)
roles = append(roles, r)
}
} }
for _, r := range roles { for _, r := range roles {

View File

@ -101,7 +101,7 @@ func (strategy DefaultUserSyncStrategy) ProduceSyncRequests(dbUsers spec.PgUserM
// ExecuteSyncRequests makes actual database changes from the requests passed in its arguments. // ExecuteSyncRequests makes actual database changes from the requests passed in its arguments.
func (strategy DefaultUserSyncStrategy) ExecuteSyncRequests(requests []spec.PgSyncUserRequest, db *sql.DB) error { func (strategy DefaultUserSyncStrategy) ExecuteSyncRequests(requests []spec.PgSyncUserRequest, db *sql.DB) error {
var reqretries []spec.PgSyncUserRequest var reqretries []spec.PgSyncUserRequest
var errors []string errors := make([]string, 0)
for _, request := range requests { for _, request := range requests {
switch request.Kind { switch request.Kind {
case spec.PGSyncUserAdd: case spec.PGSyncUserAdd: