Skip to content
Draft
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/cloudnative-pg/barman-cloud
module github.com/davidchandra95/barman-cloud

go 1.26.0

Expand Down
20 changes: 20 additions & 0 deletions pkg/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,20 @@ type GoogleCredentials struct {
GKEEnvironment bool `json:"gkeEnvironment,omitempty"`
}

// S3AddressingStyle controls how Barman Cloud addresses S3 buckets.
type S3AddressingStyle string

const (
// S3AddressingStyleAuto lets Barman Cloud choose the addressing style.
S3AddressingStyleAuto S3AddressingStyle = "auto"

// S3AddressingStyleVirtual addresses buckets as subdomains of the endpoint.
S3AddressingStyleVirtual S3AddressingStyle = "virtual"

// S3AddressingStylePath addresses buckets as a path below the endpoint.
S3AddressingStylePath S3AddressingStyle = "path"
)

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

// S3AddressingStyle controls how Barman Cloud addresses S3 buckets. It is
// applied to every Barman Cloud command that uses this object store.
// +kubebuilder:validation:Enum=auto;virtual;path
// +optional
S3AddressingStyle S3AddressingStyle `json:"s3AddressingStyle,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
4 changes: 2 additions & 2 deletions pkg/api/webhooks/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ package webhooks
import (
"k8s.io/apimachinery/pkg/util/validation/field"

"github.com/cloudnative-pg/barman-cloud/pkg/api"
"github.com/cloudnative-pg/barman-cloud/pkg/utils"
"github.com/davidchandra95/barman-cloud/pkg/api"
"github.com/davidchandra95/barman-cloud/pkg/utils"
)

// ValidateBackupConfiguration validates the backup configuration
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/webhooks/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package webhooks
import (
"k8s.io/apimachinery/pkg/util/validation/field"

api "github.com/cloudnative-pg/barman-cloud/pkg/api"
api "github.com/davidchandra95/barman-cloud/pkg/api"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down
8 changes: 4 additions & 4 deletions pkg/archiver/archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import (

"github.com/cloudnative-pg/machinery/pkg/log"

"github.com/cloudnative-pg/barman-cloud/pkg/api"
"github.com/cloudnative-pg/barman-cloud/pkg/command"
"github.com/cloudnative-pg/barman-cloud/pkg/spool"
"github.com/cloudnative-pg/barman-cloud/pkg/walarchive"
"github.com/davidchandra95/barman-cloud/pkg/api"
"github.com/davidchandra95/barman-cloud/pkg/command"
"github.com/davidchandra95/barman-cloud/pkg/spool"
"github.com/davidchandra95/barman-cloud/pkg/walarchive"
)

// WALArchiver is a structure containing every info need to archive a set of WAL files
Expand Down
6 changes: 3 additions & 3 deletions pkg/archiver/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (
"context"
"fmt"

barmanApi "github.com/cloudnative-pg/barman-cloud/pkg/api"
barmanCommand "github.com/cloudnative-pg/barman-cloud/pkg/command"
"github.com/cloudnative-pg/barman-cloud/pkg/utils"
barmanApi "github.com/davidchandra95/barman-cloud/pkg/api"
barmanCommand "github.com/davidchandra95/barman-cloud/pkg/command"
"github.com/davidchandra95/barman-cloud/pkg/utils"
)

// BarmanCloudWalArchiveOptions calculates the set of options to be
Expand Down
2 changes: 1 addition & 1 deletion pkg/archiver/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"os"
"strings"

barmanApi "github.com/cloudnative-pg/barman-cloud/pkg/api"
barmanApi "github.com/davidchandra95/barman-cloud/pkg/api"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down
8 changes: 4 additions & 4 deletions pkg/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import (
"github.com/cloudnative-pg/machinery/pkg/execlog"
"github.com/cloudnative-pg/machinery/pkg/log"

barmanApi "github.com/cloudnative-pg/barman-cloud/pkg/api"
barmanCatalog "github.com/cloudnative-pg/barman-cloud/pkg/catalog"
barmanCommand "github.com/cloudnative-pg/barman-cloud/pkg/command"
"github.com/cloudnative-pg/barman-cloud/pkg/utils"
barmanApi "github.com/davidchandra95/barman-cloud/pkg/api"
barmanCatalog "github.com/davidchandra95/barman-cloud/pkg/catalog"
barmanCommand "github.com/davidchandra95/barman-cloud/pkg/command"
"github.com/davidchandra95/barman-cloud/pkg/utils"
)

// Command represents a barman backup command
Expand Down
21 changes: 20 additions & 1 deletion pkg/backup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

"k8s.io/utils/ptr"

barmanApi "github.com/cloudnative-pg/barman-cloud/pkg/api"
barmanApi "github.com/davidchandra95/barman-cloud/pkg/api"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -130,4 +130,23 @@ var _ = Describe("GetBarmanCloudBackupOptions", func() {
"s3://bucket-name/ test-cluster",
))
})

It("should apply the configured S3 addressing style over additional arguments", func(ctx SpecContext) {
backupCommand.configuration.BarmanCredentials = barmanApi.BarmanCredentials{
AWS: &barmanApi.S3Credentials{InheritFromIAMRole: true},
}
backupCommand.configuration.S3AddressingStyle = barmanApi.S3AddressingStyleVirtual
backupCommand.configuration.Data.AdditionalCommandArgs = []string{
"--addressing-style", "path",
}

options, err := backupCommand.GetBarmanCloudBackupOptions(ctx, "test-backup", "test-cluster")
Expect(err).ToNot(HaveOccurred())
Expect(strings.Join(options, " ")).To(Equal(
"--user postgres --name test-backup " +
"--gzip --encryption aes256 --immediate-checkpoint --jobs 4 " +
"--cloud-provider aws-s3 --addressing-style virtual " +
"s3://bucket-name/ test-cluster",
))
})
})
4 changes: 2 additions & 2 deletions pkg/command/backupdelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (

"github.com/cloudnative-pg/machinery/pkg/log"

barmanApi "github.com/cloudnative-pg/barman-cloud/pkg/api"
barmanUtils "github.com/cloudnative-pg/barman-cloud/pkg/utils"
barmanApi "github.com/davidchandra95/barman-cloud/pkg/api"
barmanUtils "github.com/davidchandra95/barman-cloud/pkg/utils"
)

// DeleteBackupsByPolicy executes a command that deletes backups, given the Barman object store configuration,
Expand Down
6 changes: 3 additions & 3 deletions pkg/command/backuplist.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ import (

"github.com/cloudnative-pg/machinery/pkg/log"

barmanApi "github.com/cloudnative-pg/barman-cloud/pkg/api"
"github.com/cloudnative-pg/barman-cloud/pkg/catalog"
"github.com/cloudnative-pg/barman-cloud/pkg/utils"
barmanApi "github.com/davidchandra95/barman-cloud/pkg/api"
"github.com/davidchandra95/barman-cloud/pkg/catalog"
"github.com/davidchandra95/barman-cloud/pkg/utils"
)

func executeQueryCommand(
Expand Down
48 changes: 46 additions & 2 deletions pkg/command/commandbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ package command

import (
"context"
"fmt"
"strings"

barmanApi "github.com/cloudnative-pg/barman-cloud/pkg/api"
barmanApi "github.com/davidchandra95/barman-cloud/pkg/api"
)

// CloudWalRestoreOptions returns the options needed to execute the barman command successfully
Expand Down Expand Up @@ -62,7 +64,27 @@ func AppendCloudProviderOptionsFromConfiguration(
options []string,
barmanConfiguration *barmanApi.BarmanObjectStoreConfiguration,
) ([]string, error) {
return appendCloudProviderOptions(ctx, options, barmanConfiguration.BarmanCredentials)
if barmanConfiguration.S3AddressingStyle != "" {
if barmanConfiguration.AWS == nil {
return nil, fmt.Errorf("s3AddressingStyle requires s3Credentials")
}

options = withoutOption(options, "--addressing-style")
}

options, err := appendCloudProviderOptions(ctx, options, barmanConfiguration.BarmanCredentials)
if err != nil {
return nil, err
}

if barmanConfiguration.S3AddressingStyle != "" {
options = append(options,
"--addressing-style",
string(barmanConfiguration.S3AddressingStyle),
)
}

return options, nil
}

// AppendCloudProviderOptionsFromBackup takes an options array and adds the cloud provider specified
Expand Down Expand Up @@ -127,6 +149,28 @@ func appendCloudProviderOptions(
return options, nil
}

// withoutOption removes a command-line option and its value from options.
// The configured ObjectStore value must take precedence over a command-specific
// additional argument so every Barman command uses the same addressing style.
func withoutOption(options []string, option string) []string {
result := make([]string, 0, len(options))
for index := 0; index < len(options); index++ {
current := options[index]
switch {
case current == option:
if index+1 < len(options) {
index++
}
case strings.HasPrefix(current, option+"="):
continue
default:
result = append(result, current)
}
}

return result
}

type contextKey string

// contextKeyUseDefaultAzureCredentials contains a bool indicating if the default azure credentials should be used
Expand Down
47 changes: 46 additions & 1 deletion pkg/command/commandbuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

machineryapi "github.com/cloudnative-pg/machinery/pkg/api"

barmanApi "github.com/cloudnative-pg/barman-cloud/pkg/api"
barmanApi "github.com/davidchandra95/barman-cloud/pkg/api"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -62,6 +62,21 @@ var _ = Describe("barmanCloudWalRestoreOptions", func() {
"s3://bucket-name/ test-cluster --read-timeout=60 -vv",
))
})

It("should apply the configured S3 addressing style", func(ctx SpecContext) {
storageConf.BarmanCredentials = barmanApi.BarmanCredentials{
AWS: &barmanApi.S3Credentials{InheritFromIAMRole: true},
}
storageConf.S3AddressingStyle = barmanApi.S3AddressingStyleVirtual

options, err := CloudWalRestoreOptions(ctx, storageConf, "test-cluster")
Expect(err).ToNot(HaveOccurred())
Expect(options).To(Equal([]string{
"--cloud-provider", "aws-s3",
"--addressing-style", "virtual",
"s3://bucket-name/", "test-cluster",
}))
})
})

var _ = Describe("useDefaultAzureCredentials", func() {
Expand Down Expand Up @@ -172,3 +187,33 @@ var _ = Describe("AppendCloudProviderOptions with Azure credentials", func() {
))
})
})

var _ = Describe("AppendCloudProviderOptionsFromConfiguration with S3 addressing", func() {
It("should replace an addressing style from command-specific arguments", func(ctx SpecContext) {
configuration := &barmanApi.BarmanObjectStoreConfiguration{
BarmanCredentials: barmanApi.BarmanCredentials{
AWS: &barmanApi.S3Credentials{InheritFromIAMRole: true},
},
S3AddressingStyle: barmanApi.S3AddressingStyleVirtual,
}

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

It("should reject an addressing style without S3 credentials", func(ctx SpecContext) {
configuration := &barmanApi.BarmanObjectStoreConfiguration{
S3AddressingStyle: barmanApi.S3AddressingStyleVirtual,
}

_, err := AppendCloudProviderOptionsFromConfiguration(ctx, nil, configuration)
Expect(err).To(MatchError("s3AddressingStyle requires s3Credentials"))
})
})
2 changes: 1 addition & 1 deletion pkg/credentials/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

barmanApi "github.com/cloudnative-pg/barman-cloud/pkg/api"
barmanApi "github.com/davidchandra95/barman-cloud/pkg/api"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions pkg/restorer/restorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
"github.com/cloudnative-pg/machinery/pkg/execlog"
"github.com/cloudnative-pg/machinery/pkg/log"

"github.com/cloudnative-pg/barman-cloud/pkg/spool"
"github.com/cloudnative-pg/barman-cloud/pkg/utils"
"github.com/davidchandra95/barman-cloud/pkg/spool"
"github.com/davidchandra95/barman-cloud/pkg/utils"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion pkg/walarchive/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/cloudnative-pg/machinery/pkg/fileutils"
"github.com/cloudnative-pg/machinery/pkg/log"

"github.com/cloudnative-pg/barman-cloud/pkg/utils"
"github.com/davidchandra95/barman-cloud/pkg/utils"
)

// BarmanArchiver implements a WAL archiver based
Expand Down