@@ -823,7 +823,7 @@ func (r *Reconciler) generateBackupJobSpecIntent(ctx context.Context, postgresCl
823
823
}
824
824
} else {
825
825
mkdirCommand := ""
826
- cloudLogPath := r . reconcileCloudLogPath ( ctx , postgresCluster )
826
+ cloudLogPath := getCloudLogPath ( postgresCluster )
827
827
if cloudLogPath != "" {
828
828
mkdirCommand += shell .MakeDirectories (cloudLogPath , cloudLogPath ) + "; "
829
829
}
@@ -892,8 +892,8 @@ func (r *Reconciler) generateBackupJobSpecIntent(ctx context.Context, postgresCl
892
892
pgbackrest .AddConfigToCloudBackupJob (postgresCluster , & jobSpec .Template )
893
893
894
894
// Mount the PVC named in the "pgbackrest-cloud-log-volume" annotation, if any.
895
- if logVolumeName := postgresCluster .Annotations [naming .PGBackRestCloudLogVolume ]; logVolumeName != "" {
896
- util .AddCloudLogVolumeToPod (& jobSpec .Template .Spec , logVolumeName )
895
+ if logVolume := postgresCluster .Annotations [naming .PGBackRestCloudLogVolume ]; logVolume != "" {
896
+ util .AddCloudLogVolumeToPod (& jobSpec .Template .Spec , logVolume )
897
897
}
898
898
}
899
899
@@ -2082,7 +2082,7 @@ func (r *Reconciler) reconcilePGBackRestConfig(ctx context.Context,
2082
2082
repoHostName , configHash , serviceName , serviceNamespace string ,
2083
2083
instanceNames []string ) error {
2084
2084
2085
- cloudLogPath := r . reconcileCloudLogPath ( ctx , postgresCluster )
2085
+ cloudLogPath := getCloudLogPath ( postgresCluster )
2086
2086
2087
2087
backrestConfig , err := pgbackrest .CreatePGBackRestConfigMapIntent (ctx , postgresCluster , repoHostName ,
2088
2088
configHash , serviceName , serviceNamespace , cloudLogPath , instanceNames )
@@ -3338,35 +3338,18 @@ func authorizeBackupRemovalAnnotationPresent(postgresCluster *v1beta1.PostgresCl
3338
3338
return false
3339
3339
}
3340
3340
3341
- // reconcileCloudLogPath is responsible for determining the appropriate log path
3342
- // for pgbackrest in cloud backup jobs.
3343
- func (r * Reconciler ) reconcileCloudLogPath (ctx context.Context ,
3344
- postgresCluster * v1beta1.PostgresCluster ) string {
3345
- // If the user has specified a PVC to use as a log volume for cloud backups via the
3346
- // PGBackRestCloudLogVolume annotation, check for the PVC. If we find it, set the cloud
3347
- // log path. If the user has specified a PVC, but we can't find it, create a warning event.
3348
- // If the user has not set the PGBackRestCloudLogVolume annotation, but has set a log
3349
- // path via the spec, use that.
3350
- // TODO: Make sure this is what we want (i.e. annotation to take precedence over spec)
3341
+ // getCloudLogPath is responsible for determining the appropriate log path for pgbackrest
3342
+ // in cloud backup jobs. If the user has specified a PVC to use as a log volume for cloud
3343
+ // backups via the PGBackRestCloudLogVolume annotation, set the cloud log path accordingly.
3344
+ // If the user has not set the PGBackRestCloudLogVolume annotation, but has set a log path
3345
+ // via the spec, use that.
3346
+ // TODO: Make sure this is what we want (i.e. annotation to take precedence over spec)
3347
+ //
3348
+ // This function assumes that the backups/pgbackrest spec is present in postgresCluster.
3349
+ func getCloudLogPath (postgresCluster * v1beta1.PostgresCluster ) string {
3351
3350
cloudLogPath := ""
3352
- if logVolumeName := postgresCluster .Annotations [naming .PGBackRestCloudLogVolume ]; logVolumeName != "" {
3353
- logVolume := & corev1.PersistentVolumeClaim {
3354
- ObjectMeta : metav1.ObjectMeta {
3355
- Name : logVolumeName ,
3356
- Namespace : postgresCluster .GetNamespace (),
3357
- },
3358
- }
3359
- err := errors .WithStack (r .Client .Get (ctx ,
3360
- client .ObjectKeyFromObject (logVolume ), logVolume ))
3361
- if err != nil {
3362
- // PVC not retrieved, create warning event
3363
- r .Recorder .Event (postgresCluster , corev1 .EventTypeWarning ,
3364
- "PGBackRestCloudLogVolumeNotFound" , err .Error ())
3365
- } else {
3366
- // We successfully found the specified PVC, so we will set the log path
3367
- cloudLogPath = "/volumes/" + logVolumeName
3368
- }
3369
- // TODO: Can we safely assume that backups are enabled?
3351
+ if logVolume := postgresCluster .Annotations [naming .PGBackRestCloudLogVolume ]; logVolume != "" {
3352
+ cloudLogPath = "/volumes/" + logVolume
3370
3353
} else if postgresCluster .Spec .Backups .PGBackRest .Jobs != nil &&
3371
3354
postgresCluster .Spec .Backups .PGBackRest .Jobs .Log != nil &&
3372
3355
postgresCluster .Spec .Backups .PGBackRest .Jobs .Log .Path != "" {
0 commit comments