revert pointers for PreparedDatabases structs
This commit is contained in:
		
							parent
							
								
									c0a4c83df1
								
							
						
					
					
						commit
						f10c3ab77c
					
				| 
						 | 
				
			
			@ -53,27 +53,27 @@ type PostgresSpec struct {
 | 
			
		|||
	// load balancers' source ranges are the same for master and replica services
 | 
			
		||||
	AllowedSourceRanges []string `json:"allowedSourceRanges"`
 | 
			
		||||
 | 
			
		||||
	NumberOfInstances     int32                        `json:"numberOfInstances"`
 | 
			
		||||
	Users                 map[string]UserFlags         `json:"users,omitempty"`
 | 
			
		||||
	MaintenanceWindows    []MaintenanceWindow          `json:"maintenanceWindows,omitempty"`
 | 
			
		||||
	Clone                 *CloneDescription            `json:"clone,omitempty"`
 | 
			
		||||
	ClusterName           string                       `json:"-"`
 | 
			
		||||
	Databases             map[string]string            `json:"databases,omitempty"`
 | 
			
		||||
	PreparedDatabases     map[string]*PreparedDatabase `json:"preparedDatabases,omitempty"`
 | 
			
		||||
	SchedulerName         *string                      `json:"schedulerName,omitempty"`
 | 
			
		||||
	NodeAffinity          *v1.NodeAffinity             `json:"nodeAffinity,omitempty"`
 | 
			
		||||
	Tolerations           []v1.Toleration              `json:"tolerations,omitempty"`
 | 
			
		||||
	Sidecars              []Sidecar                    `json:"sidecars,omitempty"`
 | 
			
		||||
	InitContainers        []v1.Container               `json:"initContainers,omitempty"`
 | 
			
		||||
	PodPriorityClassName  string                       `json:"podPriorityClassName,omitempty"`
 | 
			
		||||
	ShmVolume             *bool                        `json:"enableShmVolume,omitempty"`
 | 
			
		||||
	EnableLogicalBackup   bool                         `json:"enableLogicalBackup,omitempty"`
 | 
			
		||||
	LogicalBackupSchedule string                       `json:"logicalBackupSchedule,omitempty"`
 | 
			
		||||
	StandbyCluster        *StandbyDescription          `json:"standby,omitempty"`
 | 
			
		||||
	PodAnnotations        map[string]string            `json:"podAnnotations,omitempty"`
 | 
			
		||||
	ServiceAnnotations    map[string]string            `json:"serviceAnnotations,omitempty"`
 | 
			
		||||
	TLS                   *TLSDescription              `json:"tls,omitempty"`
 | 
			
		||||
	AdditionalVolumes     []AdditionalVolume           `json:"additionalVolumes,omitempty"`
 | 
			
		||||
	NumberOfInstances     int32                       `json:"numberOfInstances"`
 | 
			
		||||
	Users                 map[string]UserFlags        `json:"users,omitempty"`
 | 
			
		||||
	MaintenanceWindows    []MaintenanceWindow         `json:"maintenanceWindows,omitempty"`
 | 
			
		||||
	Clone                 *CloneDescription           `json:"clone,omitempty"`
 | 
			
		||||
	ClusterName           string                      `json:"-"`
 | 
			
		||||
	Databases             map[string]string           `json:"databases,omitempty"`
 | 
			
		||||
	PreparedDatabases     map[string]PreparedDatabase `json:"preparedDatabases,omitempty"`
 | 
			
		||||
	SchedulerName         *string                     `json:"schedulerName,omitempty"`
 | 
			
		||||
	NodeAffinity          *v1.NodeAffinity            `json:"nodeAffinity,omitempty"`
 | 
			
		||||
	Tolerations           []v1.Toleration             `json:"tolerations,omitempty"`
 | 
			
		||||
	Sidecars              []Sidecar                   `json:"sidecars,omitempty"`
 | 
			
		||||
	InitContainers        []v1.Container              `json:"initContainers,omitempty"`
 | 
			
		||||
	PodPriorityClassName  string                      `json:"podPriorityClassName,omitempty"`
 | 
			
		||||
	ShmVolume             *bool                       `json:"enableShmVolume,omitempty"`
 | 
			
		||||
	EnableLogicalBackup   bool                        `json:"enableLogicalBackup,omitempty"`
 | 
			
		||||
	LogicalBackupSchedule string                      `json:"logicalBackupSchedule,omitempty"`
 | 
			
		||||
	StandbyCluster        *StandbyDescription         `json:"standby,omitempty"`
 | 
			
		||||
	PodAnnotations        map[string]string           `json:"podAnnotations,omitempty"`
 | 
			
		||||
	ServiceAnnotations    map[string]string           `json:"serviceAnnotations,omitempty"`
 | 
			
		||||
	TLS                   *TLSDescription             `json:"tls,omitempty"`
 | 
			
		||||
	AdditionalVolumes     []AdditionalVolume          `json:"additionalVolumes,omitempty"`
 | 
			
		||||
 | 
			
		||||
	// deprecated json tags
 | 
			
		||||
	InitContainersOld       []v1.Container `json:"init_containers,omitempty"`
 | 
			
		||||
| 
						 | 
				
			
			@ -92,9 +92,9 @@ type PostgresqlList struct {
 | 
			
		|||
 | 
			
		||||
// PreparedDatabase describes elements to be bootstrapped
 | 
			
		||||
type PreparedDatabase struct {
 | 
			
		||||
	PreparedSchemas map[string]*PreparedSchema `json:"schemas,omitempty"`
 | 
			
		||||
	DefaultUsers    bool                       `json:"defaultUsers,omitempty" defaults:"false"`
 | 
			
		||||
	Extensions      map[string]string          `json:"extensions,omitempty"`
 | 
			
		||||
	PreparedSchemas map[string]PreparedSchema `json:"schemas,omitempty"`
 | 
			
		||||
	DefaultUsers    bool                      `json:"defaultUsers,omitempty" defaults:"false"`
 | 
			
		||||
	Extensions      map[string]string         `json:"extensions,omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// PreparedSchema describes elements to be bootstrapped per schema
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -623,17 +623,9 @@ func (in *PostgresSpec) DeepCopyInto(out *PostgresSpec) {
 | 
			
		|||
	}
 | 
			
		||||
	if in.PreparedDatabases != nil {
 | 
			
		||||
		in, out := &in.PreparedDatabases, &out.PreparedDatabases
 | 
			
		||||
		*out = make(map[string]*PreparedDatabase, len(*in))
 | 
			
		||||
		*out = make(map[string]PreparedDatabase, len(*in))
 | 
			
		||||
		for key, val := range *in {
 | 
			
		||||
			var outVal *PreparedDatabase
 | 
			
		||||
			if val == nil {
 | 
			
		||||
				(*out)[key] = nil
 | 
			
		||||
			} else {
 | 
			
		||||
				in, out := &val, &outVal
 | 
			
		||||
				*out = new(PreparedDatabase)
 | 
			
		||||
				(*in).DeepCopyInto(*out)
 | 
			
		||||
			}
 | 
			
		||||
			(*out)[key] = outVal
 | 
			
		||||
			(*out)[key] = *val.DeepCopy()
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if in.SchedulerName != nil {
 | 
			
		||||
| 
						 | 
				
			
			@ -965,17 +957,9 @@ func (in *PreparedDatabase) DeepCopyInto(out *PreparedDatabase) {
 | 
			
		|||
	*out = *in
 | 
			
		||||
	if in.PreparedSchemas != nil {
 | 
			
		||||
		in, out := &in.PreparedSchemas, &out.PreparedSchemas
 | 
			
		||||
		*out = make(map[string]*PreparedSchema, len(*in))
 | 
			
		||||
		*out = make(map[string]PreparedSchema, len(*in))
 | 
			
		||||
		for key, val := range *in {
 | 
			
		||||
			var outVal *PreparedSchema
 | 
			
		||||
			if val == nil {
 | 
			
		||||
				(*out)[key] = nil
 | 
			
		||||
			} else {
 | 
			
		||||
				in, out := &val, &outVal
 | 
			
		||||
				*out = new(PreparedSchema)
 | 
			
		||||
				(*in).DeepCopyInto(*out)
 | 
			
		||||
			}
 | 
			
		||||
			(*out)[key] = outVal
 | 
			
		||||
			(*out)[key] = *val.DeepCopy()
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if in.Extensions != nil {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -975,7 +975,7 @@ func (c *Cluster) initSystemUsers() {
 | 
			
		|||
func (c *Cluster) initPreparedDatabaseRoles() error {
 | 
			
		||||
 | 
			
		||||
	if c.Spec.PreparedDatabases != nil && len(c.Spec.PreparedDatabases) == 0 { // TODO: add option to disable creating such a default DB
 | 
			
		||||
		c.Spec.PreparedDatabases = map[string]*acidv1.PreparedDatabase{strings.Replace(c.Name, "-", "_", -1): {}}
 | 
			
		||||
		c.Spec.PreparedDatabases = map[string]acidv1.PreparedDatabase{strings.Replace(c.Name, "-", "_", -1): {}}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// create maps with default roles/users as keys and their membership as values
 | 
			
		||||
| 
						 | 
				
			
			@ -994,7 +994,7 @@ func (c *Cluster) initPreparedDatabaseRoles() error {
 | 
			
		|||
		// get list of prepared schemas to set in search_path
 | 
			
		||||
		preparedSchemas := preparedDB.PreparedSchemas
 | 
			
		||||
		if len(preparedDB.PreparedSchemas) == 0 {
 | 
			
		||||
			preparedSchemas = map[string]*acidv1.PreparedSchema{"data": {DefaultRoles: util.True()}}
 | 
			
		||||
			preparedSchemas = map[string]acidv1.PreparedSchema{"data": {DefaultRoles: util.True()}}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		var searchPath strings.Builder
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -763,7 +763,7 @@ func TestInitSystemUsers(t *testing.T) {
 | 
			
		|||
func TestPreparedDatabases(t *testing.T) {
 | 
			
		||||
	testName := "TestDefaultPreparedDatabase"
 | 
			
		||||
 | 
			
		||||
	cl.Spec.PreparedDatabases = map[string]*acidv1.PreparedDatabase{}
 | 
			
		||||
	cl.Spec.PreparedDatabases = map[string]acidv1.PreparedDatabase{}
 | 
			
		||||
	cl.initPreparedDatabaseRoles()
 | 
			
		||||
 | 
			
		||||
	for _, role := range []string{"acid_test_owner", "acid_test_reader", "acid_test_writer",
 | 
			
		||||
| 
						 | 
				
			
			@ -775,10 +775,10 @@ func TestPreparedDatabases(t *testing.T) {
 | 
			
		|||
 | 
			
		||||
	testName = "TestPreparedDatabaseWithSchema"
 | 
			
		||||
 | 
			
		||||
	cl.Spec.PreparedDatabases = map[string]*acidv1.PreparedDatabase{
 | 
			
		||||
	cl.Spec.PreparedDatabases = map[string]acidv1.PreparedDatabase{
 | 
			
		||||
		"foo": {
 | 
			
		||||
			DefaultUsers: true,
 | 
			
		||||
			PreparedSchemas: map[string]*acidv1.PreparedSchema{
 | 
			
		||||
			PreparedSchemas: map[string]acidv1.PreparedSchema{
 | 
			
		||||
				"bar": {
 | 
			
		||||
					DefaultUsers: true,
 | 
			
		||||
				},
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -655,7 +655,7 @@ func (c *Cluster) syncDatabases() error {
 | 
			
		|||
 | 
			
		||||
	// if no prepared databases are specified create a database named like the cluster
 | 
			
		||||
	if c.Spec.PreparedDatabases != nil && len(c.Spec.PreparedDatabases) == 0 { // TODO: add option to disable creating such a default DB
 | 
			
		||||
		c.Spec.PreparedDatabases = map[string]*acidv1.PreparedDatabase{strings.Replace(c.Name, "-", "_", -1): {}}
 | 
			
		||||
		c.Spec.PreparedDatabases = map[string]acidv1.PreparedDatabase{strings.Replace(c.Name, "-", "_", -1): {}}
 | 
			
		||||
	}
 | 
			
		||||
	for preparedDatabaseName := range c.Spec.PreparedDatabases {
 | 
			
		||||
		_, exists := currentDatabases[preparedDatabaseName]
 | 
			
		||||
| 
						 | 
				
			
			@ -710,7 +710,7 @@ func (c *Cluster) syncPreparedDatabases() error {
 | 
			
		|||
		// now, prepare defined schemas
 | 
			
		||||
		preparedSchemas := preparedDB.PreparedSchemas
 | 
			
		||||
		if len(preparedDB.PreparedSchemas) == 0 {
 | 
			
		||||
			preparedSchemas = map[string]*acidv1.PreparedSchema{"data": {DefaultRoles: util.True()}}
 | 
			
		||||
			preparedSchemas = map[string]acidv1.PreparedSchema{"data": {DefaultRoles: util.True()}}
 | 
			
		||||
		}
 | 
			
		||||
		if err := c.syncPreparedSchemas(preparedDbName, preparedSchemas); err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
| 
						 | 
				
			
			@ -729,7 +729,7 @@ func (c *Cluster) syncPreparedDatabases() error {
 | 
			
		|||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *Cluster) syncPreparedSchemas(databaseName string, preparedSchemas map[string]*acidv1.PreparedSchema) error {
 | 
			
		||||
func (c *Cluster) syncPreparedSchemas(databaseName string, preparedSchemas map[string]acidv1.PreparedSchema) error {
 | 
			
		||||
	c.setProcessName("syncing prepared schemas")
 | 
			
		||||
 | 
			
		||||
	currentSchemas, err := c.getSchemas()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue