Skip to content
Open
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
18 changes: 18 additions & 0 deletions pkg/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,18 @@ type GoogleCredentials struct {
GKEEnvironment bool `json:"gkeEnvironment,omitempty"`
}

// S3AddressingStyle controls how bucket names are included in S3 requests.
type S3AddressingStyle string

const (
// S3AddressingStyleAuto lets the S3 client select the addressing style.
S3AddressingStyleAuto S3AddressingStyle = "auto"
// S3AddressingStyleVirtual uses virtual-hosted-style S3 requests.
S3AddressingStyleVirtual S3AddressingStyle = "virtual"
// S3AddressingStylePath uses path-style S3 requests.
S3AddressingStylePath S3AddressingStyle = "path"
)

// BarmanObjectStoreConfiguration contains the backup configuration
// using Barman against an S3-compatible object storage
type BarmanObjectStoreConfiguration struct {
Expand All @@ -176,6 +188,12 @@ type BarmanObjectStoreConfiguration struct {
// +optional
EndpointURL string `json:"endpointURL,omitempty"`

// The addressing style to use for S3 requests.
// When not specified, the S3 client selects the addressing style automatically.
// +kubebuilder:validation:Enum=auto;virtual;path
// +optional
AddressingStyle S3AddressingStyle `json:"addressingStyle,omitempty"`

// EndpointCA store the CA bundle of the barman endpoint.
// Useful when using self-signed certificates to avoid
// errors with certificate issuer and barman-cloud-wal-archive
Expand Down
11 changes: 10 additions & 1 deletion pkg/command/commandbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,16 @@ func AppendCloudProviderOptionsFromConfiguration(
options []string,
barmanConfiguration *barmanApi.BarmanObjectStoreConfiguration,
) ([]string, error) {
return appendCloudProviderOptions(ctx, options, barmanConfiguration.BarmanCredentials)
options, err := appendCloudProviderOptions(ctx, options, barmanConfiguration.BarmanCredentials)
if err != nil {
return nil, err
}

if barmanConfiguration.AWS != nil && barmanConfiguration.AddressingStyle != "" {
options = append(options, "--addressing-style", string(barmanConfiguration.AddressingStyle))
}

return options, nil
}

// AppendCloudProviderOptionsFromBackup takes an options array and adds the cloud provider specified
Expand Down
43 changes: 43 additions & 0 deletions pkg/command/commandbuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,46 @@ var _ = Describe("AppendCloudProviderOptions with Azure credentials", func() {
))
})
})

var _ = Describe("AppendCloudProviderOptionsFromConfiguration with S3 addressing style", func() {
It("should append the addressing style for AWS S3", func(ctx SpecContext) {
configuration := &barmanApi.BarmanObjectStoreConfiguration{
BarmanCredentials: barmanApi.BarmanCredentials{
AWS: &barmanApi.S3Credentials{},
},
AddressingStyle: barmanApi.S3AddressingStyleVirtual,
}

result, err := AppendCloudProviderOptionsFromConfiguration(ctx, nil, configuration)
Expect(err).ToNot(HaveOccurred())
Expect(result).To(Equal([]string{
"--cloud-provider", "aws-s3",
"--addressing-style", "virtual",
}))
})

It("should omit the addressing style when it is not configured", func(ctx SpecContext) {
configuration := &barmanApi.BarmanObjectStoreConfiguration{
BarmanCredentials: barmanApi.BarmanCredentials{
AWS: &barmanApi.S3Credentials{},
},
}

result, err := AppendCloudProviderOptionsFromConfiguration(ctx, nil, configuration)
Expect(err).ToNot(HaveOccurred())
Expect(result).To(Equal([]string{"--cloud-provider", "aws-s3"}))
})

It("should ignore the addressing style for non-S3 providers", func(ctx SpecContext) {
configuration := &barmanApi.BarmanObjectStoreConfiguration{
BarmanCredentials: barmanApi.BarmanCredentials{
Google: &barmanApi.GoogleCredentials{},
},
AddressingStyle: barmanApi.S3AddressingStyleVirtual,
}

result, err := AppendCloudProviderOptionsFromConfiguration(ctx, nil, configuration)
Expect(err).ToNot(HaveOccurred())
Expect(result).To(Equal([]string{"--cloud-provider", "google-cloud-storage"}))
})
})