create a default preparedDB if not specified
This commit is contained in:
parent
06313615fe
commit
9d9807afef
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -779,10 +780,19 @@ func (c *Cluster) initSystemUsers() {
|
||||||
|
|
||||||
func (c *Cluster) initPreparedDatabaseRoles() error {
|
func (c *Cluster) initPreparedDatabaseRoles() error {
|
||||||
|
|
||||||
for preparedDbName, preparedDB := range c.Spec.PreparedDatabases {
|
preparedDatabases := c.Spec.PreparedDatabases
|
||||||
|
if preparedDatabases == nil || len(preparedDatabases) == 0 { // TODO: add option to disable creating such a default DB
|
||||||
|
preparedDatabases = map[string]acidv1.PreparedDatabase{strings.Replace(c.Name, "-", "_", -1): {}}
|
||||||
|
c.Spec.PreparedDatabases = preparedDatabases
|
||||||
|
}
|
||||||
|
|
||||||
|
for preparedDbName, preparedDB := range preparedDatabases {
|
||||||
|
// default roles per database
|
||||||
if err := c.initDefaultRoles("admin", preparedDbName); err != nil {
|
if err := c.initDefaultRoles("admin", preparedDbName); err != nil {
|
||||||
return fmt.Errorf("could not initialize default roles for database %s: %v", preparedDbName, err)
|
return fmt.Errorf("could not initialize default roles for database %s: %v", preparedDbName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// default roles per database schema
|
||||||
preparedSchemas := preparedDB.PreparedSchemas
|
preparedSchemas := preparedDB.PreparedSchemas
|
||||||
if len(preparedDB.PreparedSchemas) == 0 {
|
if len(preparedDB.PreparedSchemas) == 0 {
|
||||||
preparedSchemas = map[string]acidv1.PreparedSchema{"data": {DefaultRoles: util.True()}}
|
preparedSchemas = map[string]acidv1.PreparedSchema{"data": {DefaultRoles: util.True()}}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package cluster
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
batchv1beta1 "k8s.io/api/batch/v1beta1"
|
batchv1beta1 "k8s.io/api/batch/v1beta1"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
|
|
@ -509,6 +510,12 @@ func (c *Cluster) syncDatabases() error {
|
||||||
return fmt.Errorf("could not get current databases: %v", err)
|
return fmt.Errorf("could not get current databases: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if no prepared databases are specified create a database named like the cluster
|
||||||
|
preparedDatabases := c.Spec.PreparedDatabases
|
||||||
|
if preparedDatabases == nil || len(preparedDatabases) == 0 { // TODO: add option to disable creating such a default DB
|
||||||
|
preparedDatabases = map[string]acidv1.PreparedDatabase{strings.Replace(c.Name, "-", "_", -1): {}}
|
||||||
|
c.Spec.PreparedDatabases = preparedDatabases
|
||||||
|
}
|
||||||
for preparedDatname := range c.Spec.PreparedDatabases {
|
for preparedDatname := range c.Spec.PreparedDatabases {
|
||||||
_, exists := currentDatabases[preparedDatname]
|
_, exists := currentDatabases[preparedDatname]
|
||||||
if !exists {
|
if !exists {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue