@@ -1678,10 +1678,29 @@ func (r *Reconciler) reconcilePostgresClusterDataSource(ctx context.Context,
16781678 return nil
16791679 }
16801680
1681- // First, create the restore configuration and ensure secrets exist
1681+ // First, copy the restore configuration from the source cluster and ensure secrets exist
16821682 // before proceeding with other operations
1683- if err := r .createRestoreConfig (ctx , cluster , configHash ); err != nil {
1684- return err
1683+ sourceCluster := & v1beta1.PostgresCluster {}
1684+ if dataSource .ClusterName != "" && dataSource .ClusterNamespace != "" {
1685+ if err := r .Client .Get (ctx , types.NamespacedName {
1686+ Name : dataSource .ClusterName ,
1687+ Namespace : dataSource .ClusterNamespace ,
1688+ }, sourceCluster ); err != nil {
1689+ // If source is not found, proceed with the restore using nil for sourceCluster
1690+ if ! apierrors .IsNotFound (err ) {
1691+ return errors .WithStack (err )
1692+ }
1693+ sourceCluster = nil
1694+ }
1695+ } else {
1696+ sourceCluster = nil
1697+ }
1698+
1699+ // Copy configuration from source cluster if it exists
1700+ if sourceCluster != nil {
1701+ if err := r .copyRestoreConfiguration (ctx , cluster , sourceCluster ); err != nil {
1702+ return err
1703+ }
16851704 }
16861705
16871706 // Create a fake StatefulSet for reconciling the PGBackRest secret
@@ -1698,21 +1717,6 @@ func (r *Reconciler) reconcilePostgresClusterDataSource(ctx context.Context,
16981717 }
16991718
17001719 // Now proceed with volumes and other resources for the restore
1701- sourceCluster := & v1beta1.PostgresCluster {}
1702- if dataSource .ClusterName != "" && dataSource .ClusterNamespace != "" {
1703- if err := r .Client .Get (ctx , types.NamespacedName {
1704- Name : dataSource .ClusterName ,
1705- Namespace : dataSource .ClusterNamespace ,
1706- }, sourceCluster ); err != nil {
1707- // If source is not found, proceed with the restore using nil for sourceCluster
1708- if ! apierrors .IsNotFound (err ) {
1709- return errors .WithStack (err )
1710- }
1711- sourceCluster = nil
1712- }
1713- } else {
1714- sourceCluster = nil
1715- }
17161720
17171721 // Define a fake STS to use when calling the reconcile functions below since when
17181722 // bootstrapping the cluster it will not exist until after the restore is complete.
0 commit comments