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 @@ -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
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/pgv2.percona.com_perconapgclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions deploy/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions deploy/cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ spec:
# pool_mode: transaction

backups:
# enabled: true
# trackLatestRestorableTime: true
# volumeSnapshots:
# mode: offline
Expand Down
3 changes: 3 additions & 0 deletions deploy/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions deploy/cw-bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Comment thread
hors marked this conversation as resolved.
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")
}
}
Comment on lines 160 to 166

Expand Down
38 changes: 19 additions & 19 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,28 +202,28 @@ 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"
t.Setenv("RELATED_IMAGE_POSTGRES_14_GIS_3.3", "")
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
Expand All @@ -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
Expand All @@ -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"))
Comment on lines 246 to +247
})

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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
Expand Down Expand Up @@ -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"`
Comment thread
hors marked this conversation as resolved.

// pgBackRest archive configuration
Expand Down
29 changes: 29 additions & 0 deletions pkg/apis/pgv2.percona.com/v2/perconapgcluster_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading