diff --git a/hack/examples/minio-store.yaml b/hack/examples/minio-store.yaml index 6c420d9..6304a92 100644 --- a/hack/examples/minio-store.yaml +++ b/hack/examples/minio-store.yaml @@ -11,7 +11,7 @@ spec: memory: "64Mi" cpu: "250m" limits: - memory: "128Mi" + memory: "512Mi" cpu: "500m" configuration: endpointCA: diff --git a/internal/cnpgi/operator/lifecycle.go b/internal/cnpgi/operator/lifecycle.go index dcfefa2..308c9e7 100644 --- a/internal/cnpgi/operator/lifecycle.go +++ b/internal/cnpgi/operator/lifecycle.go @@ -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, diff --git a/internal/cnpgi/operator/lifecycle_certificates.go b/internal/cnpgi/operator/lifecycle_certificates.go index 800612e..5ff3e0b 100644 --- a/internal/cnpgi/operator/lifecycle_certificates.go +++ b/internal/cnpgi/operator/lifecycle_certificates.go @@ -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 } diff --git a/internal/cnpgi/operator/lifecycle_envs.go b/internal/cnpgi/operator/lifecycle_envs.go index bfb5b22..e51b5c8 100644 --- a/internal/cnpgi/operator/lifecycle_envs.go +++ b/internal/cnpgi/operator/lifecycle_envs.go @@ -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 } diff --git a/internal/cnpgi/operator/lifecycle_resources.go b/internal/cnpgi/operator/lifecycle_resources.go new file mode 100644 index 0000000..52438f6 --- /dev/null +++ b/internal/cnpgi/operator/lifecycle_resources.go @@ -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 +}