diff --git a/build/crd/percona/generated/pgv2.percona.com_perconapgclusters.yaml b/build/crd/percona/generated/pgv2.percona.com_perconapgclusters.yaml index 226cb7b95..d600b02bb 100644 --- a/build/crd/percona/generated/pgv2.percona.com_perconapgclusters.yaml +++ b/build/crd/percona/generated/pgv2.percona.com_perconapgclusters.yaml @@ -121,6 +121,9 @@ spec: description: PostgreSQL backup configuration properties: enabled: + description: |- + Enabled controls whether backups are enabled for the cluster. + Defaulted to true by the operator for crVersion >= 3.1.0. type: boolean pgbackrest: description: pgBackRest archive configuration diff --git a/config/crd/bases/pgv2.percona.com_perconapgclusters.yaml b/config/crd/bases/pgv2.percona.com_perconapgclusters.yaml index 8bf33616d..2ff064e99 100644 --- a/config/crd/bases/pgv2.percona.com_perconapgclusters.yaml +++ b/config/crd/bases/pgv2.percona.com_perconapgclusters.yaml @@ -819,6 +819,9 @@ spec: description: PostgreSQL backup configuration properties: enabled: + description: |- + Enabled controls whether backups are enabled for the cluster. + Defaulted to true by the operator for crVersion >= 3.1.0. type: boolean pgbackrest: description: pgBackRest archive configuration diff --git a/deploy/bundle.yaml b/deploy/bundle.yaml index 0eddf1619..fff58aecb 100644 --- a/deploy/bundle.yaml +++ b/deploy/bundle.yaml @@ -1116,6 +1116,9 @@ spec: description: PostgreSQL backup configuration properties: enabled: + description: |- + Enabled controls whether backups are enabled for the cluster. + Defaulted to true by the operator for crVersion >= 3.1.0. type: boolean pgbackrest: description: pgBackRest archive configuration diff --git a/deploy/cr.yaml b/deploy/cr.yaml index 8a17bce26..07f69f42e 100644 --- a/deploy/cr.yaml +++ b/deploy/cr.yaml @@ -487,6 +487,7 @@ spec: # pool_mode: transaction backups: +# enabled: true # trackLatestRestorableTime: true # volumeSnapshots: # mode: offline diff --git a/deploy/crd.yaml b/deploy/crd.yaml index bd9fce8c6..340b6668f 100644 --- a/deploy/crd.yaml +++ b/deploy/crd.yaml @@ -1116,6 +1116,9 @@ spec: description: PostgreSQL backup configuration properties: enabled: + description: |- + Enabled controls whether backups are enabled for the cluster. + Defaulted to true by the operator for crVersion >= 3.1.0. type: boolean pgbackrest: description: pgBackRest archive configuration diff --git a/deploy/cw-bundle.yaml b/deploy/cw-bundle.yaml index 3492ff9ce..eb89883bf 100644 --- a/deploy/cw-bundle.yaml +++ b/deploy/cw-bundle.yaml @@ -1116,6 +1116,9 @@ spec: description: PostgreSQL backup configuration properties: enabled: + description: |- + Enabled controls whether backups are enabled for the cluster. + Defaulted to true by the operator for crVersion >= 3.1.0. type: boolean pgbackrest: description: pgBackRest archive configuration diff --git a/internal/config/config.go b/internal/config/config.go index e62c0bf9f..fda998339 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -139,29 +139,29 @@ func VerifyImageValues(cluster *v1beta1.PostgresCluster) error { dataSourceRestore := cluster.Spec.DataSource != nil && cluster.Spec.DataSource.PostgresCluster != nil // K8SPG-710: Image check will fail without a backup section in PostgresCluster if (cluster.BackupSpecFound() && backupsEnabled || dataSourceRestore) && PGBackRestContainerImage(cluster) == "" { - images = append(images, "crunchy-pgbackrest") + images = append(images, "pgbackrest") } if PGAdminContainerImage(cluster) == "" && cluster.Spec.UserInterface != nil && cluster.Spec.UserInterface.PGAdmin != nil { - images = append(images, "crunchy-pgadmin4") + images = append(images, "pgadmin4") } if PGBouncerContainerImage(cluster) == "" && cluster.Spec.Proxy != nil && cluster.Spec.Proxy.PGBouncer != nil { - images = append(images, "crunchy-pgbouncer") + images = append(images, "pgbouncer") } if PGExporterContainerImage(cluster) == "" && cluster.Spec.Monitoring != nil && cluster.Spec.Monitoring.PGMonitor != nil && cluster.Spec.Monitoring.PGMonitor.Exporter != nil { - images = append(images, "crunchy-postgres-exporter") + images = append(images, "postgres-exporter") } if PostgresContainerImage(cluster) == "" { if cluster.Spec.PostGISVersion != "" { - images = append(images, "crunchy-postgres-gis") + images = append(images, "postgres-gis") } else { - images = append(images, "crunchy-postgres") + images = append(images, "postgres") } } diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 9ecc59c1c..f6cd42454 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -202,17 +202,17 @@ func TestPostgresContainerImage(t *testing.T) { } func TestVerifyImageValues(t *testing.T) { - t.Run("crunchy-postgres", func(t *testing.T) { + t.Run("postgres", func(t *testing.T) { cluster := &v1beta1.PostgresCluster{} cluster.Spec.PostgresVersion = 14 t.Setenv("RELATED_IMAGE_POSTGRES_14", "") os.Unsetenv("RELATED_IMAGE_POSTGRES_14") err := VerifyImageValues(cluster) - assert.ErrorContains(t, err, "crunchy-postgres") + assert.ErrorContains(t, err, "postgres") }) - t.Run("crunchy-postgres-gis", func(t *testing.T) { + t.Run("postgres-gis", func(t *testing.T) { cluster := &v1beta1.PostgresCluster{} cluster.Spec.PostgresVersion = 14 cluster.Spec.PostGISVersion = "3.3" @@ -220,10 +220,10 @@ func TestVerifyImageValues(t *testing.T) { os.Unsetenv("RELATED_IMAGE_POSTGRES_14_GIS_3.3") err := VerifyImageValues(cluster) - assert.ErrorContains(t, err, "crunchy-postgres-gis") + assert.ErrorContains(t, err, "postgres-gis") }) - t.Run("crunchy-pgbackrest-enabled", func(t *testing.T) { + t.Run("pgbackrest-enabled", func(t *testing.T) { cluster := &v1beta1.PostgresCluster{} cluster.Spec.PostgresVersion = 14 enabled := true @@ -232,10 +232,10 @@ func TestVerifyImageValues(t *testing.T) { os.Unsetenv("RELATED_IMAGE_PGBACKREST") err := VerifyImageValues(cluster) - assert.ErrorContains(t, err, "crunchy-pgbackrest") + assert.ErrorContains(t, err, "pgbackrest") }) - t.Run("crunchy-pgbackrest-disabled", func(t *testing.T) { + t.Run("pgbackrest-disabled", func(t *testing.T) { cluster := &v1beta1.PostgresCluster{} cluster.Spec.PostgresVersion = 14 enabled := false @@ -244,10 +244,10 @@ func TestVerifyImageValues(t *testing.T) { os.Unsetenv("RELATED_IMAGE_PGBACKREST") err := VerifyImageValues(cluster) - assert.Assert(t, !strings.Contains(err.Error(), "crunchy-pgbackrest")) + assert.Assert(t, !strings.Contains(err.Error(), "pgbackrest")) }) - t.Run("crunchy-pgbouncer", func(t *testing.T) { + t.Run("pgbouncer", func(t *testing.T) { cluster := &v1beta1.PostgresCluster{} cluster.Spec.PostgresVersion = 14 cluster.Spec.Proxy = &v1beta1.PostgresProxySpec{ @@ -257,10 +257,10 @@ func TestVerifyImageValues(t *testing.T) { os.Unsetenv("RELATED_IMAGE_PGBOUNCER") err := VerifyImageValues(cluster) - assert.ErrorContains(t, err, "crunchy-pgbouncer") + assert.ErrorContains(t, err, "pgbouncer") }) - t.Run("crunchy-pgadmin4", func(t *testing.T) { + t.Run("pgadmin4", func(t *testing.T) { cluster := &v1beta1.PostgresCluster{} cluster.Spec.PostgresVersion = 14 cluster.Spec.UserInterface = &v1beta1.UserInterfaceSpec{ @@ -270,10 +270,10 @@ func TestVerifyImageValues(t *testing.T) { os.Unsetenv("RELATED_IMAGE_PGADMIN") err := VerifyImageValues(cluster) - assert.ErrorContains(t, err, "crunchy-pgadmin4") + assert.ErrorContains(t, err, "pgadmin4") }) - t.Run("crunchy-postgres-exporter", func(t *testing.T) { + t.Run("postgres-exporter", func(t *testing.T) { cluster := &v1beta1.PostgresCluster{} cluster.Spec.PostgresVersion = 14 cluster.Spec.Monitoring = &v1beta1.MonitoringSpec{ @@ -285,7 +285,7 @@ func TestVerifyImageValues(t *testing.T) { os.Unsetenv("RELATED_IMAGE_PGEXPORTER") err := VerifyImageValues(cluster) - assert.ErrorContains(t, err, "crunchy-postgres-exporter") + assert.ErrorContains(t, err, "postgres-exporter") }) t.Run("multiple missing images", func(t *testing.T) { @@ -307,11 +307,11 @@ func TestVerifyImageValues(t *testing.T) { } err := VerifyImageValues(cluster) - assert.ErrorContains(t, err, "crunchy-postgres-gis") - assert.ErrorContains(t, err, "crunchy-pgbackrest") - assert.ErrorContains(t, err, "crunchy-pgbouncer") - assert.ErrorContains(t, err, "crunchy-pgadmin4") - assert.ErrorContains(t, err, "crunchy-postgres-exporter") + assert.ErrorContains(t, err, "postgres-gis") + assert.ErrorContains(t, err, "pgbackrest") + assert.ErrorContains(t, err, "pgbouncer") + assert.ErrorContains(t, err, "pgadmin4") + assert.ErrorContains(t, err, "postgres-exporter") }) t.Run("all images set", func(t *testing.T) { diff --git a/pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go b/pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go index 130797dfa..41f32bb54 100644 --- a/pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go +++ b/pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go @@ -314,6 +314,10 @@ func (cr *PerconaPGCluster) Default() { cr.Spec.AutoCreateUserSchema = new(true) } + if cr.CompareVersion("3.1.0") >= 0 && cr.Spec.Backups.Enabled == nil { + cr.Spec.Backups.Enabled = new(true) + } + if cr.CompareVersion("2.9.0") < 0 && cr.Spec.Config == nil { cr.Spec.Config = &crunchyv1beta1.PostgresConfigSpec{} } @@ -642,6 +646,9 @@ type Patroni struct { // Backups struct. // +kubebuilder:validation:XValidation:rule="(has(self.enabled) && self.enabled == false) || (has(self.pgbackrest.repos) && size(self.pgbackrest.repos) > 0)",message="At least one repository must be configured when backups are enabled" type Backups struct { + // Enabled controls whether backups are enabled for the cluster. + // Defaulted to true by the operator for crVersion >= 3.1.0. + // +optional Enabled *bool `json:"enabled,omitempty"` // pgBackRest archive configuration diff --git a/pkg/apis/pgv2.percona.com/v2/perconapgcluster_types_test.go b/pkg/apis/pgv2.percona.com/v2/perconapgcluster_types_test.go index 32bc035e5..70178a8d4 100644 --- a/pkg/apis/pgv2.percona.com/v2/perconapgcluster_types_test.go +++ b/pkg/apis/pgv2.percona.com/v2/perconapgcluster_types_test.go @@ -24,6 +24,35 @@ func TestPerconaPGCluster_Default(t *testing.T) { new(PerconaPGCluster).Default() } +func TestPerconaPGCluster_DefaultBackupsEnabled(t *testing.T) { + t.Run("nil is defaulted to true for CRVersion >= 3.1.0", func(t *testing.T) { + cr := new(PerconaPGCluster) + cr.Spec.CRVersion = version.Version() + cr.Default() + + require.NotNil(t, cr.Spec.Backups.Enabled) + assert.True(t, *cr.Spec.Backups.Enabled) + }) + + t.Run("nil is left untouched for CRVersion < 3.1.0", func(t *testing.T) { + cr := new(PerconaPGCluster) + cr.Spec.CRVersion = "3.0.0" + cr.Default() + + assert.Nil(t, cr.Spec.Backups.Enabled) + }) + + t.Run("explicit false is preserved for CRVersion >= 3.1.0", func(t *testing.T) { + cr := new(PerconaPGCluster) + cr.Spec.CRVersion = version.Version() + cr.Spec.Backups.Enabled = new(false) + cr.Default() + + require.NotNil(t, cr.Spec.Backups.Enabled) + assert.False(t, *cr.Spec.Backups.Enabled) + }) +} + func TestPerconaPGCluster_BackupsEnabled(t *testing.T) { trueVal := true falseVal := false