Skip to content

Commit 3817747

Browse files
committed
Fix S3-Only Cluster Cloning (4.2 backpatch)
All S3 environment variables are now properly set on both the pgBackRest repo Pod and the pgBackRest restore Job when cloning a pgcluster. This ensure the restore is able to complete successfully during the second step of the clone workflow when cloning a cluster that utilizes S3 only with pgBackRest.
1 parent 843679e commit 3817747

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

controller/jobcontroller.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -448,15 +448,25 @@ func (c *JobController) onUpdate(oldObj, newObj interface{}) {
448448
// next, update the workflow to indicate that step 1 is complete
449449
clusteroperator.UpdateCloneWorkflow(c.JobClient, namespace, workflowID, crv1.PgtaskWorkflowCloneRestoreBackup)
450450

451+
// determine the storage source (e.g. local or s3) to use for the restore based on the storage
452+
// source utilized for the backrest repo sync job
453+
var storageSource string
454+
for _, envVar := range job.Spec.Template.Spec.Containers[0].Env {
455+
if envVar.Name == "BACKREST_STORAGE_SOURCE" {
456+
storageSource = envVar.Value
457+
}
458+
}
459+
451460
// now, set up a new pgtask that will allow us to perform the restore
452461
cloneTask := util.CloneTask{
453-
PGOUser: job.ObjectMeta.Labels[config.LABEL_PGOUSER],
454-
SourceClusterName: sourceClusterName,
455-
TargetClusterName: targetClusterName,
456-
TaskStepLabel: config.LABEL_PGO_CLONE_STEP_2,
457-
TaskType: crv1.PgtaskCloneStep2,
458-
Timestamp: time.Now(),
459-
WorkflowID: workflowID,
462+
BackrestStorageSource: storageSource,
463+
PGOUser: job.ObjectMeta.Labels[config.LABEL_PGOUSER],
464+
SourceClusterName: sourceClusterName,
465+
TargetClusterName: targetClusterName,
466+
TaskStepLabel: config.LABEL_PGO_CLONE_STEP_2,
467+
TaskType: crv1.PgtaskCloneStep2,
468+
Timestamp: time.Now(),
469+
WorkflowID: workflowID,
460470
}
461471

462472
task := cloneTask.Create()

operator/cluster/clone.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,11 @@ func cloneStep2(clientset *kubernetes.Clientset, client *rest.RESTClient, namesp
324324
},
325325
},
326326
Spec: crv1.PgclusterSpec{
327-
Port: sourcePgcluster.Spec.Port,
328-
PrimaryStorage: sourcePgcluster.Spec.PrimaryStorage,
327+
BackrestS3Bucket: sourcePgcluster.Spec.BackrestS3Bucket,
328+
BackrestS3Endpoint: sourcePgcluster.Spec.BackrestS3Endpoint,
329+
BackrestS3Region: sourcePgcluster.Spec.BackrestS3Region,
330+
Port: sourcePgcluster.Spec.Port,
331+
PrimaryStorage: sourcePgcluster.Spec.PrimaryStorage,
329332
UserLabels: map[string]string{
330333
config.LABEL_BACKREST_STORAGE_TYPE: sourcePgcluster.Spec.UserLabels[config.LABEL_BACKREST_STORAGE_TYPE],
331334
},

0 commit comments

Comments
 (0)