Skip to content

Commit d3dcb5b

Browse files
feat: pass additionalCommandArgs to barman-cloud-backup-show / -list
An ObjectStore lets users tack extra command-line flags onto four of the six barman-cloud-* invocations the plugin shells out to: - barman-cloud-backup via Data.AdditionalCommandArgs - barman-cloud-wal-archive via Wal.ArchiveAdditionalCommandArgs - barman-cloud-wal-restore via Wal.RestoreAdditionalCommandArgs - barman-cloud-restore via Data.RestoreAdditionalCommandArgs (PR #914 in the plugin) The remaining two — barman-cloud-backup-show (the post-write verification) and barman-cloud-backup-list (retention pruning) — had no equivalent, which is the gap reported in plugin-barman-cloud #712: on strictly-vhost S3-compatible endpoints, users need --addressing-style=virtual on every cloud command, and currently those two reject the user-provided args, marking otherwise-successful backups as failed and silently breaking retention pruning. This adds two new fields on DataBackupConfiguration - ShowAdditionalCommandArgs and ListAdditionalCommandArgs - plus matching AppendShowAdditionalCommandArgs and AppendListAdditionalCommandArgs helpers, mirroring the existing pattern. executeQueryCommand in pkg/command/backuplist.go grows a separate additionalFlagArgs parameter so the user-provided flags land alongside the standard options (--format json, --endpoint-url, cloud provider opts) rather than after the positional DESTINATION/SERVER/BACKUP_ID arguments; GetBackupList and GetBackupByName thread the new helpers through. Tests mirror the existing AppendAdditionalCommandArgs ones. Refs: cloudnative-pg/plugin-barman-cloud#712
1 parent 9ca5269 commit d3dcb5b

4 files changed

Lines changed: 110 additions & 2 deletions

File tree

pkg/api/config.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,33 @@ type DataBackupConfiguration struct {
325325
// behavior during execution.
326326
// +optional
327327
AdditionalCommandArgs []string `json:"additionalCommandArgs,omitempty"`
328+
329+
// ShowAdditionalCommandArgs represents additional arguments that can be appended
330+
// to the 'barman-cloud-backup-show' command-line invocation. This command is
331+
// used after a successful upload to verify and record metadata about the
332+
// freshly-written backup, so flags relevant to the underlying S3 client
333+
// (e.g. `--addressing-style=virtual` for strictly virtual-hosted S3-compatible
334+
// endpoints) generally belong here as well.
335+
//
336+
// Note:
337+
// It's essential to ensure that the provided arguments are valid and supported
338+
// by the 'barman-cloud-backup-show' command, to avoid potential errors or
339+
// unintended behavior during execution.
340+
// +optional
341+
ShowAdditionalCommandArgs []string `json:"showAdditionalCommandArgs,omitempty"`
342+
343+
// ListAdditionalCommandArgs represents additional arguments that can be appended
344+
// to the 'barman-cloud-backup-list' command-line invocation. This command is
345+
// used internally for retention-policy enforcement; flags relevant to the
346+
// underlying S3 client (e.g. `--addressing-style=virtual` for strictly
347+
// virtual-hosted S3-compatible endpoints) generally belong here as well.
348+
//
349+
// Note:
350+
// It's essential to ensure that the provided arguments are valid and supported
351+
// by the 'barman-cloud-backup-list' command, to avoid potential errors or
352+
// unintended behavior during execution.
353+
// +optional
354+
ListAdditionalCommandArgs []string `json:"listAdditionalCommandArgs,omitempty"`
328355
}
329356

330357
// ArePopulated checks if the passed set of credentials contains
@@ -466,6 +493,24 @@ func (cfg *DataBackupConfiguration) AppendAdditionalCommandArgs(options []string
466493
return appendAdditionalCommandArgs(cfg.AdditionalCommandArgs, options)
467494
}
468495

496+
// AppendShowAdditionalCommandArgs adds custom arguments as barman-cloud-backup-show
497+
// command-line options
498+
func (cfg *DataBackupConfiguration) AppendShowAdditionalCommandArgs(options []string) []string {
499+
if cfg == nil || len(cfg.ShowAdditionalCommandArgs) == 0 {
500+
return options
501+
}
502+
return appendAdditionalCommandArgs(cfg.ShowAdditionalCommandArgs, options)
503+
}
504+
505+
// AppendListAdditionalCommandArgs adds custom arguments as barman-cloud-backup-list
506+
// command-line options
507+
func (cfg *DataBackupConfiguration) AppendListAdditionalCommandArgs(options []string) []string {
508+
if cfg == nil || len(cfg.ListAdditionalCommandArgs) == 0 {
509+
return options
510+
}
511+
return appendAdditionalCommandArgs(cfg.ListAdditionalCommandArgs, options)
512+
}
513+
469514
// AppendArchiveAdditionalCommandArgs adds custom arguments as barman-cloud-wal-archive command-line options
470515
func (cfg *WalBackupConfiguration) AppendArchiveAdditionalCommandArgs(options []string) []string {
471516
if cfg == nil || len(cfg.ArchiveAdditionalCommandArgs) == 0 {

pkg/api/config_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,50 @@ var _ = Describe("DataBackupConfiguration.AppendAdditionalCommandArgs", func() {
4949
})
5050
})
5151

52+
var _ = Describe("DataBackupConfiguration.AppendShowAdditionalCommandArgs", func() {
53+
var options []string
54+
var config DataBackupConfiguration
55+
BeforeEach(func() {
56+
options = []string{"--option1", "--option2"}
57+
config = DataBackupConfiguration{
58+
ShowAdditionalCommandArgs: []string{"--option3", "--option4"},
59+
}
60+
})
61+
62+
It("should append additional command args to the options", func() {
63+
updatedOptions := config.AppendShowAdditionalCommandArgs(options)
64+
Expect(updatedOptions).To(Equal([]string{"--option1", "--option2", "--option3", "--option4"}))
65+
})
66+
67+
It("should return the original options if there are no additional command args", func() {
68+
config.ShowAdditionalCommandArgs = nil
69+
updatedOptions := config.AppendShowAdditionalCommandArgs(options)
70+
Expect(updatedOptions).To(Equal(options))
71+
})
72+
})
73+
74+
var _ = Describe("DataBackupConfiguration.AppendListAdditionalCommandArgs", func() {
75+
var options []string
76+
var config DataBackupConfiguration
77+
BeforeEach(func() {
78+
options = []string{"--option1", "--option2"}
79+
config = DataBackupConfiguration{
80+
ListAdditionalCommandArgs: []string{"--option3", "--option4"},
81+
}
82+
})
83+
84+
It("should append additional command args to the options", func() {
85+
updatedOptions := config.AppendListAdditionalCommandArgs(options)
86+
Expect(updatedOptions).To(Equal([]string{"--option1", "--option2", "--option3", "--option4"}))
87+
})
88+
89+
It("should return the original options if there are no additional command args", func() {
90+
config.ListAdditionalCommandArgs = nil
91+
updatedOptions := config.AppendListAdditionalCommandArgs(options)
92+
Expect(updatedOptions).To(Equal(options))
93+
})
94+
})
95+
5296
var _ = Describe("WalBackupConfiguration.AppendArchiveAdditionalCommandArgs", func() {
5397
var options []string
5498
var config WalBackupConfiguration

pkg/api/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/command/backuplist.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ func executeQueryCommand(
6161
barmanCommand string,
6262
barmanConfiguration *barmanApi.BarmanObjectStoreConfiguration,
6363
serverName string,
64-
additionalOptions []string,
64+
additionalFlagArgs []string,
65+
trailingArgs []string,
6566
env []string,
6667
) (string, error) {
6768
contextLogger := log.FromContext(ctx).WithName("barman")
@@ -77,8 +78,14 @@ func executeQueryCommand(
7778
return "", err
7879
}
7980

81+
// User-provided per-subcommand flags are appended after the standard
82+
// options (cloud provider, endpoint, etc.) but before the positional
83+
// arguments, matching the shape of the other Append*AdditionalCommandArgs
84+
// helpers in the rest of this library.
85+
options = append(options, additionalFlagArgs...)
86+
8087
options = append(options, barmanConfiguration.DestinationPath, serverName)
81-
options = append(options, additionalOptions...)
88+
options = append(options, trailingArgs...)
8289

8390
var stdoutBuffer bytes.Buffer
8491
var stderrBuffer bytes.Buffer
@@ -114,6 +121,7 @@ func GetBackupList(
114121
utils.BarmanCloudBackupList,
115122
barmanConfiguration,
116123
serverName,
124+
barmanConfiguration.Data.AppendListAdditionalCommandArgs(nil),
117125
[]string{},
118126
env,
119127
)
@@ -146,6 +154,7 @@ func GetBackupByName(
146154
utils.BarmanCloudBackupShow,
147155
barmanConfiguration,
148156
serverName,
157+
barmanConfiguration.Data.AppendShowAdditionalCommandArgs(nil),
149158
[]string{backupName},
150159
env,
151160
)

0 commit comments

Comments
 (0)