Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

Commit

Permalink
pkg/*: Add option to force path style s3 uploads.
Browse files Browse the repository at this point in the history
This patch adds an option to force path style s3 uploads. This is useful
when a third-party s3 endpoint doesn't support the subdomain style
uploads that's default in s3.
  • Loading branch information
ainmosni authored and hexfusion committed Jan 11, 2019
1 parent cb35c2d commit aeb3e3e
Show file tree
Hide file tree
Showing 39 changed files with 55 additions and 39 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

### Added

- Added `spec.BackupSource.S3.ForcePathStyle` to `EtcdBackup` to force path style s3 uploads. [#2036](https://github.com/coreos/etcd-operator/pull/2036)
- Added `spec.RestoreSource.S3.ForcePathStyle` to `EtcdRestore` to force path style s3 downloads. [#2036](https://github.com/coreos/etcd-operator/pull/2036)

### Changed

### Removed
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/etcd/v1beta2/backup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ type S3BackupSource struct {
// Endpoint if blank points to aws. If specified, can point to s3 compatible object
// stores.
Endpoint string `json:"endpoint,omitempty"`

// ForcePathStyle forces to use path style over the default subdomain style.
// This is useful when you have an s3 compatible endpoint that doesn't support
// subdomain buckets.
ForcePathStyle bool `json:"forcePathStyle"`
}

// ABSBackupSource provides the spec how to store backups on ABS.
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/etcd/v1beta2/restore_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ type S3RestoreSource struct {
// Endpoint if blank points to aws. If specified, can point to s3 compatible object
// stores.
Endpoint string `json:"endpoint"`

// ForcePathStyle forces to use path style over the default subdomain style.
// This is useful when you have an s3 compatible endpoint that doesn't support
// subdomain buckets.
ForcePathStyle bool `json:"forcePathStyle"`
}

type ABSRestoreSource struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/etcd/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/controller/backup-operator/s3_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
// handleS3 saves etcd cluster's backup to specificed S3 path.
func handleS3(ctx context.Context, kubecli kubernetes.Interface, s *api.S3BackupSource, endpoints []string, clientTLSSecret, namespace string) (*api.BackupStatus, error) {
// TODO: controls NewClientFromSecret with ctx. This depends on upstream kubernetes to support API calls with ctx.
cli, err := s3factory.NewClientFromSecret(kubecli, namespace, s.Endpoint, s.AWSSecret)
cli, err := s3factory.NewClientFromSecret(kubecli, namespace, s.Endpoint, s.AWSSecret, s.ForcePathStyle)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/restore-operator/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (r *Restore) serveBackup(w http.ResponseWriter, req *http.Request) error {
return errors.New("invalid s3 restore source field (spec.s3), must specify all required subfields")
}

s3Cli, err := s3factory.NewClientFromSecret(r.kubecli, r.namespace, s3RestoreSource.Endpoint, s3RestoreSource.AWSSecret)
s3Cli, err := s3factory.NewClientFromSecret(r.kubecli, r.namespace, s3RestoreSource.Endpoint, s3RestoreSource.AWSSecret, s3RestoreSource.ForcePathStyle)
if err != nil {
return fmt.Errorf("failed to create S3 client: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/generated/clientset/versioned/clientset.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/generated/clientset/versioned/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/generated/clientset/versioned/fake/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/generated/clientset/versioned/fake/register.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/generated/clientset/versioned/scheme/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/generated/clientset/versioned/scheme/register.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/generated/informers/externalversions/etcd/interface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/generated/informers/externalversions/factory.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/generated/informers/externalversions/generic.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/generated/listers/etcd/v1beta2/etcdbackup.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/generated/listers/etcd/v1beta2/etcdcluster.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/generated/listers/etcd/v1beta2/etcdrestore.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/generated/listers/etcd/v1beta2/expansion_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions pkg/util/awsutil/s3factory/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type S3Client struct {
}

// NewClientFromSecret returns a S3 client based on given k8s secret containing aws credentials.
func NewClientFromSecret(kubecli kubernetes.Interface, namespace, endpoint, awsSecret string) (w *S3Client, err error) {
func NewClientFromSecret(kubecli kubernetes.Interface, namespace, endpoint, awsSecret string, forcePathStyle bool) (w *S3Client, err error) {
defer func() {
if err != nil {
err = fmt.Errorf("new S3 client failed: %v", err)
Expand All @@ -50,7 +50,7 @@ func NewClientFromSecret(kubecli kubernetes.Interface, namespace, endpoint, awsS
if err != nil {
return nil, fmt.Errorf("failed to create aws config dir: (%v)", err)
}
so, err := setupAWSConfig(kubecli, namespace, awsSecret, endpoint, w.configDir)
so, err := setupAWSConfig(kubecli, namespace, awsSecret, endpoint, w.configDir, forcePathStyle)
if err != nil {
return nil, fmt.Errorf("failed to setup aws config: (%v)", err)
}
Expand All @@ -68,13 +68,15 @@ func (w *S3Client) Close() {
}

// setupAWSConfig setup local AWS config/credential files from Kubernetes aws secret.
func setupAWSConfig(kubecli kubernetes.Interface, ns, secret, endpoint, configDir string) (*session.Options, error) {
func setupAWSConfig(kubecli kubernetes.Interface, ns, secret, endpoint, configDir string, forcePathStyle bool) (*session.Options, error) {
options := &session.Options{}
options.SharedConfigState = session.SharedConfigEnable

// empty string defaults to aws
options.Config.Endpoint = &endpoint

options.Config.S3ForcePathStyle = &forcePathStyle

se, err := kubecli.CoreV1().Secrets(ns).Get(secret, metav1.GetOptions{})
if err != nil {
return nil, fmt.Errorf("setup AWS config failed: get k8s secret failed: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/awsutil/s3factory/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestSetupAWSConfig(t *testing.T) {
client := fake.NewSimpleClientset(sec)

e := "example.com"
opts, err := setupAWSConfig(client, "", "", e, "")
opts, err := setupAWSConfig(client, "", "", e, "", false)
if err != nil {
t.Error(err)
}
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/e2eutil/spec_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ func NewS3Backup(endpoints []string, clusterName, path, secret, clientTLSSecret
ClientTLSSecret: clientTLSSecret,
BackupSource: api.BackupSource{
S3: &api.S3BackupSource{
Path: path,
AWSSecret: secret,
Path: path,
AWSSecret: secret,
ForcePathStyle: false,
},
},
},
Expand Down

0 comments on commit aeb3e3e

Please sign in to comment.