getInfrastructureRoles should return error

This commit is contained in:
Felix Kunde 2021-11-24 12:16:21 +01:00
parent 7edc14dfb3
commit 4bbf1e9d24
3 changed files with 13 additions and 11 deletions

View File

@ -506,7 +506,7 @@ func (c *Cluster) deleteSecrets() error {
} }
if len(errors) > 0 { if len(errors) > 0 {
return fmt.Errorf("could not delete all secrets: %v", errors) return fmt.Errorf("could not delete all secrets: %v", strings.Join(errors, `', '`))
} }
return nil return nil

View File

@ -195,9 +195,9 @@ func (c *Controller) getInfrastructureRoleDefinitions() []*config.Infrastructure
func (c *Controller) getInfrastructureRoles( func (c *Controller) getInfrastructureRoles(
rolesSecrets []*config.InfrastructureRole) ( rolesSecrets []*config.InfrastructureRole) (
map[string]spec.PgUser, []error) { map[string]spec.PgUser, error) {
errors := make([]error, 0) errors := make([]string, 0)
noRolesProvided := true noRolesProvided := true
roles := []spec.PgUser{} roles := []spec.PgUser{}
uniqRoles := map[string]spec.PgUser{} uniqRoles := map[string]spec.PgUser{}
@ -220,30 +220,32 @@ func (c *Controller) getInfrastructureRoles(
infraRoles, err := c.getInfrastructureRole(secret) infraRoles, err := c.getInfrastructureRole(secret)
if err != nil || infraRoles == nil { if err != nil || infraRoles == nil {
c.logger.Debugf("Cannot get infrastructure role: %+v", *secret) c.logger.Debugf("cannot get infrastructure role: %+v", *secret)
if err != nil { if err != nil {
errors = append(errors, err) errors = append(errors, fmt.Sprintf("%v", err))
} }
continue continue
} }
for _, r := range infraRoles { roles = append(roles, infraRoles...)
roles = append(roles, r)
}
} }
for _, r := range roles { for _, r := range roles {
if _, exists := uniqRoles[r.Name]; exists { if _, exists := uniqRoles[r.Name]; exists {
msg := "Conflicting infrastructure roles: roles[%s] = (%q, %q)" msg := "conflicting infrastructure roles: roles[%s] = (%q, %q)"
c.logger.Debugf(msg, r.Name, uniqRoles[r.Name], r) c.logger.Debugf(msg, r.Name, uniqRoles[r.Name], r)
} }
uniqRoles[r.Name] = r uniqRoles[r.Name] = r
} }
return uniqRoles, errors if len(errors) > 0 {
return nil, fmt.Errorf(strings.Join(errors, `', '`))
}
return uniqRoles, nil
} }
// Generate list of users representing one infrastructure role based on its // Generate list of users representing one infrastructure role based on its

View File

@ -138,7 +138,7 @@ func (strategy DefaultUserSyncStrategy) ExecuteSyncRequests(requests []spec.PgSy
return err return err
} }
} else { } else {
return fmt.Errorf("could not execute sync requests for users: %v", errors) return fmt.Errorf("could not execute sync requests for users: %v", strings.Join(errors, `', '`))
} }
} }