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
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,38 @@ spec:
limits:
memory: "2Gi"
cpu: "2"
catalogMaintenanceIntervalSeconds: 1800
```

> [!IMPORTANT]
> Unlike Barman, pgBackRest requires object storage to be accessible over HTTPS. While
> it's possible to disable key verification and use self-signed keys, using HTTP
> endpoint is not possible.

### Backup objects cleanup

pgBackRest expires backups from the repository on its own, but it does not know about
the CNPG `Backup` objects that point to them. The sidecar running on the primary periodically
deletes the `completed` `Backup` objects of the cluster whose backup ID is not in the
pgBackRest catalog anymore. The period is set by
`instanceSidecarConfiguration.catalogMaintenanceIntervalSeconds` (default `1800`; `0`
disables the cleanup, otherwise at least `60`).

The plugin only performs the cleanup when the configuration is considered safe: the stanza
matches and all repositories are reported as readable.

> [!IMPORTANT]
> Pointing an `Archive` at another location, removing one of its repositories or renaming the
> stanza means the previously recorded objects can no longer be matched; adding or reordering
> repositories does not.
> Such `Backup` resources, as well as the ones created by plugin versions before this
> feature, must be removed manually.

> [!NOTE]
> Only `Backup` objects labeled `cnpg.io/cluster=<cluster>` are considered. Both
> `ScheduledBackup` and `kubectl cnpg backup` set the label; a hand-applied `Backup`
> manifest without it is never cleaned up. Failed backups are left untouched.

### Configuring WAL Archiving

Once the `Archive` is defined, you can configure a PostgreSQL cluster to archive WALs by
Expand Down
8 changes: 8 additions & 0 deletions api/v1/archive_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ type InstanceSidecarConfiguration struct {
// SecurityContext for the sidecar container
// +optional
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
// The catalogMaintenanceIntervalSeconds defines how often
// the Backup objects of the cluster are compared with the
// pgBackRest catalog and deleted if not present in the
// catalog anymore. 0 disables the maintenance.
// +kubebuilder:default:=1800
// +kubebuilder:validation:XValidation:rule="self == 0 || self >= 60",message="catalogMaintenanceIntervalSeconds must be 0 (disabled) or at least 60"
// +optional
CatalogMaintenanceIntervalSeconds *int32 `json:"catalogMaintenanceIntervalSeconds,omitempty"`
}

// ArchiveSpec defines the desired state of Archive.
Expand Down
5 changes: 5 additions & 0 deletions api/v1/zz_generated.deepcopy.go

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

13 changes: 13 additions & 0 deletions config/crd/bases/pgbackrest.cnpg.opera.com_archives.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,19 @@ spec:
description: InstanceSidecarConfiguration defines the configuration
for the sidecar that runs in the instance pods.
properties:
catalogMaintenanceIntervalSeconds:
default: 1800
description: |-
The catalogMaintenanceIntervalSeconds defines how often
the Backup objects of the cluster are compared with the
pgBackRest catalog and deleted if not present in the
catalog anymore. 0 disables the maintenance.
format: int32
type: integer
x-kubernetes-validations:
- message: catalogMaintenanceIntervalSeconds must be 0 (disabled)
or at least 60
rule: self == 0 || self >= 60
env:
description: The environment to be explicitly passed to the sidecar
items:
Expand Down
2 changes: 2 additions & 0 deletions internal/cmd/instance/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func NewCmd() *cobra.Command {
RunE: func(cmd *cobra.Command, _ []string) error {
requiredSettings := []string{
"namespace",
"cluster-name",
"pod-name",
"spool-directory",
}
Expand All @@ -33,6 +34,7 @@ func NewCmd() *cobra.Command {
}

_ = viper.BindEnv("namespace", "NAMESPACE")
_ = viper.BindEnv("cluster-name", "CLUSTER_NAME")
_ = viper.BindEnv("pod-name", "POD_NAME")
_ = viper.BindEnv("pgdata", "PGDATA")
_ = viper.BindEnv("spool-directory", "SPOOL_DIRECTORY")
Expand Down
8 changes: 2 additions & 6 deletions internal/cnpgi/instance/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

pgbackrestv1 "github.com/operasoftware/cnpg-plugin-pgbackrest/api/v1"
"github.com/operasoftware/cnpg-plugin-pgbackrest/internal/cnpgi/metadata"
"github.com/operasoftware/cnpg-plugin-pgbackrest/internal/cnpgi/operator/config"
pgbackrestBackup "github.com/operasoftware/cnpg-plugin-pgbackrest/internal/pgbackrest/backup"
"github.com/operasoftware/cnpg-plugin-pgbackrest/internal/pgbackrest/catalog"
Expand Down Expand Up @@ -160,10 +159,7 @@ func (b BackupServiceImplementation) Backup(
EndLsn: executedBackupInfo.Backups[0].LSN.Stop,
InstanceId: b.InstanceName,
Online: true,
Metadata: map[string]string{
"version": metadata.Data.Version,
"name": metadata.Data.Name,
"displayName": metadata.Data.DisplayName,
},
Metadata: newBackupResultMetadata(
configuration.Cluster.UID, configuration.Stanza, &archive.Spec.Configuration).toMap(),
}, nil
}
Loading
Loading