Skip to content

Commit 2d2f2c6

Browse files
authored
Ensure "pgo delete backup" works for non-POSIX storage
This modifies the "pgo delete backup" command to work with non-POSIX storage, i.e. S3, GCS, or any combination of the like. Issue: [sc-13149] Issue: #2850
1 parent 0d739ef commit 2d2f2c6

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

internal/apiserver/backrestservice/backrestimpl.go

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,16 +270,57 @@ func DeleteBackup(request msgs.DeleteBackrestBackupRequest) msgs.DeleteBackrestB
270270
return response
271271
}
272272

273+
// determine if TLS verification is enabled or not
274+
verifyTLS, _ := strconv.ParseBool(operator.GetS3VerifyTLSSetting(cluster))
275+
273276
// set up the command
274277
cmd := pgBackRestExpireCommand
275278
cmd = append(cmd, request.Target)
276279

277-
// and execute. if there is an error, return it, otherwise we are done
278-
if _, stderr, err := kubeapi.ExecToPodThroughAPI(apiserver.RESTConfig,
279-
apiserver.Clientset, cmd, containername, podName, cluster.Namespace, nil); err != nil {
280-
log.Error(stderr)
280+
// first, if storage types is empty, assume it's the posix storage type
281+
storageTypes := cluster.Spec.BackrestStorageTypes
282+
if len(storageTypes) == 0 {
283+
storageTypes = append(storageTypes, crv1.BackrestStorageTypePosix)
284+
}
285+
286+
// otherwise, iterate through the different repositories types that are
287+
// available. if it's a non-local repository, we need to set an explicit
288+
// "--repo-type"
289+
ok := false
290+
291+
for _, storageType := range storageTypes {
292+
c := cmd
293+
294+
switch storageType {
295+
default: // do nothing
296+
case crv1.BackrestStorageTypeS3:
297+
c = append(c, repoTypeFlagS3...)
298+
299+
if !verifyTLS {
300+
c = append(c, noRepoS3VerifyTLS)
301+
}
302+
case crv1.BackrestStorageTypeGCS:
303+
c = append(c, repoTypeFlagGCS...)
304+
}
305+
306+
// so...we don't necessarily care about the error here, because we're
307+
// looking for which of the repos contains the target backup. We'll log the
308+
// error, and return it if we don't have success
309+
if _, stderr, err := kubeapi.ExecToPodThroughAPI(apiserver.RESTConfig,
310+
apiserver.Clientset, c, containername, podName, cluster.Namespace, nil); err != nil {
311+
log.Infof("repo type %s does not contain backup %s or other error.", storageType, request.Target)
312+
log.Info(stderr)
313+
} else {
314+
ok = true
315+
}
316+
}
317+
318+
// if we don't ever delete the backup, provide a message as to why
319+
if !ok {
320+
msg := fmt.Sprintf("could not find backup %s in any repo or check logs for other errors.", request.Target)
321+
log.Errorf(msg)
281322
response.Code = msgs.Error
282-
response.Msg = stderr
323+
response.Msg = msg
283324
}
284325

285326
return response

0 commit comments

Comments
 (0)