feat: get resources from recovery object store

Signed-off-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com>
This commit is contained in:
Leonardo Cecchi 2025-05-06 10:50:54 +02:00 committed by Marco Nenciarini
parent 91e98994d2
commit 293c9e901f
5 changed files with 84 additions and 16 deletions

View File

@ -11,7 +11,7 @@ spec:
memory: "64Mi" memory: "64Mi"
cpu: "250m" cpu: "250m"
limits: limits:
memory: "128Mi" memory: "512Mi"
cpu: "500m" cpu: "500m"
configuration: configuration:
endpointCA: endpointCA:

View File

@ -17,7 +17,6 @@ import (
"k8s.io/utils/ptr" "k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client"
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/metadata" "github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/metadata"
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/operator/config" "github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/operator/config"
) )
@ -124,7 +123,7 @@ func (impl LifecycleImplementation) reconcileJob(
return nil, err return nil, err
} }
resources, err := impl.collectSidecarResources(ctx, pluginConfiguration) resources, err := impl.collectSidecarResourcesForRecoveryJob(ctx, pluginConfiguration)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -216,7 +215,7 @@ func (impl LifecycleImplementation) reconcilePod(
return nil, err return nil, err
} }
resources, err := impl.collectSidecarResources(ctx, pluginConfiguration) resources, err := impl.collectSidecarResourcesForPod(ctx, pluginConfiguration)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -228,18 +227,6 @@ func (impl LifecycleImplementation) reconcilePod(
}) })
} }
func (impl LifecycleImplementation) collectSidecarResources(
ctx context.Context,
configuration *config.PluginConfiguration,
) (corev1.ResourceRequirements, error) {
var barmanObjectStore barmancloudv1.ObjectStore
if err := impl.Client.Get(ctx, configuration.GetBarmanObjectKey(), &barmanObjectStore); err != nil {
return corev1.ResourceRequirements{}, err
}
return barmanObjectStore.Spec.InstanceSidecarConfiguration.Resources, nil
}
func reconcilePod( func reconcilePod(
ctx context.Context, ctx context.Context,
cluster *cnpgv1.Cluster, cluster *cnpgv1.Cluster,

View File

@ -30,6 +30,21 @@ func (impl LifecycleImplementation) collectAdditionalCertificates(
result = append(result, certs...) result = append(result, certs...)
} }
if len(pluginConfiguration.ReplicaSourceBarmanObjectName) > 0 &&
pluginConfiguration.ReplicaSourceBarmanObjectName != pluginConfiguration.BarmanObjectName {
envs, err := impl.collectObjectStoreCertificates(
ctx,
types.NamespacedName{
Name: pluginConfiguration.RecoveryBarmanObjectName,
Namespace: namespace,
},
)
if err != nil {
return nil, err
}
result = append(result, envs...)
}
return result, nil return result, nil
} }

View File

@ -17,6 +17,9 @@ func (impl LifecycleImplementation) collectAdditionalEnvs(
) ([]corev1.EnvVar, error) { ) ([]corev1.EnvVar, error) {
var result []corev1.EnvVar var result []corev1.EnvVar
// TODO: check if the environment variables are clashing and in
// that case raise an error
if len(pluginConfiguration.BarmanObjectName) > 0 { if len(pluginConfiguration.BarmanObjectName) > 0 {
envs, err := impl.collectObjectStoreEnvs( envs, err := impl.collectObjectStoreEnvs(
ctx, ctx,
@ -45,6 +48,20 @@ func (impl LifecycleImplementation) collectAdditionalEnvs(
result = append(result, envs...) result = append(result, envs...)
} }
if len(pluginConfiguration.ReplicaSourceBarmanObjectName) > 0 {
envs, err := impl.collectObjectStoreEnvs(
ctx,
types.NamespacedName{
Name: pluginConfiguration.ReplicaSourceBarmanObjectName,
Namespace: namespace,
},
)
if err != nil {
return nil, err
}
result = append(result, envs...)
}
return result, nil return result, nil
} }

View File

@ -0,0 +1,49 @@
package operator
import (
"context"
corev1 "k8s.io/api/core/v1"
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/operator/config"
)
func (impl LifecycleImplementation) collectSidecarResourcesForRecoveryJob(
ctx context.Context,
configuration *config.PluginConfiguration,
) (corev1.ResourceRequirements, error) {
if len(configuration.RecoveryBarmanObjectName) > 0 {
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
}
func (impl LifecycleImplementation) collectSidecarResourcesForPod(
ctx context.Context,
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.
// In this case, we use the cluster object store for configuring
// the resources created by the sidecar.
var barmanObjectStore barmancloudv1.ObjectStore
if err := impl.Client.Get(ctx, configuration.GetBarmanObjectKey(), &barmanObjectStore); err != nil {
return corev1.ResourceRequirements{}, err
}
return barmanObjectStore.Spec.InstanceSidecarConfiguration.Resources, nil
}
return corev1.ResourceRequirements{}, nil
}