Skip to content

Commit f2252fb

Browse files
committed
Use int32 for PostgresVersion in Go structs
This aligns the PostgresCluster and PGUpgrade structs. Tidy up some Job YAML, too.
1 parent a6ed570 commit f2252fb

File tree

10 files changed

+80
-67
lines changed

10 files changed

+80
-67
lines changed

config/crd/bases/postgres-operator.crunchydata.com_postgresclusters.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13035,6 +13035,7 @@ spec:
1303513035
postgresVersion:
1303613036
description: The major version of PostgreSQL installed in the PostgreSQL
1303713037
image
13038+
format: int32
1303813039
maximum: 17
1303913040
minimum: 11
1304013041
type: integer
@@ -18812,6 +18813,7 @@ spec:
1881218813
description: |-
1881318814
Stores the current PostgreSQL major version following a successful
1881418815
major PostgreSQL upgrade.
18816+
format: int32
1881518817
type: integer
1881618818
proxy:
1881718819
description: Current state of the PostgreSQL proxy.
@@ -31867,6 +31869,7 @@ spec:
3186731869
postgresVersion:
3186831870
description: The major version of PostgreSQL installed in the PostgreSQL
3186931871
image
31872+
format: int32
3187031873
maximum: 17
3187131874
minimum: 11
3187231875
type: integer
@@ -37612,6 +37615,7 @@ spec:
3761237615
description: |-
3761337616
Stores the current PostgreSQL major version following a successful
3761437617
major PostgreSQL upgrade.
37618+
format: int32
3761537619
type: integer
3761637620
proxy:
3761737621
description: Current state of the PostgreSQL proxy.

