From bd82c08024a67c60f2a46d9ce9b6d0a8417ecbe9 Mon Sep 17 00:00:00 2001 From: Chris Bandy Date: Thu, 19 Dec 2024 13:59:35 -0600 Subject: [PATCH] Make the Backups field a pointer for client.Create --- .../postgrescluster/helpers_test.go | 2 +- .../postgrescluster/pgadmin_test.go | 2 +- .../controller/postgrescluster/pgbackrest.go | 2 +- .../postgrescluster/pgbackrest_test.go | 32 +++++++++---------- .../postgrescluster/volumes_test.go | 4 +-- .../standalone_pgadmin/helpers_unit_test.go | 2 +- internal/pgbackrest/config_test.go | 2 +- internal/pgbackrest/pgbackrest_test.go | 2 +- internal/pgbackrest/util_test.go | 2 +- .../validation/postgrescluster_test.go | 5 --- .../v1beta1/postgrescluster_types.go | 2 +- .../v1beta1/zz_generated.deepcopy.go | 6 +++- 12 files changed, 31 insertions(+), 32 deletions(-) diff --git a/internal/controller/postgrescluster/helpers_test.go b/internal/controller/postgrescluster/helpers_test.go index 0536b466d..a5b90ef2f 100644 --- a/internal/controller/postgrescluster/helpers_test.go +++ b/internal/controller/postgrescluster/helpers_test.go @@ -120,7 +120,7 @@ func testCluster() *v1beta1.PostgresCluster { Replicas: initialize.Int32(1), DataVolumeClaimSpec: testVolumeClaimSpec(), }}, - Backups: v1beta1.Backups{ + Backups: &v1beta1.Backups{ PGBackRest: v1beta1.PGBackRestArchive{ Image: CrunchyPGBackRestImage, Repos: []v1beta1.PGBackRestRepo{{ diff --git a/internal/controller/postgrescluster/pgadmin_test.go b/internal/controller/postgrescluster/pgadmin_test.go index d173ac8ed..9ad3f509d 100644 --- a/internal/controller/postgrescluster/pgadmin_test.go +++ b/internal/controller/postgrescluster/pgadmin_test.go @@ -848,7 +848,7 @@ func pgAdminTestCluster(ns corev1.Namespace) *v1beta1.PostgresCluster { InstanceSets: []v1beta1.PostgresInstanceSetSpec{{ DataVolumeClaimSpec: testVolumeClaimSpec(), }}, - Backups: v1beta1.Backups{ + Backups: &v1beta1.Backups{ PGBackRest: v1beta1.PGBackRestArchive{ Repos: []v1beta1.PGBackRestRepo{{ Name: "repo1", diff --git a/internal/controller/postgrescluster/pgbackrest.go b/internal/controller/postgrescluster/pgbackrest.go index 95f3cf643..4dbc40eed 100644 --- a/internal/controller/postgrescluster/pgbackrest.go +++ b/internal/controller/postgrescluster/pgbackrest.go @@ -3062,7 +3062,7 @@ func (r *Reconciler) ObserveBackupUniverse(ctx context.Context, ) { // Does the cluster have a blank Backups section - backupsSpecFound = !reflect.DeepEqual(postgresCluster.Spec.Backups, v1beta1.Backups{PGBackRest: v1beta1.PGBackRestArchive{}}) + backupsSpecFound = !reflect.DeepEqual(postgresCluster.Spec.Backups, &v1beta1.Backups{PGBackRest: v1beta1.PGBackRestArchive{}}) // Does the repo-host StatefulSet exist? name := fmt.Sprintf("%s-%s", postgresCluster.GetName(), "repo-host") diff --git a/internal/controller/postgrescluster/pgbackrest_test.go b/internal/controller/postgrescluster/pgbackrest_test.go index b7855f173..e6a9af55a 100644 --- a/internal/controller/postgrescluster/pgbackrest_test.go +++ b/internal/controller/postgrescluster/pgbackrest_test.go @@ -73,7 +73,7 @@ func fakePostgresCluster(clusterName, namespace, clusterUID string, }, }, }}, - Backups: v1beta1.Backups{ + Backups: &v1beta1.Backups{ PGBackRest: v1beta1.PGBackRestArchive{ Image: "example.com/crunchy-pgbackrest:test", Jobs: &v1beta1.BackupJobs{ @@ -597,7 +597,7 @@ topologySpreadConstraints: ns := setupNamespace(t, tClient) // create a PostgresCluster without backups to test with postgresCluster := fakePostgresCluster(clusterName, ns.GetName(), clusterUID, true) - postgresCluster.Spec.Backups = v1beta1.Backups{} + postgresCluster.Spec.Backups = &v1beta1.Backups{} // create the 'observed' instances and set the leader instances := &observedInstances{ @@ -1489,7 +1489,7 @@ func TestGetPGBackRestResources(t *testing.T) { UID: types.UID(clusterUID), }, Spec: v1beta1.PostgresClusterSpec{ - Backups: v1beta1.Backups{ + Backups: &v1beta1.Backups{ PGBackRest: v1beta1.PGBackRestArchive{ Repos: []v1beta1.PGBackRestRepo{{Name: "repo1"}}, }, @@ -1526,7 +1526,7 @@ func TestGetPGBackRestResources(t *testing.T) { UID: types.UID(clusterUID), }, Spec: v1beta1.PostgresClusterSpec{ - Backups: v1beta1.Backups{ + Backups: &v1beta1.Backups{ PGBackRest: v1beta1.PGBackRestArchive{ Repos: []v1beta1.PGBackRestRepo{{Name: "repo4"}}, }, @@ -1562,7 +1562,7 @@ func TestGetPGBackRestResources(t *testing.T) { UID: types.UID(clusterUID), }, Spec: v1beta1.PostgresClusterSpec{ - Backups: v1beta1.Backups{ + Backups: &v1beta1.Backups{ PGBackRest: v1beta1.PGBackRestArchive{ Repos: []v1beta1.PGBackRestRepo{{ Name: "repo1", @@ -1601,7 +1601,7 @@ func TestGetPGBackRestResources(t *testing.T) { UID: types.UID(clusterUID), }, Spec: v1beta1.PostgresClusterSpec{ - Backups: v1beta1.Backups{ + Backups: &v1beta1.Backups{ PGBackRest: v1beta1.PGBackRestArchive{ Repos: []v1beta1.PGBackRestRepo{{ Name: "repo4", @@ -1642,7 +1642,7 @@ func TestGetPGBackRestResources(t *testing.T) { UID: types.UID(clusterUID), }, Spec: v1beta1.PostgresClusterSpec{ - Backups: v1beta1.Backups{ + Backups: &v1beta1.Backups{ PGBackRest: v1beta1.PGBackRestArchive{ Repos: []v1beta1.PGBackRestRepo{{Volume: &v1beta1.RepoPVC{}}}, }, @@ -1680,7 +1680,7 @@ func TestGetPGBackRestResources(t *testing.T) { UID: types.UID(clusterUID), }, Spec: v1beta1.PostgresClusterSpec{ - Backups: v1beta1.Backups{ + Backups: &v1beta1.Backups{ PGBackRest: v1beta1.PGBackRestArchive{}, }, }, @@ -2233,7 +2233,7 @@ func TestCopyConfigurationResources(t *testing.T) { }, }, }}, - Backups: v1beta1.Backups{ + Backups: &v1beta1.Backups{ PGBackRest: v1beta1.PGBackRestArchive{ Configuration: []corev1.VolumeProjection{{ Secret: &corev1.SecretProjection{ @@ -2285,7 +2285,7 @@ func TestCopyConfigurationResources(t *testing.T) { }, }, }}, - Backups: v1beta1.Backups{ + Backups: &v1beta1.Backups{ PGBackRest: v1beta1.PGBackRestArchive{ Image: "example.com/crunchy-pgbackrest:test", Repos: []v1beta1.PGBackRestRepo{{ @@ -2518,7 +2518,7 @@ volumes: cluster := &v1beta1.PostgresCluster{} t.Run("Resources not defined in jobs", func(t *testing.T) { - cluster.Spec.Backups = v1beta1.Backups{ + cluster.Spec.Backups = &v1beta1.Backups{ PGBackRest: v1beta1.PGBackRestArchive{}, } job := generateBackupJobSpecIntent(ctx, @@ -2568,7 +2568,7 @@ volumes: cluster := &v1beta1.PostgresCluster{ Spec: v1beta1.PostgresClusterSpec{ - Backups: v1beta1.Backups{ + Backups: &v1beta1.Backups{ PGBackRest: v1beta1.PGBackRestArchive{ Jobs: &v1beta1.BackupJobs{ Affinity: affinity, @@ -2775,7 +2775,7 @@ func TestGenerateRestoreJobIntent(t *testing.T) { Labels: map[string]string{"Global": "test"}, Annotations: map[string]string{"Global": "test"}, }, - Backups: v1beta1.Backups{PGBackRest: v1beta1.PGBackRestArchive{ + Backups: &v1beta1.Backups{PGBackRest: v1beta1.PGBackRestArchive{ Metadata: &v1beta1.Metadata{ Labels: map[string]string{"Backrest": "test"}, Annotations: map[string]string{"Backrest": "test"}, @@ -3786,7 +3786,7 @@ func TestBackupsEnabled(t *testing.T) { ns := setupNamespace(t, tClient) postgresCluster := fakePostgresCluster(clusterName, ns.GetName(), clusterUID, true) - postgresCluster.Spec.Backups = v1beta1.Backups{} + postgresCluster.Spec.Backups = &v1beta1.Backups{} backupsSpecFound, backupsReconciliationAllowed, err := r.BackupsEnabled(ctx, postgresCluster) @@ -3822,7 +3822,7 @@ func TestBackupsEnabled(t *testing.T) { _, err = r.reconcilePGBackRest(ctx, postgresCluster, instances, rootCA, true) assert.NilError(t, err) - postgresCluster.Spec.Backups = v1beta1.Backups{} + postgresCluster.Spec.Backups = &v1beta1.Backups{} backupsSpecFound, backupsReconciliationAllowed, err := r.BackupsEnabled(ctx, postgresCluster) @@ -3858,7 +3858,7 @@ func TestBackupsEnabled(t *testing.T) { _, err = r.reconcilePGBackRest(ctx, postgresCluster, instances, rootCA, true) assert.NilError(t, err) - postgresCluster.Spec.Backups = v1beta1.Backups{} + postgresCluster.Spec.Backups = &v1beta1.Backups{} annotations := map[string]string{ naming.AuthorizeBackupRemovalAnnotation: "true", } diff --git a/internal/controller/postgrescluster/volumes_test.go b/internal/controller/postgrescluster/volumes_test.go index b4156072b..09cc23c9f 100644 --- a/internal/controller/postgrescluster/volumes_test.go +++ b/internal/controller/postgrescluster/volumes_test.go @@ -401,7 +401,7 @@ func TestReconcileConfigureExistingPVCs(t *testing.T) { }, }, }}, - Backups: v1beta1.Backups{ + Backups: &v1beta1.Backups{ PGBackRest: v1beta1.PGBackRestArchive{ Image: "example.com/crunchy-pgbackrest:test", Repos: []v1beta1.PGBackRestRepo{{ @@ -684,7 +684,7 @@ func TestReconcileMoveDirectories(t *testing.T) { }, }, }}, - Backups: v1beta1.Backups{ + Backups: &v1beta1.Backups{ PGBackRest: v1beta1.PGBackRestArchive{ Image: "example.com/crunchy-pgbackrest:test", RepoHost: &v1beta1.PGBackRestRepoHost{ diff --git a/internal/controller/standalone_pgadmin/helpers_unit_test.go b/internal/controller/standalone_pgadmin/helpers_unit_test.go index 63887385f..3009e3b7a 100644 --- a/internal/controller/standalone_pgadmin/helpers_unit_test.go +++ b/internal/controller/standalone_pgadmin/helpers_unit_test.go @@ -42,7 +42,7 @@ func testCluster() *v1beta1.PostgresCluster { Replicas: initialize.Int32(1), DataVolumeClaimSpec: testVolumeClaimSpec(), }}, - Backups: v1beta1.Backups{ + Backups: &v1beta1.Backups{ PGBackRest: v1beta1.PGBackRestArchive{ Image: CrunchyPGBackRestImage, Repos: []v1beta1.PGBackRestRepo{{ diff --git a/internal/pgbackrest/config_test.go b/internal/pgbackrest/config_test.go index f648ea3b8..8350d6131 100644 --- a/internal/pgbackrest/config_test.go +++ b/internal/pgbackrest/config_test.go @@ -262,7 +262,7 @@ func TestMakePGBackrestLogDir(t *testing.T) { cluster := &v1beta1.PostgresCluster{ Spec: v1beta1.PostgresClusterSpec{ ImagePullPolicy: corev1.PullAlways, - Backups: v1beta1.Backups{ + Backups: &v1beta1.Backups{ PGBackRest: v1beta1.PGBackRestArchive{ Image: "test-image", Repos: []v1beta1.PGBackRestRepo{ diff --git a/internal/pgbackrest/pgbackrest_test.go b/internal/pgbackrest/pgbackrest_test.go index 33c97913c..ec6b616b5 100644 --- a/internal/pgbackrest/pgbackrest_test.go +++ b/internal/pgbackrest/pgbackrest_test.go @@ -56,7 +56,7 @@ fi } postgresCluster := &v1beta1.PostgresCluster{ Spec: v1beta1.PostgresClusterSpec{ - Backups: v1beta1.Backups{ + Backups: &v1beta1.Backups{ PGBackRest: v1beta1.PGBackRestArchive{ Repos: []v1beta1.PGBackRestRepo{{ Name: "repo1", diff --git a/internal/pgbackrest/util_test.go b/internal/pgbackrest/util_test.go index eb0f4dec2..f4d394fb1 100644 --- a/internal/pgbackrest/util_test.go +++ b/internal/pgbackrest/util_test.go @@ -47,7 +47,7 @@ func TestCalculateConfigHashes(t *testing.T) { Namespace: "calculate-config-hashes", }, Spec: v1beta1.PostgresClusterSpec{ - Backups: v1beta1.Backups{ + Backups: &v1beta1.Backups{ PGBackRest: v1beta1.PGBackRestArchive{ Repos: []v1beta1.PGBackRestRepo{{ Name: "repo1", diff --git a/internal/testing/validation/postgrescluster_test.go b/internal/testing/validation/postgrescluster_test.go index e71ff22b2..7829ad400 100644 --- a/internal/testing/validation/postgrescluster_test.go +++ b/internal/testing/validation/postgrescluster_test.go @@ -30,11 +30,6 @@ func TestPostgresUserOptions(t *testing.T) { // Start with a bunch of required fields. assert.NilError(t, yaml.Unmarshal([]byte(`{ postgresVersion: 16, - backups: { - pgbackrest: { - repos: [{ name: repo1 }], - }, - }, instances: [{ dataVolumeClaimSpec: { accessModes: [ReadWriteOnce], diff --git a/pkg/apis/postgres-operator.crunchydata.com/v1beta1/postgrescluster_types.go b/pkg/apis/postgres-operator.crunchydata.com/v1beta1/postgrescluster_types.go index 54e42baa3..e74fbbafc 100644 --- a/pkg/apis/postgres-operator.crunchydata.com/v1beta1/postgrescluster_types.go +++ b/pkg/apis/postgres-operator.crunchydata.com/v1beta1/postgrescluster_types.go @@ -23,7 +23,7 @@ type PostgresClusterSpec struct { // PostgreSQL backup configuration // +optional - Backups Backups `json:"backups,omitempty"` + Backups *Backups `json:"backups,omitempty"` // The secret containing the Certificates and Keys to encrypt PostgreSQL // traffic will need to contain the server TLS certificate, TLS key and the diff --git a/pkg/apis/postgres-operator.crunchydata.com/v1beta1/zz_generated.deepcopy.go b/pkg/apis/postgres-operator.crunchydata.com/v1beta1/zz_generated.deepcopy.go index e8d8826c2..9e6c7b4f8 100644 --- a/pkg/apis/postgres-operator.crunchydata.com/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/postgres-operator.crunchydata.com/v1beta1/zz_generated.deepcopy.go @@ -1690,7 +1690,11 @@ func (in *PostgresClusterSpec) DeepCopyInto(out *PostgresClusterSpec) { *out = new(DataSource) (*in).DeepCopyInto(*out) } - in.Backups.DeepCopyInto(&out.Backups) + if in.Backups != nil { + in, out := &in.Backups, &out.Backups + *out = new(Backups) + (*in).DeepCopyInto(*out) + } if in.CustomTLSSecret != nil { in, out := &in.CustomTLSSecret, &out.CustomTLSSecret *out = new(corev1.SecretProjection)