Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13035,6 +13035,7 @@ spec:
postgresVersion:
description: The major version of PostgreSQL installed in the PostgreSQL
image
format: int32
maximum: 17
minimum: 11
type: integer
Expand Down Expand Up @@ -18812,6 +18813,7 @@ spec:
description: |-
Stores the current PostgreSQL major version following a successful
major PostgreSQL upgrade.
format: int32
type: integer
proxy:
description: Current state of the PostgreSQL proxy.
Expand Down Expand Up @@ -31867,6 +31869,7 @@ spec:
postgresVersion:
description: The major version of PostgreSQL installed in the PostgreSQL
image
format: int32
maximum: 17
minimum: 11
type: integer
Expand Down Expand Up @@ -37612,6 +37615,7 @@ spec:
description: |-
Stores the current PostgreSQL major version following a successful
major PostgreSQL upgrade.
format: int32
type: integer
proxy:
description: Current state of the PostgreSQL proxy.
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func NewConfigForPostgresPod(ctx context.Context,
var postgresLogsTransforms json.RawMessage

// postgresCSVNames returns the names of fields in the CSV logs for version.
func postgresCSVNames(version int) string {
func postgresCSVNames(version int32) string {
// JSON is the preferred format, so use those names.
// https://www.postgresql.org/docs/current/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-JSONLOG

Expand Down
2 changes: 1 addition & 1 deletion internal/controller/pgupgrade/pgupgrade_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ func (r *PGUpgradeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
// Set the cluster status when we know the upgrade has completed successfully.
// This will serve to help the user see that the upgrade has completed if they
// are only watching the PostgresCluster
patch.Status.PostgresVersion = int(upgrade.Spec.ToPostgresVersion)
patch.Status.PostgresVersion = upgrade.Spec.ToPostgresVersion

// Set the pgBackRest status for bootstrapping
patch.Status.PGBackRest.Repos = []v1beta1.RepoStatus{}
Expand Down
64 changes: 30 additions & 34 deletions internal/controller/postgrescluster/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package postgrescluster
import (
"context"
"fmt"
"strconv"

"github.com/pkg/errors"
batchv1 "k8s.io/api/batch/v1"
Expand Down Expand Up @@ -476,21 +475,20 @@ func (r *Reconciler) reconcileMovePGDataDir(ctx context.Context,
// `patroni.dynamic.json` holds the previous state of the DCS. Since we are
// migrating the volumes, we want to clear out any obsolete configuration info.
script := fmt.Sprintf(`echo "Preparing cluster %s volumes for PGO v5.x"
echo "pgdata_pvc=%s"
echo "Current PG data directory volume contents:"
ls -lh "/pgdata"
echo "Now updating PG data directory..."
[ -d "/pgdata/%s" ] && mv "/pgdata/%s" "/pgdata/pg%s_bootstrap"
rm -f "/pgdata/pg%s/patroni.dynamic.json"
echo "Updated PG data directory contents:"
ls -lh "/pgdata"
echo "PG Data directory preparation complete"
`, cluster.Name,
echo "pgdata_pvc=%s"
echo "Current PG data directory volume contents:"
ls -lh "/pgdata"
echo "Now updating PG data directory..."
[ -d "/pgdata/%s" ] && mv "/pgdata/%s" "/pgdata/pg%d_bootstrap"
rm -f "/pgdata/pg%d/patroni.dynamic.json"
echo "Updated PG data directory contents:"
ls -lh "/pgdata"
echo "PG Data directory preparation complete"`, cluster.Name,
cluster.Spec.DataSource.Volumes.PGDataVolume.PVCName,
cluster.Spec.DataSource.Volumes.PGDataVolume.Directory,
cluster.Spec.DataSource.Volumes.PGDataVolume.Directory,
strconv.Itoa(cluster.Spec.PostgresVersion),
strconv.Itoa(cluster.Spec.PostgresVersion))
cluster.Spec.PostgresVersion,
cluster.Spec.PostgresVersion)

container := corev1.Container{
Command: []string{"bash", "-ceu", script},
Expand Down Expand Up @@ -596,15 +594,14 @@ func (r *Reconciler) reconcileMoveWALDir(ctx context.Context,
moveDirJob.Labels = labels

script := fmt.Sprintf(`echo "Preparing cluster %s volumes for PGO v5.x"
echo "pg_wal_pvc=%s"
echo "Current PG WAL directory volume contents:"
ls -lh "/pgwal"
echo "Now updating PG WAL directory..."
[ -d "/pgwal/%s" ] && mv "/pgwal/%s" "/pgwal/%s-wal"
echo "Updated PG WAL directory contents:"
ls -lh "/pgwal"
echo "PG WAL directory preparation complete"
`, cluster.Name,
echo "pg_wal_pvc=%s"
echo "Current PG WAL directory volume contents:"
ls -lh "/pgwal"
echo "Now updating PG WAL directory..."
[ -d "/pgwal/%s" ] && mv "/pgwal/%s" "/pgwal/%s-wal"
echo "Updated PG WAL directory contents:"
ls -lh "/pgwal"
echo "PG WAL directory preparation complete"`, cluster.Name,
cluster.Spec.DataSource.Volumes.PGWALVolume.PVCName,
cluster.Spec.DataSource.Volumes.PGWALVolume.Directory,
cluster.Spec.DataSource.Volumes.PGWALVolume.Directory,
Expand Down Expand Up @@ -714,18 +711,17 @@ func (r *Reconciler) reconcileMoveRepoDir(ctx context.Context,
moveDirJob.Labels = labels

script := fmt.Sprintf(`echo "Preparing cluster %s pgBackRest repo volume for PGO v5.x"
echo "repo_pvc=%s"
echo "pgbackrest directory:"
ls -lh /pgbackrest
echo "Current pgBackRest repo directory volume contents:"
ls -lh "/pgbackrest/%s"
echo "Now updating repo directory..."
[ -d "/pgbackrest/%s" ] && mv -t "/pgbackrest/" "/pgbackrest/%s/archive"
[ -d "/pgbackrest/%s" ] && mv -t "/pgbackrest/" "/pgbackrest/%s/backup"
echo "Updated /pgbackrest directory contents:"
ls -lh "/pgbackrest"
echo "Repo directory preparation complete"
`, cluster.Name,
echo "repo_pvc=%s"
echo "pgbackrest directory:"
ls -lh /pgbackrest
echo "Current pgBackRest repo directory volume contents:"
ls -lh "/pgbackrest/%s"
echo "Now updating repo directory..."
[ -d "/pgbackrest/%s" ] && mv -t "/pgbackrest/" "/pgbackrest/%s/archive"
[ -d "/pgbackrest/%s" ] && mv -t "/pgbackrest/" "/pgbackrest/%s/backup"
echo "Updated /pgbackrest directory contents:"
ls -lh "/pgbackrest"
echo "Repo directory preparation complete"`, cluster.Name,
cluster.Spec.DataSource.Volumes.PGBackRestVolume.PVCName,
cluster.Spec.DataSource.Volumes.PGBackRestVolume.Directory,
cluster.Spec.DataSource.Volumes.PGBackRestVolume.Directory,
Expand Down
54 changes: 34 additions & 20 deletions internal/controller/postgrescluster/volumes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,12 +754,17 @@ containers:
- command:
- bash
- -ceu
- "echo \"Preparing cluster testcluster volumes for PGO v5.x\"\n echo \"pgdata_pvc=testpgdata\"\n
\ echo \"Current PG data directory volume contents:\" \n ls -lh \"/pgdata\"\n
\ echo \"Now updating PG data directory...\"\n [ -d \"/pgdata/testpgdatadir\"
] && mv \"/pgdata/testpgdatadir\" \"/pgdata/pg13_bootstrap\"\n rm -f \"/pgdata/pg13/patroni.dynamic.json\"\n
\ echo \"Updated PG data directory contents:\" \n ls -lh \"/pgdata\"\n echo
\"PG Data directory preparation complete\"\n "
- |-
echo "Preparing cluster testcluster volumes for PGO v5.x"
echo "pgdata_pvc=testpgdata"
echo "Current PG data directory volume contents:"
ls -lh "/pgdata"
echo "Now updating PG data directory..."
[ -d "/pgdata/testpgdatadir" ] && mv "/pgdata/testpgdatadir" "/pgdata/pg13_bootstrap"
rm -f "/pgdata/pg13/patroni.dynamic.json"
echo "Updated PG data directory contents:"
ls -lh "/pgdata"
echo "PG Data directory preparation complete"
image: example.com/crunchy-postgres-ha:test
imagePullPolicy: Always
name: pgdata-move-job
Expand Down Expand Up @@ -814,12 +819,16 @@ containers:
- command:
- bash
- -ceu
- "echo \"Preparing cluster testcluster volumes for PGO v5.x\"\n echo \"pg_wal_pvc=testwal\"\n
\ echo \"Current PG WAL directory volume contents:\"\n ls -lh \"/pgwal\"\n
\ echo \"Now updating PG WAL directory...\"\n [ -d \"/pgwal/testwaldir\"
] && mv \"/pgwal/testwaldir\" \"/pgwal/testcluster-wal\"\n echo \"Updated PG
WAL directory contents:\"\n ls -lh \"/pgwal\"\n echo \"PG WAL directory
preparation complete\"\n "
- |-
echo "Preparing cluster testcluster volumes for PGO v5.x"
echo "pg_wal_pvc=testwal"
echo "Current PG WAL directory volume contents:"
ls -lh "/pgwal"
echo "Now updating PG WAL directory..."
[ -d "/pgwal/testwaldir" ] && mv "/pgwal/testwaldir" "/pgwal/testcluster-wal"
echo "Updated PG WAL directory contents:"
ls -lh "/pgwal"
echo "PG WAL directory preparation complete"
image: example.com/crunchy-postgres-ha:test
imagePullPolicy: Always
name: pgwal-move-job
Expand Down Expand Up @@ -874,14 +883,19 @@ containers:
- command:
- bash
- -ceu
- "echo \"Preparing cluster testcluster pgBackRest repo volume for PGO v5.x\"\n
\ echo \"repo_pvc=testrepo\"\n echo \"pgbackrest directory:\"\n ls -lh
/pgbackrest\n echo \"Current pgBackRest repo directory volume contents:\" \n
\ ls -lh \"/pgbackrest/testrepodir\"\n echo \"Now updating repo directory...\"\n
\ [ -d \"/pgbackrest/testrepodir\" ] && mv -t \"/pgbackrest/\" \"/pgbackrest/testrepodir/archive\"\n
\ [ -d \"/pgbackrest/testrepodir\" ] && mv -t \"/pgbackrest/\" \"/pgbackrest/testrepodir/backup\"\n
\ echo \"Updated /pgbackrest directory contents:\"\n ls -lh \"/pgbackrest\"\n
\ echo \"Repo directory preparation complete\"\n "
- |-
echo "Preparing cluster testcluster pgBackRest repo volume for PGO v5.x"
echo "repo_pvc=testrepo"
echo "pgbackrest directory:"
ls -lh /pgbackrest
echo "Current pgBackRest repo directory volume contents:"
ls -lh "/pgbackrest/testrepodir"
echo "Now updating repo directory..."
[ -d "/pgbackrest/testrepodir" ] && mv -t "/pgbackrest/" "/pgbackrest/testrepodir/archive"
[ -d "/pgbackrest/testrepodir" ] && mv -t "/pgbackrest/" "/pgbackrest/testrepodir/backup"
echo "Updated /pgbackrest directory contents:"
ls -lh "/pgbackrest"
echo "Repo directory preparation complete"
image: example.com/crunchy-pgbackrest:test
imagePullPolicy: Always
name: repo-move-job
Expand Down
7 changes: 3 additions & 4 deletions internal/pgbackrest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"context"
"fmt"
"path"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -109,7 +108,7 @@ func CreatePGBackRestConfigMapIntent(ctx context.Context, postgresCluster *v1bet
populatePGInstanceConfigurationMap(
serviceName, serviceNamespace, repoHostName, pgdataDir,
config.FetchKeyCommand(&postgresCluster.Spec),
strconv.Itoa(postgresCluster.Spec.PostgresVersion),
fmt.Sprint(postgresCluster.Spec.PostgresVersion),
pgPort, postgresCluster.Spec.Backups.PGBackRest.Repos,
postgresCluster.Spec.Backups.PGBackRest.Global,
util.GetPGBackRestLogPathForInstance(postgresCluster),
Expand All @@ -130,7 +129,7 @@ func CreatePGBackRestConfigMapIntent(ctx context.Context, postgresCluster *v1bet
populateRepoHostConfigurationMap(
serviceName, serviceNamespace,
pgdataDir, config.FetchKeyCommand(&postgresCluster.Spec),
strconv.Itoa(postgresCluster.Spec.PostgresVersion),
fmt.Sprint(postgresCluster.Spec.PostgresVersion),
pgPort, instanceNames,
postgresCluster.Spec.Backups.PGBackRest.Repos,
postgresCluster.Spec.Backups.PGBackRest.Global,
Expand Down Expand Up @@ -161,7 +160,7 @@ func CreatePGBackRestConfigMapIntent(ctx context.Context, postgresCluster *v1bet
populateCloudRepoConfigurationMap(
serviceName, serviceNamespace, pgdataDir,
config.FetchKeyCommand(&postgresCluster.Spec),
strconv.Itoa(postgresCluster.Spec.PostgresVersion),
fmt.Sprint(postgresCluster.Spec.PostgresVersion),
cloudLogPath, pgPort, instanceNames,
postgresCluster.Spec.Backups.PGBackRest.Repos,
postgresCluster.Spec.Backups.PGBackRest.Global,
Expand Down
2 changes: 1 addition & 1 deletion internal/postgres/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestDataDirectory(t *testing.T) {

func TestDataStorage(t *testing.T) {
cluster := new(v1beta1.PostgresCluster)
cluster.Spec.PostgresVersion = rand.IntN(20)
cluster.Spec.PostgresVersion = rand.Int32N(20)

assert.Equal(t, DataStorage(cluster), "/pgdata")
}
Expand Down
4 changes: 2 additions & 2 deletions internal/postgres/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var finalReleaseDates = map[int]time.Time{

// ReleaseIsFinal returns whether or not t is definitively past the final
// scheduled release of a Postgres version.
func ReleaseIsFinal(majorVersion int, t time.Time) bool {
known, ok := finalReleaseDates[majorVersion]
func ReleaseIsFinal[N ~int | ~int32](majorVersion N, t time.Time) bool {
known, ok := finalReleaseDates[int(majorVersion)]
return ok && t.After(known)
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ type PostgresClusterSpec struct {
// +kubebuilder:validation:Minimum=11
// +kubebuilder:validation:Maximum=17
// +operator-sdk:csv:customresourcedefinitions:type=spec,order=1
PostgresVersion int `json:"postgresVersion"`
PostgresVersion int32 `json:"postgresVersion"`

// The PostGIS extension version installed in the PostgreSQL image.
// When image is not set, indicates a PostGIS enabled image will be used.
Expand Down Expand Up @@ -391,7 +391,7 @@ type PostgresClusterStatus struct {
// Stores the current PostgreSQL major version following a successful
// major PostgreSQL upgrade.
// +optional
PostgresVersion int `json:"postgresVersion"`
PostgresVersion int32 `json:"postgresVersion"`

// Current state of the PostgreSQL proxy.
// +optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ type PostgresClusterSpec struct {
// +kubebuilder:validation:Minimum=11
// +kubebuilder:validation:Maximum=17
// +operator-sdk:csv:customresourcedefinitions:type=spec,order=1
PostgresVersion int `json:"postgresVersion"`
PostgresVersion int32 `json:"postgresVersion"`

// The PostGIS extension version installed in the PostgreSQL image.
// When image is not set, indicates a PostGIS enabled image will be used.
Expand Down Expand Up @@ -375,7 +375,7 @@ type PostgresClusterStatus struct {
// Stores the current PostgreSQL major version following a successful
// major PostgreSQL upgrade.
// +optional
PostgresVersion int `json:"postgresVersion"`
PostgresVersion int32 `json:"postgresVersion"`

// Current state of the PostgreSQL proxy.
// +optional
Expand Down
Loading