Skip to content

Commit d53718f

Browse files
committed
Merge branch '203-clone-config-overriding' into 'master'
* do not override user-defined configs in clones * apply only additional configs when creating a clone * manually created snapshots should contain appropriate logs configuration (https://gitlab.com/postgres-ai/database-lab/-/blob/master/configs/postgres/postgresql.conf). Closes #203 See merge request postgres-ai/database-lab!208
2 parents 873d785 + f180061 commit d53718f

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

pkg/services/provision/databases/postgres/configuration/configuration.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/pkg/errors"
1515

1616
"gitlab.com/postgres-ai/database-lab/pkg/log"
17+
"gitlab.com/postgres-ai/database-lab/pkg/retrieval/engine/postgres/tools/fs"
1718
"gitlab.com/postgres-ai/database-lab/pkg/util"
1819
)
1920

@@ -109,10 +110,6 @@ func (c Corrector) Run(dataDir string) error {
109110
}
110111
}
111112

112-
for configKey, configValue := range c.ExtraConfig {
113-
pgConfDstLines = append(pgConfDstLines, fmt.Sprintf("%s = '%s'", configKey, configValue))
114-
}
115-
116113
output := strings.Join(pgConfDstLines, "\n")
117114

118115
if err := ioutil.WriteFile(pgConfDst, []byte(output), 0644); err != nil {
@@ -121,3 +118,23 @@ func (c Corrector) Run(dataDir string) error {
121118

122119
return nil
123120
}
121+
122+
// ApplyExtraConf applies extra configuration to the provided Postgres directory.
123+
func (c Corrector) ApplyExtraConf(dataDir string) error {
124+
log.Dbg("Applying extra configuration")
125+
126+
pgConf := path.Join(dataDir, pgConfName)
127+
pgConfLines := make([]string, 0, len(c.ExtraConfig))
128+
129+
for configKey, configValue := range c.ExtraConfig {
130+
pgConfLines = append(pgConfLines, fmt.Sprintf("%s = '%s'", configKey, configValue))
131+
}
132+
133+
output := strings.Join(pgConfLines, "\n")
134+
135+
if err := fs.AppendFile(pgConf, []byte(output)); err != nil {
136+
return errors.Wrapf(err, "cannot write extra configuration to %s", pgConf)
137+
}
138+
139+
return nil
140+
}

pkg/services/provision/databases/postgres/postgres.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ const (
4040
func Start(r runners.Runner, c *resources.AppConfig) error {
4141
log.Dbg("Starting Postgres container...")
4242

43-
if err := configuration.NewCorrectorWithExtraConfig(c.ExtraConf()).Run(c.DataDir()); err != nil {
44-
return errors.Wrap(err, "cannot update configs")
43+
if extraConf := c.ExtraConf(); len(extraConf) > 0 {
44+
if err := configuration.NewCorrectorWithExtraConfig(extraConf).ApplyExtraConf(c.DataDir()); err != nil {
45+
return errors.Wrap(err, "cannot update configs")
46+
}
4547
}
4648

4749
if _, err := docker.RunContainer(r, c); err != nil {

0 commit comments

Comments
 (0)