Skip to content

Commit 5d4a21d

Browse files
jkatzJonathan S. Katz
authored andcommitted
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, or any combination of the like. Issue: [sc-13149] Issue: #2850
1 parent 1e85587 commit 5d4a21d

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

internal/apiserver/backrestservice/backrestimpl.go

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,16 +266,55 @@ func DeleteBackup(request msgs.DeleteBackrestBackupRequest) msgs.DeleteBackrestB
266266
return response
267267
}
268268

269+
// determine if TLS verification is enabled or not
270+
verifyTLS, _ := strconv.ParseBool(operator.GetS3VerifyTLSSetting(cluster))
271+
269272
// set up the command
270273
cmd := pgBackRestExpireCommand
271274
cmd = append(cmd, request.Target)
272275

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

281320
return response

0 commit comments

Comments
 (0)