@@ -134,21 +134,7 @@ func CreatePGBackRestConfigMapIntent(ctx context.Context, postgresCluster *v1bet
134
134
135
135
if collector .OpenTelemetryLogsOrMetricsEnabled (ctx , postgresCluster ) {
136
136
// Get pgbackrest log path for repo host pod
137
- var pgBackRestLogPath string
138
- for _ , repo := range postgresCluster .Spec .Backups .PGBackRest .Repos {
139
- if repo .Volume != nil {
140
- // If the user has set a log path in the spec, use it.
141
- // Otherwise, default to /pgbackrest/repo#/log
142
- if postgresCluster .Spec .Backups .PGBackRest .RepoHost != nil &&
143
- postgresCluster .Spec .Backups .PGBackRest .RepoHost .Log != nil &&
144
- postgresCluster .Spec .Backups .PGBackRest .RepoHost .Log .Path != "" {
145
- pgBackRestLogPath = postgresCluster .Spec .Backups .PGBackRest .RepoHost .Log .Path
146
- } else {
147
- pgBackRestLogPath = fmt .Sprintf (naming .PGBackRestRepoLogPath , repo .Name )
148
- }
149
- break
150
- }
151
- }
137
+ pgBackRestLogPath := generateRepoHostLogPath (postgresCluster )
152
138
153
139
err = collector .AddToConfigMap (ctx , collector .NewConfigForPgBackrestRepoHostPod (
154
140
ctx ,
@@ -190,21 +176,7 @@ func CreatePGBackRestConfigMapIntent(ctx context.Context, postgresCluster *v1bet
190
176
func MakePGBackrestLogDir (template * corev1.PodTemplateSpec ,
191
177
cluster * v1beta1.PostgresCluster ) string {
192
178
193
- var pgBackRestLogPath string
194
- for _ , repo := range cluster .Spec .Backups .PGBackRest .Repos {
195
- if repo .Volume != nil {
196
- // If the user has set a log path in the spec, use it.
197
- // Otherwise, default to /pgbackrest/repo#/log
198
- if cluster .Spec .Backups .PGBackRest .RepoHost != nil &&
199
- cluster .Spec .Backups .PGBackRest .RepoHost .Log != nil &&
200
- cluster .Spec .Backups .PGBackRest .RepoHost .Log .Path != "" {
201
- pgBackRestLogPath = cluster .Spec .Backups .PGBackRest .RepoHost .Log .Path
202
- } else {
203
- pgBackRestLogPath = fmt .Sprintf (naming .PGBackRestRepoLogPath , repo .Name )
204
- }
205
- break
206
- }
207
- }
179
+ pgBackRestLogPath := generateRepoHostLogPath (cluster )
208
180
209
181
container := corev1.Container {
210
182
// TODO(log-rotation): The second argument here should be the path
@@ -795,3 +767,27 @@ func serverConfig(cluster *v1beta1.PostgresCluster) iniSectionSet {
795
767
"global:server" : server ,
796
768
}
797
769
}
770
+
771
+ // generateRepoHostLogPath takes a postgrescluster and returns the log path that
772
+ // should be used by pgbackrest in the Repo Host Pod based on the repos specified
773
+ // and whether the user has specified a log path.
774
+ //
775
+ // This function assumes that the backups/pgbackrest spec is present in cluster.
776
+ func generateRepoHostLogPath (cluster * v1beta1.PostgresCluster ) string {
777
+ var pgBackRestLogPath string
778
+ for _ , repo := range cluster .Spec .Backups .PGBackRest .Repos {
779
+ if repo .Volume != nil {
780
+ // If the user has set a log path in the spec, use it.
781
+ // Otherwise, default to /pgbackrest/repo#/log
782
+ if cluster .Spec .Backups .PGBackRest .RepoHost != nil &&
783
+ cluster .Spec .Backups .PGBackRest .RepoHost .Log != nil &&
784
+ cluster .Spec .Backups .PGBackRest .RepoHost .Log .Path != "" {
785
+ pgBackRestLogPath = cluster .Spec .Backups .PGBackRest .RepoHost .Log .Path
786
+ } else {
787
+ pgBackRestLogPath = fmt .Sprintf (naming .PGBackRestRepoLogPath , repo .Name )
788
+ }
789
+ break
790
+ }
791
+ }
792
+ return pgBackRestLogPath
793
+ }
0 commit comments