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
3 changes: 3 additions & 0 deletions charts/rancher-backup-crd/templates/backup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ spec:
s3:
nullable: true
properties:
bucketLookupType:
nullable: true
type: string
bucketName:
nullable: true
type: string
Expand Down
3 changes: 3 additions & 0 deletions charts/rancher-backup-crd/templates/restore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ spec:
s3:
nullable: true
properties:
bucketLookupType:
nullable: true
type: string
bucketName:
nullable: true
type: string
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/resources.cattle.io/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type S3ObjectStore struct {
Region string `json:"region"`
Folder string `json:"folder"`
ClientConfig *ClientConfig `json:"clientConfig,omitempty"`
BucketLookupType string `json:"bucketLookupType,omitempty"`
}

// +genclient
Expand Down
14 changes: 11 additions & 3 deletions pkg/objectstore/s3minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ type ObjectStore struct {
Region string `json:"region"`
Folder string `json:"folder"`
// TODO: this may need to be a string too
ClientConfig *v1.ClientConfig `json:"clientConfig,omitempty"`
ClientConfig *v1.ClientConfig `json:"clientConfig,omitempty"`
BucketLookupType string `json:"bucketLookupType,omitempty"`
}

// Almost everything in this file is from rke-tools with some modifications https://github.com/rancher/rke-tools/blob/master/main.go
Expand All @@ -59,13 +60,14 @@ func SetS3Service(bc *v1.S3ObjectStore, accessKeyID, secretKey string, useSSL bo
"s3-endpoint-ca": bc.EndpointCA,
"s3-folder": bc.Folder,
"insecure-tls-skip-verify": bc.InsecureTLSSkipVerify,
"bucket-lookup-type": bc.BucketLookupType,
}).Info("invoking set s3 service client")

var err error
var client = &minio.Client{}
var cred credentials.Credentials
var tr = http.DefaultTransport
bucketLookup := getBucketLookupType(bc.Endpoint)
bucketLookup := getBucketLookupType(bc.Endpoint, bc.BucketLookupType)
for retries := 0; retries <= s3ServerRetries; retries++ {
// if the s3 access key and secret is not set use iam role
if len(accessKeyID) == 0 && len(secretKey) == 0 {
Expand Down Expand Up @@ -177,10 +179,16 @@ func GetS3Client(ctx context.Context, objectStore *v1.S3ObjectStore, dynamicClie
return s3Client, nil
}

func getBucketLookupType(endpoint string) minio.BucketLookupType {
func getBucketLookupType(endpoint, lookupType string) minio.BucketLookupType {
if endpoint == "" {
return minio.BucketLookupAuto
}
switch strings.ToLower(lookupType) {
case "dns":
return minio.BucketLookupDNS
case "path":
return minio.BucketLookupPath
}
if strings.Contains(endpoint, "aliyun") {
return minio.BucketLookupDNS
}
Expand Down