Skip to content

Commit 47076dc

Browse files
andrewlecuyerJonathan S. Katz
authored andcommitted
Only Delete Backup pgtask if One Already Exists
When cleaning the existing backup pgtask Custom Resource prior to creating a new backup for a cluster, the PostgreSQL Operator will now only attempt to delete a prior backup pgtask if one currently exists. This ensures that certain backups can be properly submitted and executed in the event that the pgtask from the previous cluster backup has been removed (either manually or by the Operator). For instance, this ensures that the post-restore backup executed following a cluster restore can still be executed in the event that the user has scaled down the cluster prior to the restore, since successfully scaling down a replica currently results in the deletion of all pgtasks for the specific cluster.
1 parent 4b48932 commit 47076dc

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

operator/backrest/backup.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -225,22 +225,27 @@ func CreateBackup(restclient *rest.RESTClient, namespace, clusterName, podName s
225225
func CleanBackupResources(restclient *rest.RESTClient, clientset *kubernetes.Clientset, namespace,
226226
clusterName string) error {
227227

228-
pgtask := crv1.Pgtask{}
229228
taskName := "backrest-backup-" + clusterName
230-
// error if it already exists
231-
found, err := kubeapi.Getpgtask(restclient, &pgtask, taskName, namespace)
232-
if !found {
233-
log.Debugf("backrest backup pgtask %s was not found so we will create it", taskName)
234-
} else if err != nil {
229+
// lookup the pgBackRest backup pgtask for the cluster to determine if it exsits
230+
found, err := kubeapi.Getpgtask(restclient, &crv1.Pgtask{}, taskName, namespace)
231+
if err != nil {
235232
log.Error(err)
236233
return err
237234
}
238235

239-
log.Debugf("pgtask %s was found so we will recreate it", taskName)
240-
//remove the existing pgtask
241-
err = kubeapi.Deletepgtask(restclient, taskName, namespace)
242-
if err != nil {
243-
return err
236+
// if the pgBackRest backup pgtask exits, then delete it so that a new pgBackRest backup
237+
// pgtask can be created in order to initiate a new backup
238+
if found {
239+
log.Debugf("pgtask %s was found when cleaning backup resources prior to creating a new "+
240+
"backrest backup pgtask and will be deleted", taskName)
241+
// delete the existing pgBackRest backup pgtask
242+
err = kubeapi.Deletepgtask(restclient, taskName, namespace)
243+
if err != nil {
244+
return err
245+
}
246+
} else {
247+
log.Debugf("pgtask %s was not found when cleaning backup resources prior to creating a "+
248+
"new backrest backup pgtask", taskName)
244249
}
245250

246251
//remove previous backup job

0 commit comments

Comments
 (0)