-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade MP and adding tests for S3 Express #90
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,8 @@ spec: | |
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"s3:*" | ||
"s3:*", | ||
"s3express:*" | ||
], | ||
"Resource": "*" | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,14 @@ package e2e | |
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/config" | ||
"github.com/aws/aws-sdk-go-v2/service/s3" | ||
"github.com/aws/aws-sdk-go-v2/service/s3/types" | ||
custom_testsuites "github.com/awslabs/aws-s3-csi-driver/tests/e2e-kubernetes/testsuites" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/s3" | ||
"github.com/aws/aws-sdk-go/service/s3/s3manager" | ||
v1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/util/sets" | ||
"k8s.io/apiserver/pkg/storage/names" | ||
|
@@ -16,6 +19,10 @@ import ( | |
"k8s.io/kubernetes/test/e2e/storage/framework" | ||
) | ||
|
||
const ( | ||
maxS3ExpressBucketNameLength = 63 | ||
) | ||
|
||
var ( | ||
CommitId string | ||
BucketRegion string // assumed to be the same as k8s cluster's region | ||
|
@@ -80,8 +87,44 @@ func (d *s3Driver) CreateVolume(ctx context.Context, config *framework.PerTestCo | |
bucketName := names.SimpleNameGenerator.GenerateName(fmt.Sprintf("%s-e2e-kubernetes-%s-", BucketPrefix, CommitId)) | ||
input := &s3.CreateBucketInput{ | ||
Bucket: aws.String(bucketName), | ||
// note: you need this if testing in non us-east-1 regions | ||
// CreateBucketConfiguration: &types.CreateBucketConfiguration{ | ||
// LocationConstraint: types.BucketLocationConstraint(BucketRegion), | ||
// }, | ||
} | ||
|
||
if config.Prefix == custom_testsuites.S3ExpressTestIdentifier { | ||
// assume us-east-1 since that's where our integration tests currently do their work | ||
// https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-express-networking.html | ||
regionAz := "use1-az4" | ||
if BucketRegion == "us-west-2" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm guessing this won't work for regions that aren't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yea I actually took a brief look into this but there's no programmatic way to see where S3 Express is supported, and right now the only NA regions it supports is us-east-1 and us-west-2, but agreed something to look into in the future |
||
regionAz = "usw2-az1" | ||
} | ||
// refer to s3 express bucket naming conventions | ||
// https://docs.aws.amazon.com/AmazonS3/latest/userguide/directory-bucket-naming-rules.html | ||
suffix := fmt.Sprintf("--%s--x-s3", regionAz) | ||
// s3 express doesn't allow non-virtually routable names | ||
bucketName = strings.Replace(bucketName, ".", "", -1) | ||
if len(bucketName)+len(suffix) > maxS3ExpressBucketNameLength { | ||
bucketName = strings.TrimRight(bucketName[:maxS3ExpressBucketNameLength-len(suffix)], "-") | ||
} | ||
bucketName = fmt.Sprintf("%s%s", bucketName, suffix) | ||
input = &s3.CreateBucketInput{ | ||
Bucket: aws.String(bucketName), | ||
CreateBucketConfiguration: &types.CreateBucketConfiguration{ | ||
Location: &types.LocationInfo{ | ||
Name: aws.String(regionAz), | ||
Type: types.LocationTypeAvailabilityZone, | ||
}, | ||
Bucket: &types.BucketInfo{ | ||
DataRedundancy: types.DataRedundancySingleAvailabilityZone, | ||
Type: types.BucketTypeDirectory, | ||
}, | ||
}, | ||
} | ||
} | ||
_, err := newS3Client().CreateBucket(input) | ||
f.Logf("Attempting to create bucket: %s", bucketName) | ||
_, err := newS3Client().CreateBucket(context.TODO(), input) | ||
f.ExpectNoError(err) | ||
f.Logf("Created bucket: %s", bucketName) | ||
return &s3Volume{bucketName: bucketName} | ||
|
@@ -100,23 +143,36 @@ func (d *s3Driver) GetPersistentVolumeSource(readOnly bool, fsType string, testV | |
|
||
func (v *s3Volume) DeleteVolume(ctx context.Context) { | ||
s3Client := newS3Client() | ||
// delete all objects from a bucket | ||
iter := s3manager.NewDeleteListIterator(s3Client, &s3.ListObjectsInput{ | ||
objects, err := s3Client.ListObjectsV2(context.TODO(), &s3.ListObjectsV2Input{ | ||
Bucket: aws.String(v.bucketName), | ||
}) | ||
err := s3manager.NewBatchDeleteWithClient(s3Client).Delete(aws.BackgroundContext(), iter) | ||
f.ExpectNoError(err) | ||
var objectIds []types.ObjectIdentifier | ||
// get all object keys in the s3 bucket | ||
for _, obj := range objects.Contents { | ||
objectIds = append(objectIds, types.ObjectIdentifier{Key: obj.Key}) | ||
} | ||
// delete all objects from the bucket | ||
if len(objectIds) > 0 { | ||
_, err = s3Client.DeleteObjects(context.TODO(), &s3.DeleteObjectsInput{ | ||
Bucket: aws.String(v.bucketName), | ||
Delete: &types.Delete{Objects: objectIds}, | ||
}) | ||
f.ExpectNoError(err) | ||
} | ||
// finally delete the bucket | ||
input := &s3.DeleteBucketInput{ | ||
Bucket: aws.String(v.bucketName), | ||
} | ||
_, err = s3Client.DeleteBucket(input) | ||
_, err = s3Client.DeleteBucket(context.TODO(), input) | ||
f.ExpectNoError(err) | ||
f.Logf("Deleted bucket: %s", v.bucketName) | ||
} | ||
|
||
func newS3Client() *s3.S3 { | ||
session, err := session.NewSession(&aws.Config{Region: aws.String(BucketRegion)}) | ||
func newS3Client() *s3.Client { | ||
cfg, err := config.LoadDefaultConfig(context.TODO(), | ||
config.WithRegion(BucketRegion), | ||
) | ||
f.ExpectNoError(err) | ||
return s3.New(session) | ||
return s3.NewFromConfig(cfg) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the swap here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unintentional, I had removed it in a previous commit to test kops only and then added it back in but in reverse order