diff --git a/pkg/api/config.go b/pkg/api/config.go index 0e731081..f454b96d 100644 --- a/pkg/api/config.go +++ b/pkg/api/config.go @@ -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 { @@ -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 diff --git a/pkg/command/commandbuilder.go b/pkg/command/commandbuilder.go index 70260b0b..5ab6d56b 100644 --- a/pkg/command/commandbuilder.go +++ b/pkg/command/commandbuilder.go @@ -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 diff --git a/pkg/command/commandbuilder_test.go b/pkg/command/commandbuilder_test.go index bb2d1a0d..f8b5c467 100644 --- a/pkg/command/commandbuilder_test.go +++ b/pkg/command/commandbuilder_test.go @@ -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"})) + }) +})