Skip to content

Commit 4752a4d

Browse files
leonardocemnencia
authored andcommitted
feat: get resources from recovery object store
Signed-off-by: Leonardo Cecchi <[email protected]>
1 parent 58a9980 commit 4752a4d

File tree

5 files changed

+84
-16
lines changed

5 files changed

+84
-16
lines changed

hack/examples/minio-store.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ spec:
1111
memory: "64Mi"
1212
cpu: "250m"
1313
limits:
14-
memory: "128Mi"
14+
memory: "512Mi"
1515
cpu: "500m"
1616
configuration:
1717
endpointCA:

internal/cnpgi/operator/lifecycle.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"k8s.io/utils/ptr"
1818
"sigs.k8s.io/controller-runtime/pkg/client"
1919

20-
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
2120
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/metadata"
2221
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/operator/config"
2322
)
@@ -124,7 +123,7 @@ func (impl LifecycleImplementation) reconcileJob(
124123
return nil, err
125124
}
126125

127-
resources, err := impl.collectSidecarResources(ctx, pluginConfiguration)
126+
resources, err := impl.collectSidecarResourcesForRecoveryJob(ctx, pluginConfiguration)
128127
if err != nil {
129128
return nil, err
130129
}
@@ -216,7 +215,7 @@ func (impl LifecycleImplementation) reconcilePod(
216215
return nil, err
217216
}
218217

219-
resources, err := impl.collectSidecarResources(ctx, pluginConfiguration)
218+
resources, err := impl.collectSidecarResourcesForPod(ctx, pluginConfiguration)
220219
if err != nil {
221220
return nil, err
222221
}
@@ -228,18 +227,6 @@ func (impl LifecycleImplementation) reconcilePod(
228227
})
229228
}
230229

231-
func (impl LifecycleImplementation) collectSidecarResources(
232-
ctx context.Context,
233-
configuration *config.PluginConfiguration,
234-
) (corev1.ResourceRequirements, error) {
235-
var barmanObjectStore barmancloudv1.ObjectStore
236-
if err := impl.Client.Get(ctx, configuration.GetBarmanObjectKey(), &barmanObjectStore); err != nil {
237-
return corev1.ResourceRequirements{}, err
238-
}
239-
240-
return barmanObjectStore.Spec.InstanceSidecarConfiguration.Resources, nil
241-
}
242-
243230
func reconcilePod(
244231
ctx context.Context,
245232
cluster *cnpgv1.Cluster,

internal/cnpgi/operator/lifecycle_certificates.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ func (impl LifecycleImplementation) collectAdditionalCertificates(
5252
result = append(result, envs...)
5353
}
5454

55+
if len(pluginConfiguration.ReplicaSourceBarmanObjectName) > 0 &&
56+
pluginConfiguration.ReplicaSourceBarmanObjectName != pluginConfiguration.BarmanObjectName {
57+
envs, err := impl.collectObjectStoreCertificates(
58+
ctx,
59+
types.NamespacedName{
60+
Name: pluginConfiguration.RecoveryBarmanObjectName,
61+
Namespace: namespace,
62+
},
63+
)
64+
if err != nil {
65+
return nil, err
66+
}
67+
result = append(result, envs...)
68+
}
69+
5570
return result, nil
5671
}
5772

internal/cnpgi/operator/lifecycle_envs.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ func (impl LifecycleImplementation) collectAdditionalEnvs(
1717
) ([]corev1.EnvVar, error) {
1818
var result []corev1.EnvVar
1919

20+
// TODO: check if the environment variables are clashing and in
21+
// that case raise an error
22+
2023
if len(pluginConfiguration.BarmanObjectName) > 0 {
2124
envs, err := impl.collectObjectStoreEnvs(
2225
ctx,
@@ -45,6 +48,20 @@ func (impl LifecycleImplementation) collectAdditionalEnvs(
4548
result = append(result, envs...)
4649
}
4750

51+
if len(pluginConfiguration.ReplicaSourceBarmanObjectName) > 0 {
52+
envs, err := impl.collectObjectStoreEnvs(
53+
ctx,
54+
types.NamespacedName{
55+
Name: pluginConfiguration.ReplicaSourceBarmanObjectName,
56+
Namespace: namespace,
57+
},
58+
)
59+
if err != nil {
60+
return nil, err
61+
}
62+
result = append(result, envs...)
63+
}
64+
4865
return result, nil
4966
}
5067

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package operator
2+
3+
import (
4+
"context"
5+
6+
corev1 "k8s.io/api/core/v1"
7+
8+
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
9+
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/operator/config"
10+
)
11+
12+
func (impl LifecycleImplementation) collectSidecarResourcesForRecoveryJob(
13+
ctx context.Context,
14+
configuration *config.PluginConfiguration,
15+
) (corev1.ResourceRequirements, error) {
16+
if len(configuration.RecoveryBarmanObjectName) > 0 {
17+
var barmanObjectStore barmancloudv1.ObjectStore
18+
if err := impl.Client.Get(ctx, configuration.GetRecoveryBarmanObjectKey(), &barmanObjectStore); err != nil {
19+
return corev1.ResourceRequirements{}, err
20+
}
21+
22+
return barmanObjectStore.Spec.InstanceSidecarConfiguration.Resources, nil
23+
}
24+
25+
return corev1.ResourceRequirements{}, nil
26+
}
27+
28+
func (impl LifecycleImplementation) collectSidecarResourcesForPod(
29+
ctx context.Context,
30+
configuration *config.PluginConfiguration,
31+
) (corev1.ResourceRequirements, error) {
32+
if len(configuration.BarmanObjectName) > 0 {
33+
// On a replica cluster, the designated primary will use both the
34+
// replica source object store and the object store of the cluster.
35+
// The designed primary role can change without the Pod being
36+
// recreated.
37+
// In this case, we use the cluster object store for configuring
38+
// the resources created by the sidecar.
39+
40+
var barmanObjectStore barmancloudv1.ObjectStore
41+
if err := impl.Client.Get(ctx, configuration.GetBarmanObjectKey(), &barmanObjectStore); err != nil {
42+
return corev1.ResourceRequirements{}, err
43+
}
44+
45+
return barmanObjectStore.Spec.InstanceSidecarConfiguration.Resources, nil
46+
}
47+
48+
return corev1.ResourceRequirements{}, nil
49+
}

0 commit comments

Comments
 (0)