|
8 | 8 | "context"
|
9 | 9 | "fmt"
|
10 | 10 | "io"
|
| 11 | + "path/filepath" |
11 | 12 | "reflect"
|
12 | 13 | "regexp"
|
13 | 14 | "sort"
|
@@ -823,7 +824,7 @@ func (r *Reconciler) generateBackupJobSpecIntent(ctx context.Context, postgresCl
|
823 | 824 | }
|
824 | 825 | } else {
|
825 | 826 | mkdirCommand := ""
|
826 |
| - cloudLogPath := r.reconcileCloudLogPath(ctx, postgresCluster) |
| 827 | + cloudLogPath := getCloudLogPath(postgresCluster) |
827 | 828 | if cloudLogPath != "" {
|
828 | 829 | mkdirCommand += shell.MakeDirectories(cloudLogPath, cloudLogPath) + "; "
|
829 | 830 | }
|
@@ -892,8 +893,8 @@ func (r *Reconciler) generateBackupJobSpecIntent(ctx context.Context, postgresCl
|
892 | 893 | pgbackrest.AddConfigToCloudBackupJob(postgresCluster, &jobSpec.Template)
|
893 | 894 |
|
894 | 895 | // 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) |
| 896 | + if logVolume := postgresCluster.Annotations[naming.PGBackRestCloudLogVolume]; logVolume != "" { |
| 897 | + util.AddCloudLogVolumeToPod(&jobSpec.Template.Spec, logVolume) |
897 | 898 | }
|
898 | 899 | }
|
899 | 900 |
|
@@ -2082,7 +2083,7 @@ func (r *Reconciler) reconcilePGBackRestConfig(ctx context.Context,
|
2082 | 2083 | repoHostName, configHash, serviceName, serviceNamespace string,
|
2083 | 2084 | instanceNames []string) error {
|
2084 | 2085 |
|
2085 |
| - cloudLogPath := r.reconcileCloudLogPath(ctx, postgresCluster) |
| 2086 | + cloudLogPath := getCloudLogPath(postgresCluster) |
2086 | 2087 |
|
2087 | 2088 | backrestConfig, err := pgbackrest.CreatePGBackRestConfigMapIntent(ctx, postgresCluster, repoHostName,
|
2088 | 2089 | configHash, serviceName, serviceNamespace, cloudLogPath, instanceNames)
|
@@ -3338,39 +3339,22 @@ func authorizeBackupRemovalAnnotationPresent(postgresCluster *v1beta1.PostgresCl
|
3338 | 3339 | return false
|
3339 | 3340 | }
|
3340 | 3341 |
|
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) |
| 3342 | +// getCloudLogPath is responsible for determining the appropriate log path for pgbackrest |
| 3343 | +// in cloud backup jobs. If the user has specified a PVC to use as a log volume for cloud |
| 3344 | +// backups via the PGBackRestCloudLogVolume annotation, set the cloud log path accordingly. |
| 3345 | +// If the user has not set the PGBackRestCloudLogVolume annotation, but has set a log path |
| 3346 | +// via the spec, use that. |
| 3347 | +// TODO: Make sure this is what we want (i.e. annotation to take precedence over spec) |
| 3348 | +// |
| 3349 | +// This function assumes that the backups/pgbackrest spec is present in postgresCluster. |
| 3350 | +func getCloudLogPath(postgresCluster *v1beta1.PostgresCluster) string { |
3351 | 3351 | 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? |
| 3352 | + if logVolume := postgresCluster.Annotations[naming.PGBackRestCloudLogVolume]; logVolume != "" { |
| 3353 | + cloudLogPath = "/volumes/" + logVolume |
3370 | 3354 | } else if postgresCluster.Spec.Backups.PGBackRest.Jobs != nil &&
|
3371 | 3355 | postgresCluster.Spec.Backups.PGBackRest.Jobs.Log != nil &&
|
3372 | 3356 | postgresCluster.Spec.Backups.PGBackRest.Jobs.Log.Path != "" {
|
3373 |
| - cloudLogPath = postgresCluster.Spec.Backups.PGBackRest.Jobs.Log.Path |
| 3357 | + cloudLogPath = filepath.Clean(postgresCluster.Spec.Backups.PGBackRest.Jobs.Log.Path) |
3374 | 3358 | }
|
3375 | 3359 | return cloudLogPath
|
3376 | 3360 | }
|
0 commit comments