Skip to content

Commit 6ee3d66

Browse files
gbartoliniarmru
andauthored
fix(recovery): fix external cluster validation (cloudnative-pg#10268)
Add missing check for `ConnectionParameters` in `validateBootstrapRecoverySource` and update the error message to include all valid configuration types. Closes cloudnative-pg#10260 Signed-off-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com> Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com> Co-authored-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
1 parent da1cbdb commit 6ee3d66

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

internal/webhook/v1/cluster_webhook.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,14 +682,16 @@ func (v *ClusterCustomValidator) validateBootstrapRecoverySource(r *apiv1.Cluste
682682

683683
// Ensure the external cluster definition has enough information
684684
// to be used to recover a data directory
685-
if externalCluster.BarmanObjectStore == nil && externalCluster.PluginConfiguration == nil {
685+
if externalCluster.ConnectionParameters == nil &&
686+
externalCluster.BarmanObjectStore == nil &&
687+
externalCluster.PluginConfiguration == nil {
686688
result = append(
687689
result,
688690
field.Invalid(
689691
field.NewPath("spec", "bootstrap", "recovery", "source"),
690692
r.Spec.Bootstrap.Recovery.Source,
691693
fmt.Sprintf("External cluster %v cannot be used for recovery: "+
692-
"both Barman and CNPG-i plugin configurations are missing", r.Spec.Bootstrap.Recovery.Source)))
694+
"missing connection parameters, Barman, or CNPG-i configuration", r.Spec.Bootstrap.Recovery.Source)))
693695
}
694696

695697
return result

pkg/management/postgres/restore.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,12 @@ func (info InitInfo) RestoreSnapshot(ctx context.Context, cli client.Client, imm
154154
restoreCmd)
155155

156156
if pluginConfiguration := cluster.GetRecoverySourcePlugin(); pluginConfiguration == nil {
157-
envs, config, err = info.createEnvAndConfigForSnapshotRestore(ctx, cli, cluster)
158-
if err != nil {
159-
return err
157+
server, found := cluster.ExternalCluster(cluster.Spec.Bootstrap.Recovery.Source)
158+
if found && server.BarmanObjectStore != nil {
159+
envs, config, err = info.createEnvAndConfigForSnapshotRestore(ctx, cli, cluster, &server)
160+
if err != nil {
161+
return err
162+
}
160163
}
161164
}
162165

@@ -218,20 +221,12 @@ func (info InitInfo) createEnvAndConfigForSnapshotRestore(
218221
ctx context.Context,
219222
typedClient client.Client,
220223
cluster *apiv1.Cluster,
224+
server *apiv1.ExternalCluster,
221225
) ([]string, string, error) {
222226
contextLogger := log.FromContext(ctx)
223-
sourceName := cluster.Spec.Bootstrap.Recovery.Source
224-
225-
if sourceName == "" {
226-
return nil, "", fmt.Errorf("recovery source not specified")
227-
}
228227

229-
contextLogger.Info("Recovering from external cluster", "sourceName", sourceName)
228+
contextLogger.Info("Recovering from external cluster", "sourceName", server.Name)
230229

231-
server, found := cluster.ExternalCluster(sourceName)
232-
if !found {
233-
return nil, "", fmt.Errorf("missing external cluster: %v", sourceName)
234-
}
235230
serverName := server.GetServerName()
236231

237232
env, err := barmanCredentials.EnvSetRestoreCloudCredentials(

0 commit comments

Comments
 (0)