Skip to content

Commit a36c5e2

Browse files
committed
hold pgbackrest
1 parent 5ee89d1 commit a36c5e2

File tree

8 files changed

+29
-16
lines changed

8 files changed

+29
-16
lines changed

internal/collector/instance.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/crunchydata/postgres-operator/internal/feature"
1414
"github.com/crunchydata/postgres-operator/internal/initialize"
1515
"github.com/crunchydata/postgres-operator/internal/naming"
16+
"github.com/crunchydata/postgres-operator/internal/shell"
1617
"github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
1718
)
1819

@@ -40,7 +41,8 @@ func AddToPod(
4041
inInstanceConfigMap *corev1.ConfigMap,
4142
outPod *corev1.PodSpec,
4243
volumeMounts []corev1.VolumeMount,
43-
sqlQueryPassword string,
44+
sqlQueryPassword,
45+
dir string,
4446
includeLogrotate bool,
4547
) {
4648
if !(feature.Enabled(ctx, feature.OpenTelemetryLogs) || feature.Enabled(ctx, feature.OpenTelemetryMetrics)) {
@@ -81,7 +83,7 @@ func AddToPod(
8183
Name: naming.ContainerCollector,
8284
Image: config.CollectorContainerImage(spec),
8385
ImagePullPolicy: pullPolicy,
84-
Command: startCommand(includeLogrotate),
86+
Command: startCommand(dir, includeLogrotate),
8587
Env: []corev1.EnvVar{
8688
{
8789
Name: "K8S_POD_NAMESPACE",
@@ -143,7 +145,12 @@ func AddToPod(
143145
}
144146

145147
// startCommand generates the command script used by the collector container
146-
func startCommand(includeLogrotate bool) []string {
148+
func startCommand(dir string, includeLogrotate bool) []string {
149+
var mkdirScript string
150+
if dir != "" {
151+
mkdirScript = `
152+
` + shell.MakeDirectories(0o775, dir, dir+"/receiver")
153+
}
147154
var startScript = `
148155
/otelcol-contrib --config /etc/otel-collector/config.yaml
149156
`
@@ -159,7 +166,7 @@ done
159166
`
160167
}
161168

162-
wrapper := `monitor() {` + startScript + `}; export -f monitor; exec -a "$0" bash -ceu monitor`
169+
wrapper := `monitor() {` + mkdirScript + startScript + `}; export -f monitor; exec -a "$0" bash -ceu monitor`
163170

164171
return []string{"bash", "-ceu", "--", wrapper, "collector"}
165172
}

internal/collector/pgbackrest.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ func NewConfigForPgBackrestRepoHostPod(
4747

4848
// Keep track of what log records and files have been processed.
4949
// Use a subdirectory of the logs directory to stay within the same failure domain.
50-
// TODO(log-rotation): Create this directory during Collector startup.
5150
config.Extensions["file_storage/pgbackrest_logs"] = map[string]any{
5251
"directory": directory + "/receiver",
53-
"create_directory": true,
52+
"create_directory": false,
5453
"fsync": true,
5554
}
5655

internal/collector/postgres.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ func NewConfigForPostgresPod(ctx context.Context,
2323
) *Config {
2424
config := NewConfig(inCluster.Spec.Instrumentation)
2525

26+
// Metrics
2627
EnablePostgresMetrics(ctx, inCluster, config)
2728
EnablePatroniMetrics(ctx, inCluster, config)
28-
EnablePatroniLogging(ctx, inCluster, config)
29+
30+
// Logging
2931
EnablePostgresLogging(ctx, inCluster, config, outParameters)
32+
EnablePatroniLogging(ctx, inCluster, config)
3033

3134
return config
3235
}

internal/controller/postgrescluster/instance.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,8 +1205,9 @@ func (r *Reconciler) reconcileInstance(
12051205

12061206
// TODO: Setting the includeLogrotate argument to false for now. This
12071207
// should be changed when we implement log rotation for postgres
1208+
// TODO: add dir
12081209
collector.AddToPod(ctx, cluster.Spec.Instrumentation, cluster.Spec.ImagePullPolicy, instanceConfigMap, &instance.Spec.Template.Spec,
1209-
[]corev1.VolumeMount{postgres.DataVolumeMount()}, "", false)
1210+
[]corev1.VolumeMount{postgres.DataVolumeMount()}, "", "", false)
12101211
}
12111212

12121213
if err == nil &&
@@ -1217,8 +1218,11 @@ func (r *Reconciler) reconcileInstance(
12171218
r.Client.Get(ctx, client.ObjectKeyFromObject(monitoringUserSecret), monitoringUserSecret))
12181219

12191220
if err == nil {
1221+
// TODO: Setting the includeLogrotate argument to false for now. This
1222+
// should be changed when we implement log rotation for postgres
1223+
// TODO: add dir
12201224
collector.AddToPod(ctx, cluster.Spec.Instrumentation, cluster.Spec.ImagePullPolicy, instanceConfigMap, &instance.Spec.Template.Spec,
1221-
[]corev1.VolumeMount{postgres.DataVolumeMount()}, string(monitoringUserSecret.Data["password"]), false)
1225+
[]corev1.VolumeMount{postgres.DataVolumeMount()}, string(monitoringUserSecret.Data["password"]), "", false)
12221226
}
12231227
}
12241228

internal/controller/postgrescluster/pgbackrest.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -688,18 +688,16 @@ func (r *Reconciler) generateRepoHostIntent(ctx context.Context, postgresCluster
688688

689689
if pgbackrest.RepoHostVolumeDefined(postgresCluster) {
690690
// add the init container to make the pgBackRest repo volume log directory
691-
pgbackrest.MakePGBackrestLogDir(&repo.Spec.Template, postgresCluster)
691+
pgBackRestLogPath := pgbackrest.MakePGBackrestLogDir(&repo.Spec.Template, postgresCluster)
692692

693693
containersToAdd := []string{naming.PGBackRestRepoContainerName}
694694

695695
// If OpenTelemetryLogs is enabled, we want to add the collector to the pod
696696
// and also add the RepoVolumes to the container.
697697
if feature.Enabled(ctx, feature.OpenTelemetryLogs) {
698-
// TODO: Setting the includeLogrotate argument to false for now. This
699-
// should be changed when we implement log rotation for pgbackrest
700698
collector.AddToPod(ctx, postgresCluster.Spec.Instrumentation, postgresCluster.Spec.ImagePullPolicy,
701699
&corev1.ConfigMap{ObjectMeta: naming.PGBackRestConfig(postgresCluster)},
702-
&repo.Spec.Template.Spec, []corev1.VolumeMount{}, "", false)
700+
&repo.Spec.Template.Spec, []corev1.VolumeMount{}, "", pgBackRestLogPath, true)
703701

704702
containersToAdd = append(containersToAdd, naming.ContainerCollector)
705703
}

internal/controller/standalone_pgadmin/statefulset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func statefulset(
132132
}
133133

134134
collector.AddToPod(ctx, pgadmin.Spec.Instrumentation, pgadmin.Spec.ImagePullPolicy,
135-
configmap, &sts.Spec.Template.Spec, volumeMounts, "", false)
135+
configmap, &sts.Spec.Template.Spec, volumeMounts, "", "", false)
136136
}
137137

138138
return sts

internal/pgbackrest/config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func CreatePGBackRestConfigMapIntent(ctx context.Context, postgresCluster *v1bet
160160
// MakePGBackrestLogDir creates the pgBackRest default log path directory used when a
161161
// dedicated repo host is configured.
162162
func MakePGBackrestLogDir(template *corev1.PodTemplateSpec,
163-
cluster *v1beta1.PostgresCluster) {
163+
cluster *v1beta1.PostgresCluster) string {
164164

165165
var pgBackRestLogPath string
166166
for _, repo := range cluster.Spec.Backups.PGBackRest.Repos {
@@ -188,6 +188,8 @@ func MakePGBackrestLogDir(template *corev1.PodTemplateSpec,
188188
}
189189
}
190190
template.Spec.InitContainers = append(template.Spec.InitContainers, container)
191+
192+
return pgBackRestLogPath
191193
}
192194

193195
// RestoreCommand returns the command for performing a pgBackRest restore. In addition to calling

internal/pgbouncer/reconcile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func Pod(
192192

193193
if feature.Enabled(ctx, feature.OpenTelemetryLogs) || feature.Enabled(ctx, feature.OpenTelemetryMetrics) {
194194
collector.AddToPod(ctx, inCluster.Spec.Instrumentation, inCluster.Spec.ImagePullPolicy, inConfigMap,
195-
outPod, []corev1.VolumeMount{configVolumeMount}, string(inSecret.Data["pgbouncer-password"]),
195+
outPod, []corev1.VolumeMount{configVolumeMount}, string(inSecret.Data["pgbouncer-password"]), "",
196196
true)
197197
}
198198
}

0 commit comments

Comments
 (0)