Skip to content

Commit a6747c9

Browse files
mnencialeonardoce
andauthored
feat(barman-cloud): remove support for Barman <= 3.4 (cloudnative-pg#7220)
This patch removes compatibility with Barman versions 3.4 and earlier, which have been deprecated. These versions, released before April 2023, are no longer maintained and require specific workarounds that increase code complexity. Removing support simplifies the backup integration logic and aligns the operator with recent, supported versions of Barman (≥ 3.5). We have simultaneously reduced technical debt by eliminating the capability detection framework that required checking the version of Barman Cloud before every execution of the program. Users running an operand version released before January 2023 must upgrade to a more recent version before updating the operator, as older operand images may not be compatible with the updated backup mechanisms introduced in this patch. This commit represents progress in transitioning users to the recommended Barman Cloud plugin. Closes cloudnative-pg#3954 Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com> Signed-off-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com> Co-authored-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com>
1 parent 78cec27 commit a6747c9

File tree

6 files changed

+23
-63
lines changed

6 files changed

+23
-63
lines changed

config/crd/bases/postgresql.cnpg.io_clusters.yaml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,14 +1152,11 @@ spec:
11521152
description: |-
11531153
Compress a backup file (a tar file per tablespace) while streaming it
11541154
to the object store. Available options are empty string (no
1155-
compression, default), `gzip`, `bzip2`, `lz4`, `snappy`, `xz`, and `zstd`.
1155+
compression, default), `gzip`, `bzip2`, and `snappy`.
11561156
enum:
11571157
- bzip2
11581158
- gzip
1159-
- lz4
11601159
- snappy
1161-
- xz
1162-
- zstd
11631160
type: string
11641161
encryption:
11651162
description: |-
@@ -2661,14 +2658,11 @@ spec:
26612658
description: |-
26622659
Compress a backup file (a tar file per tablespace) while streaming it
26632660
to the object store. Available options are empty string (no
2664-
compression, default), `gzip`, `bzip2`, `lz4`, `snappy`, `xz`, and `zstd`.
2661+
compression, default), `gzip`, `bzip2`, and `snappy`.
26652662
enum:
26662663
- bzip2
26672664
- gzip
2668-
- lz4
26692665
- snappy
2670-
- xz
2671-
- zstd
26722666
type: string
26732667
encryption:
26742668
description: |-

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ require (
88
github.com/avast/retry-go/v4 v4.6.1
99
github.com/blang/semver v3.5.1+incompatible
1010
github.com/cheynewallace/tabby v1.1.1
11-
github.com/cloudnative-pg/barman-cloud v0.3.0
11+
github.com/cloudnative-pg/barman-cloud v0.3.1
1212
github.com/cloudnative-pg/cnpg-i v0.1.1-0.20250321093050-de4ab51537cb
13-
github.com/cloudnative-pg/machinery v0.1.0
13+
github.com/cloudnative-pg/machinery v0.2.0
1414
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
1515
github.com/evanphx/json-patch/v5 v5.9.11
1616
github.com/go-logr/logr v1.4.2

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UF
1818
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
1919
github.com/cheynewallace/tabby v1.1.1 h1:JvUR8waht4Y0S3JF17G6Vhyt+FRhnqVCkk8l4YrOU54=
2020
github.com/cheynewallace/tabby v1.1.1/go.mod h1:Pba/6cUL8uYqvOc9RkyvFbHGrQ9wShyrn6/S/1OYVys=
21-
github.com/cloudnative-pg/barman-cloud v0.3.0 h1:tCtIF7nsHDH5X7nAXXd7VqNKKNGHrycXAyyKKKpdGS4=
22-
github.com/cloudnative-pg/barman-cloud v0.3.0/go.mod h1:8m6W117343zT28ctcskUYEu/dy+MX3hUUW4DynH8MLI=
21+
github.com/cloudnative-pg/barman-cloud v0.3.1 h1:kzkY77k2lN/caoyh7ibXDSZjJeSJTNvnVt6Gfa8Iq5M=
22+
github.com/cloudnative-pg/barman-cloud v0.3.1/go.mod h1:4HL3AjY9oEl2Ed0HSkyvTZEQPhwyFOaAnuCz9lfVeYQ=
2323
github.com/cloudnative-pg/cnpg-i v0.1.1-0.20250321093050-de4ab51537cb h1:FPORwCxjZwlnKnF7dOkuOAz0GBSQ3Hrn+8lm4uMiWeM=
2424
github.com/cloudnative-pg/cnpg-i v0.1.1-0.20250321093050-de4ab51537cb/go.mod h1:n+kbHm3rzRCY5IJKuE1tGMbG6JaeYz8yycYoLt7BeKo=
25-
github.com/cloudnative-pg/machinery v0.1.0 h1:tjRmsqQmsO/OlaT0uFmkEtVqgr+SGPM88cKZOHYKLBo=
26-
github.com/cloudnative-pg/machinery v0.1.0/go.mod h1:0V3vm44FaIsY+x4pm8ORry7xCC3AJiO+ebfPNxeP5Ck=
25+
github.com/cloudnative-pg/machinery v0.2.0 h1:x8OAwxdeL/6wkbxqorz+nX6UovTyx7/TBeCfiRebR2o=
26+
github.com/cloudnative-pg/machinery v0.2.0/go.mod h1:Kg8W8Tb/1UFGGtw3hR8S5SytSWddlHaCnJSgBo4x/nc=
2727
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
2828
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
2929
github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=

pkg/management/postgres/backup.go

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"time"
2929

3030
barmanBackup "github.com/cloudnative-pg/barman-cloud/pkg/backup"
31-
barmanCapabilities "github.com/cloudnative-pg/barman-cloud/pkg/capabilities"
3231
barmanCatalog "github.com/cloudnative-pg/barman-cloud/pkg/catalog"
3332
barmanCommand "github.com/cloudnative-pg/barman-cloud/pkg/command"
3433
barmanCredentials "github.com/cloudnative-pg/barman-cloud/pkg/credentials"
@@ -68,7 +67,6 @@ type BackupCommand struct {
6867
Env []string
6968
Log log.Logger
7069
Instance *Instance
71-
Capabilities *barmanCapabilities.Capabilities
7270
barmanBackup *barmanBackup.Command
7371
}
7472

@@ -82,11 +80,6 @@ func NewBarmanBackupCommand(
8280
instance *Instance,
8381
log log.Logger,
8482
) (*BackupCommand, error) {
85-
capabilities, err := barmanCapabilities.CurrentCapabilities()
86-
if err != nil {
87-
return nil, err
88-
}
89-
9083
return &BackupCommand{
9184
Cluster: cluster,
9285
Backup: backup,
@@ -95,18 +88,14 @@ func NewBarmanBackupCommand(
9588
Env: os.Environ(),
9689
Instance: instance,
9790
Log: log,
98-
Capabilities: capabilities,
99-
barmanBackup: barmanBackup.NewBackupCommand(cluster.Spec.Backup.BarmanObjectStore, capabilities),
91+
barmanBackup: barmanBackup.NewBackupCommand(cluster.Spec.Backup.BarmanObjectStore),
10092
}, nil
10193
}
10294

10395
// Start initiates a backup for this instance using
10496
// barman-cloud-backup
10597
func (b *BackupCommand) Start(ctx context.Context) error {
10698
contextLogger := log.FromContext(ctx)
107-
if err := b.ensureCompatibility(); err != nil {
108-
return err
109-
}
11099

111100
b.setupBackupStatus()
112101

@@ -145,15 +134,6 @@ func (b *BackupCommand) Start(ctx context.Context) error {
145134
return nil
146135
}
147136

148-
func (b *BackupCommand) ensureCompatibility() error {
149-
postgresVers, err := b.Instance.GetPgVersion()
150-
if err != nil {
151-
return err
152-
}
153-
154-
return b.barmanBackup.IsCompatible(postgresVers)
155-
}
156-
157137
func (b *BackupCommand) retryWithRefreshedCluster(
158138
ctx context.Context,
159139
cb func() error,
@@ -234,7 +214,6 @@ func (b *BackupCommand) takeBackup(ctx context.Context) error {
234214
b.Backup.Status.BackupName,
235215
backupStatus.ServerName,
236216
b.Env,
237-
b.Cluster,
238217
postgres.BackupTemporaryDirectory,
239218
)
240219
if err != nil {
@@ -249,7 +228,7 @@ func (b *BackupCommand) takeBackup(ctx context.Context) error {
249228
b.Backup.Status.SetAsCompleted()
250229

251230
barmanBackup, err := b.barmanBackup.GetExecutedBackupInfo(
252-
ctx, b.Backup.Status.BackupName, backupStatus.ServerName, b.Cluster, b.Env)
231+
ctx, b.Backup.Status.BackupName, backupStatus.ServerName, b.Env)
253232
if err != nil {
254233
return err
255234
}
@@ -348,9 +327,7 @@ func (b *BackupCommand) setupBackupStatus() {
348327
barmanConfiguration := b.Cluster.Spec.Backup.BarmanObjectStore
349328
backupStatus := b.Backup.GetStatus()
350329

351-
if b.Capabilities.ShouldExecuteBackupWithName(b.Cluster) {
352-
backupStatus.BackupName = fmt.Sprintf("backup-%v", pgTime.ToCompactISO8601(time.Now()))
353-
}
330+
backupStatus.BackupName = fmt.Sprintf("backup-%v", pgTime.ToCompactISO8601(time.Now()))
354331
backupStatus.BarmanCredentials = barmanConfiguration.BarmanCredentials
355332
backupStatus.EndpointCA = barmanConfiguration.EndpointCA
356333
backupStatus.EndpointURL = barmanConfiguration.EndpointURL

pkg/management/postgres/backup_test.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"strings"
2626

2727
barmanBackup "github.com/cloudnative-pg/barman-cloud/pkg/backup"
28-
barmanCapabilities "github.com/cloudnative-pg/barman-cloud/pkg/capabilities"
2928
"github.com/cloudnative-pg/machinery/pkg/log"
3029
"k8s.io/apimachinery/pkg/api/meta"
3130
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -120,8 +119,6 @@ var _ = Describe("testing backup command", func() {
120119
},
121120
},
122121
}
123-
capabilities, err := barmanCapabilities.CurrentCapabilities()
124-
Expect(err).ShouldNot(HaveOccurred())
125122
backupCommand = BackupCommand{
126123
Cluster: cluster,
127124
Backup: backup,
@@ -130,11 +127,10 @@ var _ = Describe("testing backup command", func() {
130127
WithObjects(cluster, backup).
131128
WithStatusSubresource(cluster, backup).
132129
Build(),
133-
Recorder: &record.FakeRecorder{},
134-
Env: os.Environ(),
135-
Log: log.FromContext(context.Background()),
136-
Instance: &Instance{},
137-
Capabilities: capabilities,
130+
Recorder: &record.FakeRecorder{},
131+
Env: os.Environ(),
132+
Log: log.FromContext(context.Background()),
133+
Instance: &Instance{},
138134
}
139135
})
140136

@@ -154,16 +150,9 @@ var _ = Describe("testing backup command", func() {
154150
var _ = Describe("generate backup options", func() {
155151
const namespace = "test"
156152

157-
var (
158-
capabilities *barmanCapabilities.Capabilities
159-
cluster *apiv1.Cluster
160-
)
153+
var cluster *apiv1.Cluster
161154

162155
BeforeEach(func() {
163-
var err error
164-
capabilities, err = barmanCapabilities.CurrentCapabilities()
165-
Expect(err).ShouldNot(HaveOccurred())
166-
167156
cluster = &apiv1.Cluster{
168157
ObjectMeta: metav1.ObjectMeta{Name: "test-cluster", Namespace: namespace},
169158
Spec: apiv1.ClusterSpec{
@@ -185,7 +174,7 @@ var _ = Describe("generate backup options", func() {
185174
extraOptions := []string{"--min-chunk-size=5MB", "--read-timeout=60", "-vv"}
186175
cluster.Spec.Backup.BarmanObjectStore.Data.AdditionalCommandArgs = extraOptions
187176

188-
cmd := barmanBackup.NewBackupCommand(cluster.Spec.Backup.BarmanObjectStore, capabilities)
177+
cmd := barmanBackup.NewBackupCommand(cluster.Spec.Backup.BarmanObjectStore)
189178
options, err := cmd.GetDataConfiguration([]string{})
190179
Expect(err).ToNot(HaveOccurred())
191180

@@ -206,7 +195,7 @@ var _ = Describe("generate backup options", func() {
206195
"--encryption=aes256",
207196
}
208197
cluster.Spec.Backup.BarmanObjectStore.Data.AdditionalCommandArgs = extraOptions
209-
cmd := barmanBackup.NewBackupCommand(cluster.Spec.Backup.BarmanObjectStore, capabilities)
198+
cmd := barmanBackup.NewBackupCommand(cluster.Spec.Backup.BarmanObjectStore)
210199
options, err := cmd.GetDataConfiguration([]string{})
211200
Expect(err).ToNot(HaveOccurred())
212201

pkg/management/postgres/restore.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ import (
3535
"time"
3636

3737
barmanArchiver "github.com/cloudnative-pg/barman-cloud/pkg/archiver"
38-
barmanCapabilities "github.com/cloudnative-pg/barman-cloud/pkg/capabilities"
3938
barmanCatalog "github.com/cloudnative-pg/barman-cloud/pkg/catalog"
4039
barmanCommand "github.com/cloudnative-pg/barman-cloud/pkg/command"
4140
barmanCredentials "github.com/cloudnative-pg/barman-cloud/pkg/credentials"
4241
barmanRestorer "github.com/cloudnative-pg/barman-cloud/pkg/restorer"
42+
barmanUtils "github.com/cloudnative-pg/barman-cloud/pkg/utils"
4343
restore "github.com/cloudnative-pg/cnpg-i/pkg/restore/job"
4444
"github.com/cloudnative-pg/machinery/pkg/envmap"
4545
"github.com/cloudnative-pg/machinery/pkg/execlog"
@@ -452,13 +452,13 @@ func (info InitInfo) restoreDataDir(ctx context.Context, backup *apiv1.Backup, e
452452
contextLogger.Info("Starting barman-cloud-restore",
453453
"options", options)
454454

455-
cmd := exec.Command(barmanCapabilities.BarmanCloudRestore, options...) // #nosec G204
455+
cmd := exec.Command(barmanUtils.BarmanCloudRestore, options...) // #nosec G204
456456
cmd.Env = env
457-
err = execlog.RunStreaming(cmd, barmanCapabilities.BarmanCloudRestore)
457+
err = execlog.RunStreaming(cmd, barmanUtils.BarmanCloudRestore)
458458
if err != nil {
459459
var exitError *exec.ExitError
460460
if errors.As(err, &exitError) {
461-
err = barmanCommand.UnmarshalBarmanCloudRestoreExitCode(ctx, exitError.ExitCode())
461+
err = barmanCommand.UnmarshalBarmanCloudRestoreExitCode(exitError.ExitCode())
462462
}
463463

464464
contextLogger.Error(err, "Can't restore backup")
@@ -655,7 +655,7 @@ func (info InitInfo) writeCustomRestoreWalConfig(cluster *apiv1.Cluster, conf st
655655
func getRestoreWalConfig(ctx context.Context, backup *apiv1.Backup) (string, error) {
656656
var err error
657657

658-
cmd := []string{barmanCapabilities.BarmanCloudWalRestore}
658+
cmd := []string{barmanUtils.BarmanCloudWalRestore}
659659
if backup.Status.EndpointURL != "" {
660660
cmd = append(cmd, "--endpoint-url", backup.Status.EndpointURL)
661661
}

0 commit comments

Comments
 (0)