Use custom endpoint in detectBucketLocation
What does this MR do?
detectBucketLocation was creating its S3 client with no endpoint options, so GetBucketLocation always hit the default AWS S3 endpoint regardless of the configured ServerAddress. For users with a custom endpoint (e.g. MinIO, regional endpoints), this caused the location detection call to time out against the wrong host, ultimately falling back to us-east-1 and potentially routing requests to the wrong region.
Pass the full CacheS3Config to detectBucketLocation so it can apply he same custom endpoint and path-style settings as the main client.
Why was this MR needed?
To speed up bucket detection on third-party S3 servers.
What's the best way to test this MR?
- Configure the runner to talk to a local Minio server. I ran:
docker run -d \
-p 9000:9000 \
-p 9001:9001 \
--name minio \
-e "MINIO_ROOT_USER=minioadmin" \
-e "MINIO_ROOT_PASSWORD=minioadmin" \
-v /mnt/data:/data \
quay.io/minio/minio server /data --console-address ":9001"
- Create a bucket:
docker exec -it minio bash
mc alias set myminio http://localhost:9000 minioadmin minioadmin
mc mb myminio/my-bucket-name
- Configure your runner with a shell executor to talk to this bucket without a `BucketLocation:
[runners.cache]
Type = "s3"
MaxUploadedArchiveSize = 0
[runners.cache.s3]
BucketName = "my-bucket-name"
ServerAddress = "localhost:9000"
AccessKey = "minioadmin"
SecretKey = "minioadmin"
Insecure = true
- Add this debugging:
diff --git a/cache/s3v2/s3.go b/cache/s3v2/s3.go
index a02beab98..4d2f0ec51 100644
--- a/cache/s3v2/s3.go
+++ b/cache/s3v2/s3.go
@@ -353,6 +353,8 @@ func detectBucketLocation(s3Config *cacheconfig.CacheS3Config, optFuncs ...func(
Bucket: aws.String(s3Config.BucketName),
})
+ fmt.Printf("=== GetBucketLocation response: %v, err = %v\n", output, err)
+
switch {
case err != nil || output.LocationConstraint == "":
return fallbackBucketLocation
- In
main, you will see the runner trying to talk to AWS:
=== GetBucketLocation response: <nil>, err = operation error S3: GetBucketLocation, https response error StatusCode: 403, RequestID: EZXQ7TX411RSWN4H, HostID: t2/y830duYKVpw3+dkRfMxXLrMqBr4ZgXQtlCodKvV9bes3AnqoD9yplIYEm+rcbRvl6HSSA0PIzyqYpDRzKQFcbBL9j1avN, api error InvalidAccessKeyId: The AWS Access Key Id you provided does not exist in our records.
With this branch, you should see no error:
=== GetBucketLocation response: &{ {map[{}:-605731879 {}:0xc0000b2b80 {}:189F9A167E3DE1C6 {}:{14008603621522586663 7814601810 0x660c860} {}:{0 63909902999 <nil>} {}:{[{<nil> false false {map[{}:-605731879 {}:0xc0000b2b80 {}:189F9A167E3DE1C6 {}:{14008603621522586663 7814601810 0x660c860} {}:{0 63909902999 <nil>} {}:dd9025bab4ad464b049177c95eb6ebf374d3b3fd1af92
51148b658df7ac2e3e8]}}]} {}:dd9025bab4ad464b049177c95eb6ebf374d3b3fd1af9251148b658df7ac2e3e8]} {}}, err = <nil>
What are the relevant issue numbers?
Relates to #39279 (closed)
Edited by Stan Hu