Skip to content

Commit e8c8dcd

Browse files
authored
refactor(restore): remove duplicate code (cloudnative-pg#7388)
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
1 parent 91aeecb commit e8c8dcd

File tree

1 file changed

+11
-36
lines changed

1 file changed

+11
-36
lines changed

pkg/management/postgres/restore.go

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,16 @@ func (info InitInfo) RestoreSnapshot(ctx context.Context, cli client.Client, imm
166166
return err
167167
}
168168

169+
return info.concludeRestore(ctx, cli, cluster, config, envs)
170+
}
171+
172+
func (info InitInfo) concludeRestore(
173+
ctx context.Context,
174+
cli client.Client,
175+
cluster *apiv1.Cluster,
176+
config string,
177+
envs []string,
178+
) error {
169179
if err := info.WriteInitialPostgresqlConf(ctx, cluster); err != nil {
170180
return err
171181
}
@@ -334,42 +344,7 @@ func (info InitInfo) Restore(ctx context.Context, cli client.Client) error {
334344
envs = env
335345
}
336346

337-
if err := info.WriteInitialPostgresqlConf(ctx, cluster); err != nil {
338-
return err
339-
}
340-
// we need a migration here, otherwise the server will not start up if
341-
// we recover from a base which has postgresql.auto.conf
342-
// the override.conf and include statement is present, what we need to do is to
343-
// migrate the content
344-
if _, err := info.GetInstance().migratePostgresAutoConfFile(ctx); err != nil {
345-
return err
346-
}
347-
if cluster.IsReplica() {
348-
server, ok := cluster.ExternalCluster(cluster.Spec.ReplicaCluster.Source)
349-
if !ok {
350-
return fmt.Errorf("missing external cluster: %v", cluster.Spec.ReplicaCluster.Source)
351-
}
352-
353-
connectionString, err := external.ConfigureConnectionToServer(
354-
ctx, cli, info.Namespace, &server)
355-
if err != nil {
356-
return err
357-
}
358-
359-
// TODO: Using a replication slot on replica cluster is not supported (yet?)
360-
_, err = UpdateReplicaConfiguration(info.PgData, connectionString, "")
361-
return err
362-
}
363-
364-
if err := info.WriteRestoreHbaConf(ctx); err != nil {
365-
return err
366-
}
367-
368-
if err := info.writeCustomRestoreWalConfig(cluster, config); err != nil {
369-
return err
370-
}
371-
372-
return info.ConfigureInstanceAfterRestore(ctx, cluster, envs)
347+
return info.concludeRestore(ctx, cli, cluster, config, envs)
373348
}
374349

375350
func (info InitInfo) ensureArchiveContainsLastCheckpointRedoWAL(

0 commit comments

Comments
 (0)