From 8a248d5a146028a7be98b07de670437cf2495d1e Mon Sep 17 00:00:00 2001
From: vbeaucha <vbeaucha77@gmail.com>
Date: Tue, 17 Jun 2025 11:01:06 +0200
Subject: [PATCH] Include logrotate on collector if local volumes are setup

---
 internal/controller/postgrescluster/instance.go | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/internal/controller/postgrescluster/instance.go b/internal/controller/postgrescluster/instance.go
index e24c0aca7b..eed6b7f538 100644
--- a/internal/controller/postgrescluster/instance.go
+++ b/internal/controller/postgrescluster/instance.go
@@ -1220,10 +1220,12 @@ func (r *Reconciler) reconcileInstance(
 
 		// For now, we are not using logrotate to rotate postgres or patroni logs,
 		// but we are using it for pgbackrest logs in the postgres pod, so we will
-		// set includeLogrotate to true, but only if backups are enabled.
+		// set includeLogrotate to true, but only if backups are enabled
+		// and local volumes are available.
+		includeLogrotate := backupsSpecFound && pgbackrest.RepoHostVolumeDefined(cluster)
 		collector.AddToPod(ctx, cluster.Spec.Instrumentation, cluster.Spec.ImagePullPolicy, instanceConfigMap, &instance.Spec.Template,
 			[]corev1.VolumeMount{postgres.DataVolumeMount()}, pgPassword,
-			[]string{naming.PGBackRestPGDataLogPath}, backupsSpecFound, true)
+			[]string{naming.PGBackRestPGDataLogPath}, includeLogrotate, true)
 	}
 
 	// Add postgres-exporter to the instance Pod spec