From eae195b5d3b3a828b1110edf3ed84b6ec223a955 Mon Sep 17 00:00:00 2001 From: Marco Nenciarini Date: Thu, 8 May 2025 15:05:56 +0200 Subject: [PATCH] feat: fall back on recovery source object if cluster is not defined Signed-off-by: Marco Nenciarini --- .../cnpgi/operator/lifecycle_resources.go | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/internal/cnpgi/operator/lifecycle_resources.go b/internal/cnpgi/operator/lifecycle_resources.go index 52438f6..a68339b 100644 --- a/internal/cnpgi/operator/lifecycle_resources.go +++ b/internal/cnpgi/operator/lifecycle_resources.go @@ -30,12 +30,11 @@ func (impl LifecycleImplementation) collectSidecarResourcesForPod( configuration *config.PluginConfiguration, ) (corev1.ResourceRequirements, error) { if len(configuration.BarmanObjectName) > 0 { - // On a replica cluster, the designated primary will use both the - // replica source object store and the object store of the cluster. - // The designed primary role can change without the Pod being - // recreated. + // On a replica cluster that also archives, the designated primary + // will use both the replica source object store and the object store + // of the cluster. // In this case, we use the cluster object store for configuring - // the resources created by the sidecar. + // the resources of the sidecar container. var barmanObjectStore barmancloudv1.ObjectStore if err := impl.Client.Get(ctx, configuration.GetBarmanObjectKey(), &barmanObjectStore); err != nil { @@ -45,5 +44,18 @@ func (impl LifecycleImplementation) collectSidecarResourcesForPod( return barmanObjectStore.Spec.InstanceSidecarConfiguration.Resources, nil } + if len(configuration.RecoveryBarmanObjectName) > 0 { + // On a replica cluster that doesn't archive, the designated primary + // uses only the replica source object store. + // In this case, we use the replica source object store for configuring + // the resources of the sidecar container. + var barmanObjectStore barmancloudv1.ObjectStore + if err := impl.Client.Get(ctx, configuration.GetRecoveryBarmanObjectKey(), &barmanObjectStore); err != nil { + return corev1.ResourceRequirements{}, err + } + + return barmanObjectStore.Spec.InstanceSidecarConfiguration.Resources, nil + } + return corev1.ResourceRequirements{}, nil }