Skip to content

Commit

Permalink
Make the Backups field a pointer for client.Create
Browse files Browse the repository at this point in the history
  • Loading branch information
cbandy committed Dec 19, 2024
1 parent 612a8b0 commit bd82c08
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 32 deletions.
2 changes: 1 addition & 1 deletion internal/controller/postgrescluster/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{{
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/postgrescluster/pgadmin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/postgrescluster/pgbackrest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
32 changes: 16 additions & 16 deletions internal/controller/postgrescluster/pgbackrest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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"}},
},
Expand Down Expand Up @@ -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"}},
},
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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{}}},
},
Expand Down Expand Up @@ -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{},
},
},
Expand Down Expand Up @@ -2233,7 +2233,7 @@ func TestCopyConfigurationResources(t *testing.T) {
},
},
}},
Backups: v1beta1.Backups{
Backups: &v1beta1.Backups{
PGBackRest: v1beta1.PGBackRestArchive{
Configuration: []corev1.VolumeProjection{{
Secret: &corev1.SecretProjection{
Expand Down Expand Up @@ -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{{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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",
}
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/postgrescluster/volumes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{{
Expand Down Expand Up @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{{
Expand Down
2 changes: 1 addition & 1 deletion internal/pgbackrest/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion internal/pgbackrest/pgbackrest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion internal/pgbackrest/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 0 additions & 5 deletions internal/testing/validation/postgrescluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bd82c08

Please sign in to comment.