mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-09-04 22:22:21 +02:00
feat: honor the operator's check_empty_wal_archive decision
Archive() and the restore job hook each re-derived, on their own, whether to verify the WAL archive destination is empty, by reading a Cluster annotation and, for Archive, an on-disk marker file. That decision belongs to the operator, which already tracks both the annotation and the marker file's lifecycle. Honor cnpg-i's new WALArchiveRequest/RestoreRequest field CheckEmptyWalArchive when the operator sets it: obey it directly, without re-inspecting the marker file. Only fall back to the previous annotation-and-marker-file logic when talking to an operator that predates this field. Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
This commit is contained in:
parent
1d777435d0
commit
7efb2cdf56
@ -156,13 +156,23 @@ func (w WALServiceImplementation) Archive(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 2: Check if the archive location is safe to perform archiving
|
// Step 2: Check if the archive location is safe to perform archiving.
|
||||||
checkFileExisting, err := fileutils.FileExists(emptyWalArchiveFile)
|
// The operator owns the marker file's lifecycle, so a non-nil decision
|
||||||
if err != nil {
|
// already accounts for it and is obeyed as-is. A nil value means an
|
||||||
return nil, fmt.Errorf("while checking for empty wal archive check file %q: %w", emptyWalArchiveFile, err)
|
// operator that predates this field; fall back to checking the marker
|
||||||
|
// file and Cluster annotation directly.
|
||||||
|
var checkEmptyWalArchive bool
|
||||||
|
if request.CheckEmptyWalArchive != nil {
|
||||||
|
checkEmptyWalArchive = *request.CheckEmptyWalArchive
|
||||||
|
} else {
|
||||||
|
checkFileExisting, err := fileutils.FileExists(emptyWalArchiveFile)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("while checking for empty wal archive check file %q: %w", emptyWalArchiveFile, err)
|
||||||
|
}
|
||||||
|
checkEmptyWalArchive = utils.IsEmptyWalArchiveCheckEnabled(&configuration.Cluster.ObjectMeta) && checkFileExisting
|
||||||
}
|
}
|
||||||
|
|
||||||
if utils.IsEmptyWalArchiveCheckEnabled(&configuration.Cluster.ObjectMeta) && checkFileExisting {
|
if checkEmptyWalArchive {
|
||||||
if err := CheckBackupDestination(
|
if err := CheckBackupDestination(
|
||||||
ctx,
|
ctx,
|
||||||
&objectStore.Spec.Configuration,
|
&objectStore.Spec.Configuration,
|
||||||
|
|||||||
@ -113,6 +113,7 @@ func (impl JobHookImpl) Restore(
|
|||||||
configuration.Cluster,
|
configuration.Cluster,
|
||||||
&targetObjectStore.Spec.Configuration,
|
&targetObjectStore.Spec.Configuration,
|
||||||
targetObjectStore.Name,
|
targetObjectStore.Name,
|
||||||
|
req.CheckEmptyWalArchive,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -250,6 +251,7 @@ func (impl *JobHookImpl) checkBackupDestination(
|
|||||||
cluster *cnpgv1.Cluster,
|
cluster *cnpgv1.Cluster,
|
||||||
barmanConfiguration *cnpgv1.BarmanObjectStoreConfiguration,
|
barmanConfiguration *cnpgv1.BarmanObjectStoreConfiguration,
|
||||||
objectStoreName string,
|
objectStoreName string,
|
||||||
|
operatorCheckEmptyWalArchive *bool,
|
||||||
) error {
|
) error {
|
||||||
// Get environment from cache
|
// Get environment from cache
|
||||||
env, err := barmanCredentials.EnvSetCloudCredentialsAndCertificates(ctx,
|
env, err := barmanCredentials.EnvSetCloudCredentialsAndCertificates(ctx,
|
||||||
@ -288,8 +290,18 @@ func (impl *JobHookImpl) checkBackupDestination(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we're ok to archive in the desired destination
|
// Check if we're ok to restore from the desired destination. Unlike
|
||||||
if utils.IsEmptyWalArchiveCheckEnabled(&cluster.ObjectMeta) {
|
// archiving, restore is a one-shot operation that has never been gated
|
||||||
|
// on the first-archive marker file, so the only fallback needed here
|
||||||
|
// (for an operator that predates this field) is the Cluster annotation.
|
||||||
|
var checkEmptyWalArchive bool
|
||||||
|
if operatorCheckEmptyWalArchive != nil {
|
||||||
|
checkEmptyWalArchive = *operatorCheckEmptyWalArchive
|
||||||
|
} else {
|
||||||
|
checkEmptyWalArchive = utils.IsEmptyWalArchiveCheckEnabled(&cluster.ObjectMeta)
|
||||||
|
}
|
||||||
|
|
||||||
|
if checkEmptyWalArchive {
|
||||||
return common.CheckBackupDestination(ctx, barmanConfiguration, walArchiver, serverName)
|
return common.CheckBackupDestination(ctx, barmanConfiguration, walArchiver, serverName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user