internal/collector/postgres.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func NewConfigForPostgresPod(ctx context.Context,
9292
var postgresLogsTransforms json.RawMessage
9393

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

internal/controller/pgupgrade/pgupgrade_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ func (r *PGUpgradeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
440440
// Set the cluster status when we know the upgrade has completed successfully.
441441
// This will serve to help the user see that the upgrade has completed if they
442442
// are only watching the PostgresCluster
443-
patch.Status.PostgresVersion = int(upgrade.Spec.ToPostgresVersion)
443+
patch.Status.PostgresVersion = upgrade.Spec.ToPostgresVersion
444444

445445
// Set the pgBackRest status for bootstrapping
446446
patch.Status.PGBackRest.Repos = []v1beta1.RepoStatus{}

internal/controller/postgrescluster/volumes.go

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package postgrescluster
77
import (
88
"context"
99
"fmt"
10-
"strconv"
1110

1211
"github.com/pkg/errors"
1312
batchv1 "k8s.io/api/batch/v1"
@@ -476,21 +475,20 @@ func (r *Reconciler) reconcileMovePGDataDir(ctx context.Context,
476475
// `patroni.dynamic.json` holds the previous state of the DCS. Since we are
477476
// migrating the volumes, we want to clear out any obsolete configuration info.
478477
script := fmt.Sprintf(`echo "Preparing cluster %s volumes for PGO v5.x"
479-
echo "pgdata_pvc=%s"
480-
echo "Current PG data directory volume contents:"
481-
ls -lh "/pgdata"
482-
echo "Now updating PG data directory..."
483-
[ -d "/pgdata/%s" ] && mv "/pgdata/%s" "/pgdata/pg%s_bootstrap"
484-
rm -f "/pgdata/pg%s/patroni.dynamic.json"
485-
echo "Updated PG data directory contents:"
486-
ls -lh "/pgdata"
487-
echo "PG Data directory preparation complete"
488-
`, cluster.Name,
478+
echo "pgdata_pvc=%s"
479+
echo "Current PG data directory volume contents:"
480+
ls -lh "/pgdata"
481+
echo "Now updating PG data directory..."
482+
[ -d "/pgdata/%s" ] && mv "/pgdata/%s" "/pgdata/pg%d_bootstrap"
483+
rm -f "/pgdata/pg%d/patroni.dynamic.json"
484+
echo "Updated PG data directory contents:"
485+
ls -lh "/pgdata"
486+
echo "PG Data directory preparation complete"`, cluster.Name,
489487
cluster.Spec.DataSource.Volumes.PGDataVolume.PVCName,
490488
cluster.Spec.DataSource.Volumes.PGDataVolume.Directory,
491489
cluster.Spec.DataSource.Volumes.PGDataVolume.Directory,
492-
strconv.Itoa(cluster.Spec.PostgresVersion),
493-
strconv.Itoa(cluster.Spec.PostgresVersion))
490+
cluster.Spec.PostgresVersion,
491+
cluster.Spec.PostgresVersion)
494492

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

598596
script := fmt.Sprintf(`echo "Preparing cluster %s volumes for PGO v5.x"
599-
echo "pg_wal_pvc=%s"
600-
echo "Current PG WAL directory volume contents:"
601-
ls -lh "/pgwal"
602-
echo "Now updating PG WAL directory..."
603-
[ -d "/pgwal/%s" ] && mv "/pgwal/%s" "/pgwal/%s-wal"
604-
echo "Updated PG WAL directory contents:"
605-
ls -lh "/pgwal"
606-
echo "PG WAL directory preparation complete"
607-
`, cluster.Name,
597+
echo "pg_wal_pvc=%s"
598+
echo "Current PG WAL directory volume contents:"
599+
ls -lh "/pgwal"
600+
echo "Now updating PG WAL directory..."
601+
[ -d "/pgwal/%s" ] && mv "/pgwal/%s" "/pgwal/%s-wal"
602+
echo "Updated PG WAL directory contents:"
603+
ls -lh "/pgwal"
604+
echo "PG WAL directory preparation complete"`, cluster.Name,
608605
cluster.Spec.DataSource.Volumes.PGWALVolume.PVCName,
609606
cluster.Spec.DataSource.Volumes.PGWALVolume.Directory,
610607
cluster.Spec.DataSource.Volumes.PGWALVolume.Directory,
@@ -714,18 +711,17 @@ func (r *Reconciler) reconcileMoveRepoDir(ctx context.Context,
714711
moveDirJob.Labels = labels
715712

716713
script := fmt.Sprintf(`echo "Preparing cluster %s pgBackRest repo volume for PGO v5.x"
717-
echo "repo_pvc=%s"
718-
echo "pgbackrest directory:"
719-
ls -lh /pgbackrest
720-
echo "Current pgBackRest repo directory volume contents:"
721-
ls -lh "/pgbackrest/%s"
722-
echo "Now updating repo directory..."
723-
[ -d "/pgbackrest/%s" ] && mv -t "/pgbackrest/" "/pgbackrest/%s/archive"
724-
[ -d "/pgbackrest/%s" ] && mv -t "/pgbackrest/" "/pgbackrest/%s/backup"
725-
echo "Updated /pgbackrest directory contents:"
726-
ls -lh "/pgbackrest"
727-
echo "Repo directory preparation complete"
728-
`, cluster.Name,
714+
echo "repo_pvc=%s"
715+
echo "pgbackrest directory:"
716+
ls -lh /pgbackrest
717+
echo "Current pgBackRest repo directory volume contents:"
718+
ls -lh "/pgbackrest/%s"
719+
echo "Now updating repo directory..."
720+
[ -d "/pgbackrest/%s" ] && mv -t "/pgbackrest/" "/pgbackrest/%s/archive"
721+
[ -d "/pgbackrest/%s" ] && mv -t "/pgbackrest/" "/pgbackrest/%s/backup"
722+
echo "Updated /pgbackrest directory contents:"
723+
ls -lh "/pgbackrest"
724+
echo "Repo directory preparation complete"`, cluster.Name,
729725
cluster.Spec.DataSource.Volumes.PGBackRestVolume.PVCName,
730726
cluster.Spec.DataSource.Volumes.PGBackRestVolume.Directory,
731727
cluster.Spec.DataSource.Volumes.PGBackRestVolume.Directory,

internal/controller/postgrescluster/volumes_test.go

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -754,12 +754,17 @@ containers:
754754
- command:
755755
- bash
756756
- -ceu
757-
- "echo \"Preparing cluster testcluster volumes for PGO v5.x\"\n echo \"pgdata_pvc=testpgdata\"\n
758-
\ echo \"Current PG data directory volume contents:\" \n ls -lh \"/pgdata\"\n
759-
\ echo \"Now updating PG data directory...\"\n [ -d \"/pgdata/testpgdatadir\"
760-
] && mv \"/pgdata/testpgdatadir\" \"/pgdata/pg13_bootstrap\"\n rm -f \"/pgdata/pg13/patroni.dynamic.json\"\n
761-
\ echo \"Updated PG data directory contents:\" \n ls -lh \"/pgdata\"\n echo
762-
\"PG Data directory preparation complete\"\n "
757+
- |-
758+
echo "Preparing cluster testcluster volumes for PGO v5.x"
759+
echo "pgdata_pvc=testpgdata"
760+
echo "Current PG data directory volume contents:"
761+
ls -lh "/pgdata"
762+
echo "Now updating PG data directory..."
763+
[ -d "/pgdata/testpgdatadir" ] && mv "/pgdata/testpgdatadir" "/pgdata/pg13_bootstrap"
764+
rm -f "/pgdata/pg13/patroni.dynamic.json"
765+
echo "Updated PG data directory contents:"
766+
ls -lh "/pgdata"
767+
echo "PG Data directory preparation complete"
763768
image: example.com/crunchy-postgres-ha:test
764769
imagePullPolicy: Always
765770
name: pgdata-move-job
@@ -814,12 +819,16 @@ containers:
814819
- command:
815820
- bash
816821
- -ceu
817-
- "echo \"Preparing cluster testcluster volumes for PGO v5.x\"\n echo \"pg_wal_pvc=testwal\"\n
818-
\ echo \"Current PG WAL directory volume contents:\"\n ls -lh \"/pgwal\"\n
819-
\ echo \"Now updating PG WAL directory...\"\n [ -d \"/pgwal/testwaldir\"
820-
] && mv \"/pgwal/testwaldir\" \"/pgwal/testcluster-wal\"\n echo \"Updated PG
821-
WAL directory contents:\"\n ls -lh \"/pgwal\"\n echo \"PG WAL directory
822-
preparation complete\"\n "
822+
- |-
823+
echo "Preparing cluster testcluster volumes for PGO v5.x"
824+
echo "pg_wal_pvc=testwal"
825+
echo "Current PG WAL directory volume contents:"
826+
ls -lh "/pgwal"
827+
echo "Now updating PG WAL directory..."
828+
[ -d "/pgwal/testwaldir" ] && mv "/pgwal/testwaldir" "/pgwal/testcluster-wal"
829+
echo "Updated PG WAL directory contents:"
830+
ls -lh "/pgwal"
831+
echo "PG WAL directory preparation complete"
823832
image: example.com/crunchy-postgres-ha:test
824833
imagePullPolicy: Always
825834
name: pgwal-move-job
@@ -874,14 +883,19 @@ containers:
874883
- command:
875884
- bash
876885
- -ceu
877-
- "echo \"Preparing cluster testcluster pgBackRest repo volume for PGO v5.x\"\n
878-
\ echo \"repo_pvc=testrepo\"\n echo \"pgbackrest directory:\"\n ls -lh
879-
/pgbackrest\n echo \"Current pgBackRest repo directory volume contents:\" \n
880-
\ ls -lh \"/pgbackrest/testrepodir\"\n echo \"Now updating repo directory...\"\n
881-
\ [ -d \"/pgbackrest/testrepodir\" ] && mv -t \"/pgbackrest/\" \"/pgbackrest/testrepodir/archive\"\n
882-
\ [ -d \"/pgbackrest/testrepodir\" ] && mv -t \"/pgbackrest/\" \"/pgbackrest/testrepodir/backup\"\n
883-
\ echo \"Updated /pgbackrest directory contents:\"\n ls -lh \"/pgbackrest\"\n
884-
\ echo \"Repo directory preparation complete\"\n "
886+
- |-
887+
echo "Preparing cluster testcluster pgBackRest repo volume for PGO v5.x"
888+
echo "repo_pvc=testrepo"
889+
echo "pgbackrest directory:"
890+
ls -lh /pgbackrest
891+
echo "Current pgBackRest repo directory volume contents:"
892+
ls -lh "/pgbackrest/testrepodir"
893+
echo "Now updating repo directory..."
894+
[ -d "/pgbackrest/testrepodir" ] && mv -t "/pgbackrest/" "/pgbackrest/testrepodir/archive"
895+
[ -d "/pgbackrest/testrepodir" ] && mv -t "/pgbackrest/" "/pgbackrest/testrepodir/backup"
896+
echo "Updated /pgbackrest directory contents:"
897+
ls -lh "/pgbackrest"
898+
echo "Repo directory preparation complete"
885899
image: example.com/crunchy-pgbackrest:test
886900
imagePullPolicy: Always
887901
name: repo-move-job

internal/pgbackrest/config.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"context"
99
"fmt"
1010
"path"
11-
"strconv"
1211
"strings"
1312
"time"
1413

@@ -109,7 +108,7 @@ func CreatePGBackRestConfigMapIntent(ctx context.Context, postgresCluster *v1bet
109108
populatePGInstanceConfigurationMap(
110109
serviceName, serviceNamespace, repoHostName, pgdataDir,
111110
config.FetchKeyCommand(&postgresCluster.Spec),
112-
strconv.Itoa(postgresCluster.Spec.PostgresVersion),
111+
fmt.Sprint(postgresCluster.Spec.PostgresVersion),
113112
pgPort, postgresCluster.Spec.Backups.PGBackRest.Repos,
114113
postgresCluster.Spec.Backups.PGBackRest.Global,
115114
util.GetPGBackRestLogPathForInstance(postgresCluster),
@@ -130,7 +129,7 @@ func CreatePGBackRestConfigMapIntent(ctx context.Context, postgresCluster *v1bet
130129
populateRepoHostConfigurationMap(
131130
serviceName, serviceNamespace,
132131
pgdataDir, config.FetchKeyCommand(&postgresCluster.Spec),
133-
strconv.Itoa(postgresCluster.Spec.PostgresVersion),
132+
fmt.Sprint(postgresCluster.Spec.PostgresVersion),
134133
pgPort, instanceNames,
135134
postgresCluster.Spec.Backups.PGBackRest.Repos,
136135
postgresCluster.Spec.Backups.PGBackRest.Global,
@@ -161,7 +160,7 @@ func CreatePGBackRestConfigMapIntent(ctx context.Context, postgresCluster *v1bet
161160
populateCloudRepoConfigurationMap(
162161
serviceName, serviceNamespace, pgdataDir,
163162
config.FetchKeyCommand(&postgresCluster.Spec),
164-
strconv.Itoa(postgresCluster.Spec.PostgresVersion),
163+
fmt.Sprint(postgresCluster.Spec.PostgresVersion),
165164
cloudLogPath, pgPort, instanceNames,
166165
postgresCluster.Spec.Backups.PGBackRest.Repos,
167166
postgresCluster.Spec.Backups.PGBackRest.Global,

internal/postgres/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestDataDirectory(t *testing.T) {
4444

4545
func TestDataStorage(t *testing.T) {
4646
cluster := new(v1beta1.PostgresCluster)
47-
cluster.Spec.PostgresVersion = rand.IntN(20)
47+
cluster.Spec.PostgresVersion = rand.Int32N(20)
4848

4949
assert.Equal(t, DataStorage(cluster), "/pgdata")
5050
}

internal/postgres/versions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var finalReleaseDates = map[int]time.Time{
2020

2121
// ReleaseIsFinal returns whether or not t is definitively past the final
2222
// scheduled release of a Postgres version.
23-
func ReleaseIsFinal(majorVersion int, t time.Time) bool {
24-
known, ok := finalReleaseDates[majorVersion]
23+
func ReleaseIsFinal[N ~int | ~int32](majorVersion N, t time.Time) bool {
24+
known, ok := finalReleaseDates[int(majorVersion)]
2525
return ok && t.After(known)
2626
}

pkg/apis/postgres-operator.crunchydata.com/v1/postgrescluster_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ type PostgresClusterSpec struct {
144144
// +kubebuilder:validation:Minimum=11
145145
// +kubebuilder:validation:Maximum=17
146146
// +operator-sdk:csv:customresourcedefinitions:type=spec,order=1
147-
PostgresVersion int `json:"postgresVersion"`
147+
PostgresVersion int32 `json:"postgresVersion"`
148148

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

396396
// Current state of the PostgreSQL proxy.
397397
// +optional

pkg/apis/postgres-operator.crunchydata.com/v1beta1/postgrescluster_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ type PostgresClusterSpec struct {
129129
// +kubebuilder:validation:Minimum=11
130130
// +kubebuilder:validation:Maximum=17
131131
// +operator-sdk:csv:customresourcedefinitions:type=spec,order=1
132-
PostgresVersion int `json:"postgresVersion"`
132+
PostgresVersion int32 `json:"postgresVersion"`
133133

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

380380
// Current state of the PostgreSQL proxy.
381381
// +optional

0 commit comments

Comments
 (0)