mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-01-11 21:23:12 +01:00
feat: get resources from recovery object store
Signed-off-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com>
This commit is contained in:
parent
91e98994d2
commit
293c9e901f
@ -11,7 +11,7 @@ spec:
|
||||
memory: "64Mi"
|
||||
cpu: "250m"
|
||||
limits:
|
||||
memory: "128Mi"
|
||||
memory: "512Mi"
|
||||
cpu: "500m"
|
||||
configuration:
|
||||
endpointCA:
|
||||
|
||||
@ -17,7 +17,6 @@ import (
|
||||
"k8s.io/utils/ptr"
|
||||
"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/operator/config"
|
||||
)
|
||||
@ -124,7 +123,7 @@ func (impl LifecycleImplementation) reconcileJob(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resources, err := impl.collectSidecarResources(ctx, pluginConfiguration)
|
||||
resources, err := impl.collectSidecarResourcesForRecoveryJob(ctx, pluginConfiguration)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -216,7 +215,7 @@ func (impl LifecycleImplementation) reconcilePod(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resources, err := impl.collectSidecarResources(ctx, pluginConfiguration)
|
||||
resources, err := impl.collectSidecarResourcesForPod(ctx, pluginConfiguration)
|
||||
if err != nil {
|
||||
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(
|
||||
ctx context.Context,
|
||||
cluster *cnpgv1.Cluster,
|
||||
|
||||
@ -30,6 +30,21 @@ func (impl LifecycleImplementation) collectAdditionalCertificates(
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@ -17,6 +17,9 @@ func (impl LifecycleImplementation) collectAdditionalEnvs(
|
||||
) ([]corev1.EnvVar, error) {
|
||||
var result []corev1.EnvVar
|
||||
|
||||
// TODO: check if the environment variables are clashing and in
|
||||
// that case raise an error
|
||||
|
||||
if len(pluginConfiguration.BarmanObjectName) > 0 {
|
||||
envs, err := impl.collectObjectStoreEnvs(
|
||||
ctx,
|
||||
@ -45,6 +48,20 @@ func (impl LifecycleImplementation) collectAdditionalEnvs(
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
49
internal/cnpgi/operator/lifecycle_resources.go
Normal file
49
internal/cnpgi/operator/lifecycle_resources.go
Normal 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
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user