diff --git a/pkg/cluster/resources.go b/pkg/cluster/resources.go index f078c6434..919e75153 100644 --- a/pkg/cluster/resources.go +++ b/pkg/cluster/resources.go @@ -496,17 +496,16 @@ func (c *Cluster) deleteEndpoint(role PostgresRole) error { func (c *Cluster) deleteSecrets() error { c.setProcessName("deleting secrets") - var errors []string - errorCount := 0 + errors := make([]string, 0) + for uid, secret := range c.Secrets { err := c.deleteSecret(uid, *secret) if err != nil { 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) } diff --git a/pkg/cluster/sync_test.go b/pkg/cluster/sync_test.go index c6e2a8357..3e3fc9318 100644 --- a/pkg/cluster/sync_test.go +++ b/pkg/cluster/sync_test.go @@ -196,17 +196,15 @@ func TestCheckAndSetGlobalPostgreSQLConfiguration(t *testing.T) { cluster.patroni = p mockPod := newMockPod("192.168.100.1") - // simulate existing config that differs with cluster.Spec + // simulate existing config that differs from cluster.Spec tests := []struct { subtest string - pod *v1.Pod patroni acidv1.Patroni pgParams map[string]string restartMaster bool }{ { subtest: "Patroni and Postgresql.Parameters differ - restart replica first", - pod: mockPod, patroni: acidv1.Patroni{ TTL: 30, // desired 20 }, @@ -218,7 +216,6 @@ func TestCheckAndSetGlobalPostgreSQLConfiguration(t *testing.T) { }, { subtest: "multiple Postgresql.Parameters differ - restart replica first", - pod: mockPod, patroni: acidv1.Patroni{ TTL: 20, }, @@ -230,7 +227,6 @@ func TestCheckAndSetGlobalPostgreSQLConfiguration(t *testing.T) { }, { subtest: "desired max_connections bigger - restart replica first", - pod: mockPod, patroni: acidv1.Patroni{ TTL: 20, }, @@ -242,7 +238,6 @@ func TestCheckAndSetGlobalPostgreSQLConfiguration(t *testing.T) { }, { subtest: "desired max_connections smaller - restart master first", - pod: mockPod, patroni: acidv1.Patroni{ TTL: 20, }, @@ -255,7 +250,7 @@ func TestCheckAndSetGlobalPostgreSQLConfiguration(t *testing.T) { } 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) if requireMasterRestart != tt.restartMaster { t.Errorf("%s - %s: unexpect master restart strategy, got %v, expected %v", testName, tt.subtest, requireMasterRestart, tt.restartMaster) diff --git a/pkg/cluster/volumes.go b/pkg/cluster/volumes.go index 4962319ed..78533ef54 100644 --- a/pkg/cluster/volumes.go +++ b/pkg/cluster/volumes.go @@ -88,7 +88,7 @@ func (c *Cluster) syncUnderlyingEBSVolume() error { awsGp3 := aws.String("gp3") awsIo2 := aws.String("io2") - errors := []string{} + errors := make([]string, 0) for _, volume := range c.EBSVolumes { var modifyIops *int64 diff --git a/pkg/controller/util.go b/pkg/controller/util.go index 8aa891c09..3639b4123 100644 --- a/pkg/controller/util.go +++ b/pkg/controller/util.go @@ -197,9 +197,8 @@ func (c *Controller) getInfrastructureRoles( rolesSecrets []*config.InfrastructureRole) ( map[string]spec.PgUser, []error) { - var errors []error - var noRolesProvided = true - + errors := make([]error, 0) + noRolesProvided := true roles := []spec.PgUser{} uniqRoles := map[string]spec.PgUser{} @@ -230,9 +229,7 @@ func (c *Controller) getInfrastructureRoles( continue } - for _, r := range infraRoles { - roles = append(roles, r) - } + roles = append(roles, infraRoles...) } for _, r := range roles { diff --git a/pkg/util/users/users.go b/pkg/util/users/users.go index 3da933644..c6b6461fe 100644 --- a/pkg/util/users/users.go +++ b/pkg/util/users/users.go @@ -101,7 +101,7 @@ func (strategy DefaultUserSyncStrategy) ProduceSyncRequests(dbUsers spec.PgUserM // ExecuteSyncRequests makes actual database changes from the requests passed in its arguments. func (strategy DefaultUserSyncStrategy) ExecuteSyncRequests(requests []spec.PgSyncUserRequest, db *sql.DB) error { var reqretries []spec.PgSyncUserRequest - var errors []string + errors := make([]string, 0) for _, request := range requests { switch request.Kind { case spec.PGSyncUserAdd: