-
Notifications
You must be signed in to change notification settings - Fork 84
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
Migrate to aws sdk v2 #397
Migrate to aws sdk v2 #397
Conversation
|
Welcome @michael-diggin! |
Hi @michael-diggin. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Hi @michael-diggin, Thanks for posting this PR! Can you squash the commits into a single commit? |
ba89676
to
4bf4845
Compare
Hey @jacobwolfaws, thanks for the quick review! I've squashed the two commits. |
/approve |
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.
PR largely lgtm, thank you for the contribution.
pkg/util/util.go
Outdated
func roundUpSize(volumeSizeBytes int64, allocationUnitBytes int64) int32 { | ||
return int32((volumeSizeBytes + allocationUnitBytes - 1) / allocationUnitBytes) |
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.
I think we can silently overflow with large inputs here.
Casting in several different places is rather confusing and increases the likelihood of bugs. If the expected output from this function is int32
, can we make sure that the inputs are also int32
?
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.
I agree, it was a bit confusing working on it.
The inputs should be int64 however, as they are volume sizes in bytes and provided as that type from the CSI API. The output is the number of allocationUnitBytes
needed to store volumeSizeBytes
(rounded up) and so will always fit in an int32 based on the set of inputs provided in this file. It could overflow if someone provided a very small number of bytes as an input, the smallest that is given is 1200 * 1024 * 1024 * 1024.
I've added a comment and altered the function name as well to hopefully make it more clear, let me know if you'd like me to have another go.
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.
ack - Thanks for letting us know about that pain point. I generally agree that we should make the minimal set of changes for the migration and not blow up the scope of this PR; maintainers of this repo ought to be aware of this and help with cleaning up the casting situation to prevent regressions in the future.
TLDR - CSI spec expects and returns values in int64
, for example:
int64 volume_capacity_bytes = 2;
but the SDK's expected input/output might be of typeint32
for some attributes.
In other words, we need to work towards a state where minimal casting is done - preferably, all inputs are in int32
where needed, then a single cast to int64
is performed in a centralized place. That should be safe because int32
is implicitly convertible to int64
- every 32 bit int can be expressed as a 64 bit int, so there is no risk of silent overflows, etc.
cc: @jacobwolfaws
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.
Makes sense, thanks for the extra detail!
Just thinking, we could leave everything in RoundUpVolumeSize
in int64, there's only two uses of that function (https://github.com/kubernetes-sigs/aws-fsx-csi-driver/blob/master/pkg/driver/controller.go#L213 and https://github.com/kubernetes-sigs/aws-fsx-csi-driver/blob/master/pkg/driver/controller.go#L395). I could change it there such that they cast to int32 only in those locations, and even check if the number to cast doesn't exceed Math.MaxInt32
, with an error if it is?
Thanks for the review, I've replied to your comments and made a small update. Let me know what you think when you get another chance to review it. |
/approve Code looks good for migration. @michael-diggin @jacobwolfaws please manually test the scenario where IMDS is not available to validate that there are no regressions in expected behavior before this is released. The driver should successfully fall back to retrieving the needful information from k8s API without crashing. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: jacobwolfaws, michael-diggin, torredil The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Hi @michael-diggin @torredil, just catching up to this thread. |
12b460b
to
7a144b4
Compare
Done, thanks for offering to test it! |
Confirmed that this falls back to kubernetes api successfully when imds is disabled (also tested dynamic provisioning)
/lgtm |
Is this a bug fix or adding new feature?
Neither, changes all uses of
aws-sdk-go
toaws-sdk-go-v2
- resolves #385.What is this PR about? / Why do we need it?
As mentioned in #385, aws-sdk-go-v1 won't be receiving any more updates. Migrating to v2 allows for using newer features from FSx (eg AutoExportPolicy as mentioned in #255, this is something I need and is my motivation for this PR).
What testing is done?
make test
I've aimed to make as few changes to the interfaces as possible, hoping it's just a 'drop-in' replacement, following https://aws.github.io/aws-sdk-go-v2/docs/migrating/
Summary of changes
aws-sdk-go
->aws-sdk-go-v2
and addedaws-sdk-go-v2/config
,aws-sdk-go-v2/service/fsx
,aws-sdk-go-v2/feature/ec2/imds
to go.mod.aws-sdk-go-v2/service/fsx/types
, and enums are now used rather than strings in many of the structs.int64
toint32
. (This did mean I've changed the types of some of the fields in some of the public APIs egpkg/cloud/cloud.go FileSystem
, alternatively they could be kept as int64 and the uses could be converted to int32 where needed.)ec2metadata
is replaced byec2/imds
ec2/imds
in v2 doesn't have anAvailable()
function, however in v1 all that did was checkGetMetadata
, so I've implementedAvailable()
here following the same logic.