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:
Marco Nenciarini 2026-07-16 18:05:28 +02:00 committed by Leonardo Cecchi
parent 1d777435d0
commit 7efb2cdf56
2 changed files with 29 additions and 7 deletions

View File

@ -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,

View File

@ -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)
} }