use pointer types for preparedDatabases and nodeAffinity
This commit is contained in:
parent
636ba9b846
commit
c0a4c83df1
|
|
@ -59,9 +59,9 @@ type PostgresSpec struct {
|
||||||
Clone *CloneDescription `json:"clone,omitempty"`
|
Clone *CloneDescription `json:"clone,omitempty"`
|
||||||
ClusterName string `json:"-"`
|
ClusterName string `json:"-"`
|
||||||
Databases map[string]string `json:"databases,omitempty"`
|
Databases map[string]string `json:"databases,omitempty"`
|
||||||
PreparedDatabases map[string]PreparedDatabase `json:"preparedDatabases,omitempty"`
|
PreparedDatabases map[string]*PreparedDatabase `json:"preparedDatabases,omitempty"`
|
||||||
SchedulerName *string `json:"schedulerName,omitempty"`
|
SchedulerName *string `json:"schedulerName,omitempty"`
|
||||||
NodeAffinity v1.NodeAffinity `json:"nodeAffinity,omitempty"`
|
NodeAffinity *v1.NodeAffinity `json:"nodeAffinity,omitempty"`
|
||||||
Tolerations []v1.Toleration `json:"tolerations,omitempty"`
|
Tolerations []v1.Toleration `json:"tolerations,omitempty"`
|
||||||
Sidecars []Sidecar `json:"sidecars,omitempty"`
|
Sidecars []Sidecar `json:"sidecars,omitempty"`
|
||||||
InitContainers []v1.Container `json:"initContainers,omitempty"`
|
InitContainers []v1.Container `json:"initContainers,omitempty"`
|
||||||
|
|
@ -92,7 +92,7 @@ type PostgresqlList struct {
|
||||||
|
|
||||||
// PreparedDatabase describes elements to be bootstrapped
|
// PreparedDatabase describes elements to be bootstrapped
|
||||||
type PreparedDatabase struct {
|
type PreparedDatabase struct {
|
||||||
PreparedSchemas map[string]PreparedSchema `json:"schemas,omitempty"`
|
PreparedSchemas map[string]*PreparedSchema `json:"schemas,omitempty"`
|
||||||
DefaultUsers bool `json:"defaultUsers,omitempty" defaults:"false"`
|
DefaultUsers bool `json:"defaultUsers,omitempty" defaults:"false"`
|
||||||
Extensions map[string]string `json:"extensions,omitempty"`
|
Extensions map[string]string `json:"extensions,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -623,9 +623,17 @@ func (in *PostgresSpec) DeepCopyInto(out *PostgresSpec) {
|
||||||
}
|
}
|
||||||
if in.PreparedDatabases != nil {
|
if in.PreparedDatabases != nil {
|
||||||
in, out := &in.PreparedDatabases, &out.PreparedDatabases
|
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 {
|
for key, val := range *in {
|
||||||
(*out)[key] = *val.DeepCopy()
|
var outVal *PreparedDatabase
|
||||||
|
if val == nil {
|
||||||
|
(*out)[key] = nil
|
||||||
|
} else {
|
||||||
|
in, out := &val, &outVal
|
||||||
|
*out = new(PreparedDatabase)
|
||||||
|
(*in).DeepCopyInto(*out)
|
||||||
|
}
|
||||||
|
(*out)[key] = outVal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if in.SchedulerName != nil {
|
if in.SchedulerName != nil {
|
||||||
|
|
@ -633,7 +641,11 @@ func (in *PostgresSpec) DeepCopyInto(out *PostgresSpec) {
|
||||||
*out = new(string)
|
*out = new(string)
|
||||||
**out = **in
|
**out = **in
|
||||||
}
|
}
|
||||||
in.NodeAffinity.DeepCopyInto(&out.NodeAffinity)
|
if in.NodeAffinity != nil {
|
||||||
|
in, out := &in.NodeAffinity, &out.NodeAffinity
|
||||||
|
*out = new(corev1.NodeAffinity)
|
||||||
|
(*in).DeepCopyInto(*out)
|
||||||
|
}
|
||||||
if in.Tolerations != nil {
|
if in.Tolerations != nil {
|
||||||
in, out := &in.Tolerations, &out.Tolerations
|
in, out := &in.Tolerations, &out.Tolerations
|
||||||
*out = make([]corev1.Toleration, len(*in))
|
*out = make([]corev1.Toleration, len(*in))
|
||||||
|
|
@ -953,9 +965,17 @@ func (in *PreparedDatabase) DeepCopyInto(out *PreparedDatabase) {
|
||||||
*out = *in
|
*out = *in
|
||||||
if in.PreparedSchemas != nil {
|
if in.PreparedSchemas != nil {
|
||||||
in, out := &in.PreparedSchemas, &out.PreparedSchemas
|
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 {
|
for key, val := range *in {
|
||||||
(*out)[key] = *val.DeepCopy()
|
var outVal *PreparedSchema
|
||||||
|
if val == nil {
|
||||||
|
(*out)[key] = nil
|
||||||
|
} else {
|
||||||
|
in, out := &val, &outVal
|
||||||
|
*out = new(PreparedSchema)
|
||||||
|
(*in).DeepCopyInto(*out)
|
||||||
|
}
|
||||||
|
(*out)[key] = outVal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if in.Extensions != nil {
|
if in.Extensions != nil {
|
||||||
|
|
|
||||||
|
|
@ -113,9 +113,9 @@ func New(cfg Config, kubeClient k8sutil.KubernetesClient, pgSpec acidv1.Postgres
|
||||||
|
|
||||||
return fmt.Sprintf("%s-%s", e.PodName, e.ResourceVersion), nil
|
return fmt.Sprintf("%s-%s", e.PodName, e.ResourceVersion), nil
|
||||||
})
|
})
|
||||||
password_encryption, ok := pgSpec.Spec.PostgresqlParam.Parameters["password_encryption"]
|
passwordEncryption, ok := pgSpec.Spec.PostgresqlParam.Parameters["password_encryption"]
|
||||||
if !ok {
|
if !ok {
|
||||||
password_encryption = "md5"
|
passwordEncryption = "md5"
|
||||||
}
|
}
|
||||||
|
|
||||||
cluster := &Cluster{
|
cluster := &Cluster{
|
||||||
|
|
@ -128,7 +128,7 @@ func New(cfg Config, kubeClient k8sutil.KubernetesClient, pgSpec acidv1.Postgres
|
||||||
Secrets: make(map[types.UID]*v1.Secret),
|
Secrets: make(map[types.UID]*v1.Secret),
|
||||||
Services: make(map[PostgresRole]*v1.Service),
|
Services: make(map[PostgresRole]*v1.Service),
|
||||||
Endpoints: make(map[PostgresRole]*v1.Endpoints)},
|
Endpoints: make(map[PostgresRole]*v1.Endpoints)},
|
||||||
userSyncStrategy: users.DefaultUserSyncStrategy{PasswordEncryption: password_encryption},
|
userSyncStrategy: users.DefaultUserSyncStrategy{PasswordEncryption: passwordEncryption},
|
||||||
deleteOptions: metav1.DeleteOptions{PropagationPolicy: &deletePropagationPolicy},
|
deleteOptions: metav1.DeleteOptions{PropagationPolicy: &deletePropagationPolicy},
|
||||||
podEventsQueue: podEventsQueue,
|
podEventsQueue: podEventsQueue,
|
||||||
KubeClient: kubeClient,
|
KubeClient: kubeClient,
|
||||||
|
|
@ -975,7 +975,7 @@ func (c *Cluster) initSystemUsers() {
|
||||||
func (c *Cluster) initPreparedDatabaseRoles() error {
|
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
|
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
|
// 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
|
// get list of prepared schemas to set in search_path
|
||||||
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()}}
|
||||||
}
|
}
|
||||||
|
|
||||||
var searchPath strings.Builder
|
var searchPath strings.Builder
|
||||||
|
|
|
||||||
|
|
@ -763,7 +763,7 @@ func TestInitSystemUsers(t *testing.T) {
|
||||||
func TestPreparedDatabases(t *testing.T) {
|
func TestPreparedDatabases(t *testing.T) {
|
||||||
testName := "TestDefaultPreparedDatabase"
|
testName := "TestDefaultPreparedDatabase"
|
||||||
|
|
||||||
cl.Spec.PreparedDatabases = map[string]acidv1.PreparedDatabase{}
|
cl.Spec.PreparedDatabases = map[string]*acidv1.PreparedDatabase{}
|
||||||
cl.initPreparedDatabaseRoles()
|
cl.initPreparedDatabaseRoles()
|
||||||
|
|
||||||
for _, role := range []string{"acid_test_owner", "acid_test_reader", "acid_test_writer",
|
for _, role := range []string{"acid_test_owner", "acid_test_reader", "acid_test_writer",
|
||||||
|
|
@ -775,10 +775,10 @@ func TestPreparedDatabases(t *testing.T) {
|
||||||
|
|
||||||
testName = "TestPreparedDatabaseWithSchema"
|
testName = "TestPreparedDatabaseWithSchema"
|
||||||
|
|
||||||
cl.Spec.PreparedDatabases = map[string]acidv1.PreparedDatabase{
|
cl.Spec.PreparedDatabases = map[string]*acidv1.PreparedDatabase{
|
||||||
"foo": {
|
"foo": {
|
||||||
DefaultUsers: true,
|
DefaultUsers: true,
|
||||||
PreparedSchemas: map[string]acidv1.PreparedSchema{
|
PreparedSchemas: map[string]*acidv1.PreparedSchema{
|
||||||
"bar": {
|
"bar": {
|
||||||
DefaultUsers: true,
|
DefaultUsers: true,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ import (
|
||||||
"github.com/zalando/postgres-operator/pkg/util/k8sutil"
|
"github.com/zalando/postgres-operator/pkg/util/k8sutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
// K8S objects that are belong to connection pooler
|
// ConnectionPoolerObjects K8s objects that are belong to connection pooler
|
||||||
type ConnectionPoolerObjects struct {
|
type ConnectionPoolerObjects struct {
|
||||||
Deployment *appsv1.Deployment
|
Deployment *appsv1.Deployment
|
||||||
Service *v1.Service
|
Service *v1.Service
|
||||||
|
|
|
||||||
|
|
@ -1223,7 +1223,7 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*appsv1.Statef
|
||||||
effectiveRunAsUser,
|
effectiveRunAsUser,
|
||||||
effectiveRunAsGroup,
|
effectiveRunAsGroup,
|
||||||
effectiveFSGroup,
|
effectiveFSGroup,
|
||||||
nodeAffinity(c.OpConfig.NodeReadinessLabel, &spec.NodeAffinity),
|
nodeAffinity(c.OpConfig.NodeReadinessLabel, spec.NodeAffinity),
|
||||||
spec.SchedulerName,
|
spec.SchedulerName,
|
||||||
int64(c.OpConfig.PodTerminateGracePeriod.Seconds()),
|
int64(c.OpConfig.PodTerminateGracePeriod.Seconds()),
|
||||||
c.OpConfig.PodServiceAccountName,
|
c.OpConfig.PodServiceAccountName,
|
||||||
|
|
|
||||||
|
|
@ -882,7 +882,7 @@ func TestNodeAffinity(t *testing.T) {
|
||||||
Volume: acidv1.Volume{
|
Volume: acidv1.Volume{
|
||||||
Size: "1G",
|
Size: "1G",
|
||||||
},
|
},
|
||||||
NodeAffinity: *nodeAffinity,
|
NodeAffinity: nodeAffinity,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -655,7 +655,7 @@ func (c *Cluster) syncDatabases() error {
|
||||||
|
|
||||||
// if no prepared databases are specified create a database named like the cluster
|
// 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
|
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 {
|
for preparedDatabaseName := range c.Spec.PreparedDatabases {
|
||||||
_, exists := currentDatabases[preparedDatabaseName]
|
_, exists := currentDatabases[preparedDatabaseName]
|
||||||
|
|
@ -710,7 +710,7 @@ func (c *Cluster) syncPreparedDatabases() error {
|
||||||
// now, prepare defined schemas
|
// now, prepare defined schemas
|
||||||
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()}}
|
||||||
}
|
}
|
||||||
if err := c.syncPreparedSchemas(preparedDbName, preparedSchemas); err != nil {
|
if err := c.syncPreparedSchemas(preparedDbName, preparedSchemas); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -729,7 +729,7 @@ func (c *Cluster) syncPreparedDatabases() error {
|
||||||
return nil
|
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")
|
c.setProcessName("syncing prepared schemas")
|
||||||
|
|
||||||
currentSchemas, err := c.getSchemas()
|
currentSchemas, err := c.getSchemas()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue