diff --git a/pkg/controllers/common/fileservice.go b/pkg/controllers/common/fileservice.go index 8ed94c0f..2e0d426d 100644 --- a/pkg/controllers/common/fileservice.go +++ b/pkg/controllers/common/fileservice.go @@ -153,6 +153,9 @@ func sharedFileServiceConfig(sp v1alpha1.SharedStorageProvider, cache *v1alpha1. // TODO: let AWS SDK discover its own endpoint by default s3Config["endpoint"] = "s3.us-west-2.amazonaws.com" } + if s3.Region != "" { + s3Config["region"] = s3.Region + } paths := strings.SplitN(strings.Trim(s3.Path, "/"), "/", 2) s3Config["bucket"] = paths[0] keyPrefix := subDir diff --git a/pkg/controllers/common/fileservice_test.go b/pkg/controllers/common/fileservice_test.go index a81c075c..bccb4f9b 100644 --- a/pkg/controllers/common/fileservice_test.go +++ b/pkg/controllers/common/fileservice_test.go @@ -40,7 +40,8 @@ func TestFileServiceConfig(t *testing.T) { localPath: "/test", sp: v1alpha1.SharedStorageProvider{ S3: &v1alpha1.S3Provider{ - Path: "bucket/prefix", + Path: "bucket/prefix", + Region: "ap-shanghai", SecretRef: &corev1.LocalObjectReference{ Name: "aws", }, @@ -62,6 +63,7 @@ func TestFileServiceConfig(t *testing.T) { }, "s3": map[string]interface{}{ "endpoint": "s3.us-west-2.amazonaws.com", + "region": "ap-shanghai", "key-prefix": "prefix/data", "bucket": "bucket", }, @@ -73,6 +75,7 @@ func TestFileServiceConfig(t *testing.T) { }, "s3": map[string]interface{}{ "endpoint": "s3.us-west-2.amazonaws.com", + "region": "ap-shanghai", "key-prefix": "prefix/etl", "bucket": "bucket", }, @@ -137,3 +140,34 @@ func TestFileServiceConfig(t *testing.T) { }) } } + +func TestLogServiceFSConfigWithS3Region(t *testing.T) { + sp := v1alpha1.SharedStorageProvider{ + S3: &v1alpha1.S3Provider{ + Path: "bucket", + Region: "ap-shanghai", + }, + } + want := map[string]interface{}{ + "data-dir": "/test", + "fileservice": []map[string]interface{}{ + { + "name": BackupFileServiceName, + "backend": fsBackendTypeS3, + "s3": map[string]interface{}{ + "endpoint": "s3.us-west-2.amazonaws.com", + "region": "ap-shanghai", + "bucket": "bucket", + "key-prefix": "", + }, + "cache": map[string]interface{}{ + "memory-capacity": "1B", + }, + }, + }, + } + + if diff := cmp.Diff(want, LogServiceFSConfig("/test", sp)); diff != "" { + t.Errorf("LogServiceFSConfig(), diff:\n %s", diff) + } +}