Add dualstack option to S3 storage driver

Allow the storage driver to optionally use AWS SDK's dualstack mode.
This allows the registry to communicate with S3 in IPv6 environments.

Signed-off-by: Adam Kaplan <adam.kaplan@redhat.com>
This commit is contained in:
Adam Kaplan 2019-12-11 15:41:40 -05:00
parent 81a2d171ee
commit e2caaf9cba
3 changed files with 33 additions and 0 deletions

View file

@ -128,6 +128,7 @@ storage:
multipartcopymaxconcurrency: 100 multipartcopymaxconcurrency: 100
multipartcopythresholdsize: 33554432 multipartcopythresholdsize: 33554432
rootdirectory: /s3/object/name/prefix rootdirectory: /s3/object/name/prefix
usedualstack: false
swift: swift:
username: username username: username
password: password password: password

View file

@ -102,6 +102,7 @@ type DriverParameters struct {
UserAgent string UserAgent string
ObjectACL string ObjectACL string
SessionToken string SessionToken string
UseDualStack bool
} }
func init() { func init() {
@ -338,6 +339,23 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) {
objectACL = objectACLString objectACL = objectACLString
} }
useDualStackBool := false
useDualStack := parameters["usedualstack"]
switch useDualStack := useDualStack.(type) {
case string:
b, err := strconv.ParseBool(useDualStack)
if err != nil {
return nil, fmt.Errorf("the useDualStack parameter should be a boolean")
}
useDualStackBool = b
case bool:
useDualStackBool = useDualStack
case nil:
// do nothing
default:
return nil, fmt.Errorf("the useDualStack parameter should be a boolean")
}
sessionToken := "" sessionToken := ""
params := DriverParameters{ params := DriverParameters{
@ -360,6 +378,7 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) {
fmt.Sprint(userAgent), fmt.Sprint(userAgent),
objectACL, objectACL,
fmt.Sprint(sessionToken), fmt.Sprint(sessionToken),
useDualStackBool,
} }
return New(params) return New(params)
@ -421,6 +440,9 @@ func New(params DriverParameters) (*Driver, error) {
awsConfig.WithRegion(params.Region) awsConfig.WithRegion(params.Region)
awsConfig.WithDisableSSL(!params.Secure) awsConfig.WithDisableSSL(!params.Secure)
if params.UseDualStack {
awsConfig.UseDualStackEndpoint = endpoints.DualStackEndpointStateEnabled
}
if params.UserAgent != "" || params.SkipVerify { if params.UserAgent != "" || params.SkipVerify {
httpTransport := http.DefaultTransport httpTransport := http.DefaultTransport

View file

@ -42,6 +42,7 @@ func init() {
root, err := ioutil.TempDir("", "driver-") root, err := ioutil.TempDir("", "driver-")
regionEndpoint := os.Getenv("REGION_ENDPOINT") regionEndpoint := os.Getenv("REGION_ENDPOINT")
sessionToken := os.Getenv("AWS_SESSION_TOKEN") sessionToken := os.Getenv("AWS_SESSION_TOKEN")
useDualStack := os.Getenv("S3_USE_DUALSTACK")
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -80,6 +81,14 @@ func init() {
} }
} }
useDualStackBool := false
if useDualStack != "" {
useDualStackBool, err = strconv.ParseBool(useDualStack)
if err != nil {
return nil, err
}
}
parameters := DriverParameters{ parameters := DriverParameters{
accessKey, accessKey,
secretKey, secretKey,
@ -100,6 +109,7 @@ func init() {
driverName + "-test", driverName + "-test",
objectACL, objectACL,
sessionToken, sessionToken,
useDualStackBool,
} }
return New(parameters) return New(parameters)