mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-09-06 15:02: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
9c84d069ed
commit
9304fd14cf
2
go.mod
2
go.mod
@ -7,7 +7,7 @@ require (
|
|||||||
github.com/cloudnative-pg/api v1.30.0
|
github.com/cloudnative-pg/api v1.30.0
|
||||||
github.com/cloudnative-pg/barman-cloud v0.5.2-0.20260709152604-43158c204df1
|
github.com/cloudnative-pg/barman-cloud v0.5.2-0.20260709152604-43158c204df1
|
||||||
github.com/cloudnative-pg/cloudnative-pg v1.30.0
|
github.com/cloudnative-pg/cloudnative-pg v1.30.0
|
||||||
github.com/cloudnative-pg/cnpg-i v0.5.0
|
github.com/cloudnative-pg/cnpg-i v0.5.1-0.20260716144117-db806aee0db1
|
||||||
github.com/cloudnative-pg/cnpg-i-machinery v0.4.2
|
github.com/cloudnative-pg/cnpg-i-machinery v0.4.2
|
||||||
github.com/cloudnative-pg/machinery v0.5.0
|
github.com/cloudnative-pg/machinery v0.5.0
|
||||||
github.com/onsi/ginkgo/v2 v2.32.0
|
github.com/onsi/ginkgo/v2 v2.32.0
|
||||||
|
|||||||
2
go.sum
2
go.sum
@ -26,6 +26,8 @@ github.com/cloudnative-pg/cloudnative-pg v1.30.0 h1:fnhVq44xXx97MNiuvJsPrX1vSjYb
|
|||||||
github.com/cloudnative-pg/cloudnative-pg v1.30.0/go.mod h1:QkolwBOWZ+GvAiJt6KpDSymwkpf0K19/p4Q6MQlTM8U=
|
github.com/cloudnative-pg/cloudnative-pg v1.30.0/go.mod h1:QkolwBOWZ+GvAiJt6KpDSymwkpf0K19/p4Q6MQlTM8U=
|
||||||
github.com/cloudnative-pg/cnpg-i v0.5.0 h1:/TOzpNT6cwNgrpftTtrnLKdoHgMwd+88vZgXjlVgXeE=
|
github.com/cloudnative-pg/cnpg-i v0.5.0 h1:/TOzpNT6cwNgrpftTtrnLKdoHgMwd+88vZgXjlVgXeE=
|
||||||
github.com/cloudnative-pg/cnpg-i v0.5.0/go.mod h1:7Gh4+UzhBpGhr4DreB1GN9wGYfvxwXCXZUyVt3zE/3I=
|
github.com/cloudnative-pg/cnpg-i v0.5.0/go.mod h1:7Gh4+UzhBpGhr4DreB1GN9wGYfvxwXCXZUyVt3zE/3I=
|
||||||
|
github.com/cloudnative-pg/cnpg-i v0.5.1-0.20260716144117-db806aee0db1 h1:HO7S6jJ21DhSS6oQg7Ok1+uT23hF6I58im1IIRMPufk=
|
||||||
|
github.com/cloudnative-pg/cnpg-i v0.5.1-0.20260716144117-db806aee0db1/go.mod h1:4kcpLAj+feMTnh0TVadXRASdVnEhBytNSm/BvktLgmI=
|
||||||
github.com/cloudnative-pg/cnpg-i-machinery v0.4.2 h1:0reS9MtyLYINHXQ/MfxJ9jp39hhBf8e3Qdj+T5Nsq6I=
|
github.com/cloudnative-pg/cnpg-i-machinery v0.4.2 h1:0reS9MtyLYINHXQ/MfxJ9jp39hhBf8e3Qdj+T5Nsq6I=
|
||||||
github.com/cloudnative-pg/cnpg-i-machinery v0.4.2/go.mod h1:gvrKabgxXq0zGthXGucemDdsxakLEQDMxn43M4HLW30=
|
github.com/cloudnative-pg/cnpg-i-machinery v0.4.2/go.mod h1:gvrKabgxXq0zGthXGucemDdsxakLEQDMxn43M4HLW30=
|
||||||
github.com/cloudnative-pg/machinery v0.5.0 h1:hhTnkzn+AiN3NmbjCQ6RXj5rfqV3K6arzq6kdXAzcnQ=
|
github.com/cloudnative-pg/machinery v0.5.0 h1:hhTnkzn+AiN3NmbjCQ6RXj5rfqV3K6arzq6kdXAzcnQ=
|
||||||
|
|||||||
@ -155,13 +155,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.
|
||||||
|
// The operator owns the marker file's lifecycle, so a non-nil decision
|
||||||
|
// already accounts for it and is obeyed as-is. A nil value means an
|
||||||
|
// 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)
|
checkFileExisting, err := fileutils.FileExists(emptyWalArchiveFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("while checking for empty wal archive check file %q: %w", emptyWalArchiveFile, err)
|
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