diff --git a/charts/rancher-backup-crd/templates/backup.yaml b/charts/rancher-backup-crd/templates/backup.yaml index 3f936cbb..c24403ec 100644 --- a/charts/rancher-backup-crd/templates/backup.yaml +++ b/charts/rancher-backup-crd/templates/backup.yaml @@ -59,6 +59,9 @@ spec: s3: nullable: true properties: + bucketLookupType: + nullable: true + type: string bucketName: nullable: true type: string diff --git a/charts/rancher-backup-crd/templates/restore.yaml b/charts/rancher-backup-crd/templates/restore.yaml index 3da422f7..9d7842c6 100644 --- a/charts/rancher-backup-crd/templates/restore.yaml +++ b/charts/rancher-backup-crd/templates/restore.yaml @@ -49,6 +49,9 @@ spec: s3: nullable: true properties: + bucketLookupType: + nullable: true + type: string bucketName: nullable: true type: string diff --git a/pkg/apis/resources.cattle.io/v1/types.go b/pkg/apis/resources.cattle.io/v1/types.go index 342a21e3..ca305430 100644 --- a/pkg/apis/resources.cattle.io/v1/types.go +++ b/pkg/apis/resources.cattle.io/v1/types.go @@ -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 diff --git a/pkg/objectstore/s3minio.go b/pkg/objectstore/s3minio.go index 2509b6e2..86bea05f 100644 --- a/pkg/objectstore/s3minio.go +++ b/pkg/objectstore/s3minio.go @@ -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 @@ -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 { @@ -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 }