feat: pass the check_empty_wal_archive decision to plugins · cloudnative-pg/cloudnative-pg@73836fe · GitHub
Skip to content

Commit 73836fe

Browse files
mnencialeonardoce
authored andcommitted
feat: pass the check_empty_wal_archive decision to plugins
The empty-WAL-archive check depends on the Cluster's annotation and, for archiving, on a first-archive marker file whose lifecycle the operator owns. A plugin re-deriving this decision on its own (e.g. by reading the annotation directly) duplicates policy that belongs here. Compute the decision once and pass it explicitly to plugins through cnpg-i's new CheckEmptyWalArchive field, for both WAL archiving and the restore job hooks. The in-tree archiving path is refactored to share the same composition rule via shouldCheckEmptyWalArchive, instead of computing it twice. Closes #11217 Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
1 parent ad1d52c commit 73836fe

4 files changed

Lines changed: 39 additions & 13 deletions

File tree

‎internal/cnpi/plugin/client/contracts.go‎

Lines changed: 5 additions & 1 deletion

‎internal/cnpi/plugin/client/restore_job.go‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ import (
2626
"slices"
2727

2828
restore "github.com/cloudnative-pg/cnpg-i/pkg/restore/job"
29+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2930
"sigs.k8s.io/controller-runtime/pkg/client"
31+
32+
"github.com/cloudnative-pg/cloudnative-pg/pkg/utils"
3033
)
3134

3235
// ErrNoPluginSupportsRestoreJobHooksCapability is raised when no plugin supports the restore job hooks capability
@@ -62,8 +65,15 @@ func (data *data) innerRestore(
6265
if err != nil {
6366
return nil, err
6467
}
68+
69+
// Computed here so the plugin gets the operator's decision instead
70+
// of re-deriving it independently (e.g. from a Cluster annotation).
71+
checkEmptyWalArchive := utils.IsEmptyWalArchiveCheckEnabled(
72+
&metav1.ObjectMeta{Annotations: cluster.GetAnnotations()})
73+
6574
request := restore.RestoreRequest{
66-
ClusterDefinition: clusterDefinition,
75+
ClusterDefinition: clusterDefinition,
76+
CheckEmptyWalArchive: &checkEmptyWalArchive,
6777
}
6878
res, err := plugin.RestoreJobHooksClient().Restore(ctx, &request)
6979
if err != nil {

‎internal/cnpi/plugin/client/wal.go‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,16 @@ func (data *data) ArchiveWAL(
3535
ctx context.Context,
3636
cluster client.Object,
3737
sourceFileName string,
38+
checkEmptyWalArchive bool,
3839
) error {
39-
return wrapAsPluginErrorIfNeeded(data.innerArchiveWAL(ctx, cluster, sourceFileName))
40+
return wrapAsPluginErrorIfNeeded(data.innerArchiveWAL(ctx, cluster, sourceFileName, checkEmptyWalArchive))
4041
}
4142

4243
func (data *data) innerArchiveWAL(
4344
ctx context.Context,
4445
cluster client.Object,
4546
sourceFileName string,
47+
checkEmptyWalArchive bool,
4648
) error {
4749
contextLogger := log.FromContext(ctx)
4850

@@ -64,8 +66,9 @@ func (data *data) innerArchiveWAL(
6466

6567
pluginLogger := contextLogger.WithValues("pluginName", plugin.Name())
6668
request := wal.WALArchiveRequest{
67-
ClusterDefinition: serializedCluster,
68-
SourceFileName: sourceFileName,
69+
ClusterDefinition: serializedCluster,
70+
SourceFileName: sourceFileName,
71+
CheckEmptyWalArchive: &checkEmptyWalArchive,
6972
}
7073

7174
pluginLogger.Trace(

‎pkg/management/postgres/archiver/archiver.go‎

Lines changed: 17 additions & 8 deletions

0 commit comments

Comments
 (0)