Skip to content
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 aws sdk go v1 to v2 #3844

Merged
merged 9 commits into from
Sep 24, 2024
Merged

Conversation

shraddhabang
Copy link
Collaborator

@shraddhabang shraddhabang commented Sep 5, 2024

Issue

#3784

Description

As AWS SDK for GO v1 has gone into maintenance mode, this PR migrates the AWS SDK for GO v1 to v2

The migration includes the following key changes:

Updated dependencies: The go.mod file has been modified to use the AWS SDK for Go v2 dependencies.
Package imports: All imports referencing the v1 SDK have been updated to use the v2 packages.
Service clients: Service clients have been created using the NewFromConfig method in v2.
Waiters: The waiter functionality has been migrated to use the new waiter pattern in v2.
API calls: API calls have been updated to use the correct parameters and data types in v2.

Benefits:

Improved performance and efficiency: The AWS SDK for Go v2 offers performance enhancements and new features.
Enhanced security: The v2 SDK incorporates security best practices and addresses potential vulnerabilities.
Simplified usage: The v2 SDK provides a more intuitive and streamlined API.

Testing:

Unit tests: Unit tests have been updated to ensure the code works as expected with the v2 SDK.
Integration tests: Integration tests have been run to verify compatibility with other components of the application.

Please review the changes carefully and provide any feedback or suggestions

Checklist

  • Added tests that cover your change (if possible)
  • Added/modified documentation as required (such as the README.md, or the docs directory)
  • Manually tested
  • Made sure the title of the PR is a good description that can go into the release notes

BONUS POINTS checklist: complete for good vibes and maybe prizes?! 🤯

  • Backfilled missing tests for code in same general area 🎉
  • Refactored something and made the world a better place 🌟

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 5, 2024
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Sep 5, 2024
@shraddhabang shraddhabang changed the title [WIP] Migrate aws sdk go v1 to v2 Migrate aws sdk go v1 to v2 Sep 16, 2024
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 16, 2024
@shraddhabang
Copy link
Collaborator Author

/retest

@@ -106,6 +110,20 @@ func (p *suffixAnnotationParser) ParseInt64Annotation(annotation string, value *
return true, nil
}

func (p *suffixAnnotationParser) ParseInt32Annotation(annotation string, value *int32, annotations map[string]string, opts ...ParseOption) (bool, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this ParseInt32Annotation() in addition to ParseInt64Annotation()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theaws-sdk-v2 now migrated all the int64 types to int32. Hence to minimize the conversions after parsing. I have created a new parsing method.

pkg/aws/metrics/collector.go Show resolved Hide resolved
pkg/backend/endpoint_types.go Show resolved Hide resolved
pkg/deploy/elbv2/listener_utils.go Show resolved Hide resolved
pkg/deploy/elbv2/load_balancer_manager.go Show resolved Hide resolved
pkg/deploy/elbv2/target_group_manager.go Show resolved Hide resolved
pkg/deploy/elbv2/target_group_manager_test.go Show resolved Hide resolved
pkg/ingress/model_build_load_balancer.go Show resolved Hide resolved
pkg/networking/backend_sg_provider.go Show resolved Hide resolved
pkg/networking/node_eni_info_resolver.go Show resolved Hide resolved
@shraddhabang
Copy link
Collaborator Author

/retest

@shraddhabang
Copy link
Collaborator Author

/retest pull-aws-load-balancer-controller-e2e-test

@k8s-ci-robot
Copy link
Contributor

@shraddhabang: The /retest command does not accept any targets.
The following commands are available to trigger required jobs:

  • /test pull-aws-load-balancer-controller-e2e-test
  • /test pull-aws-load-balancer-controller-lint
  • /test pull-aws-load-balancer-controller-unit-2
  • /test pull-aws-load-balancer-controller-unit-3
  • /test pull-aws-load-balancer-controller-unit-4
  • /test pull-aws-load-balancer-controller-unit-test

Use /test all to run the following jobs that were automatically triggered:

  • pull-aws-load-balancer-controller-e2e-test
  • pull-aws-load-balancer-controller-lint
  • pull-aws-load-balancer-controller-unit-test

In response to this:

/retest pull-aws-load-balancer-controller-e2e-test

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.

@shraddhabang
Copy link
Collaborator Author

/test pull-aws-load-balancer-controller-e2e-test

@oliviassss
Copy link
Collaborator

/lgtm
/assign @M00nF1sh
sending for a second opinion from @M00nF1sh just in case, given it's a large change.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 20, 2024
if !exists {
return false, nil
}
i, err := strconv.ParseInt(raw, 10, 64)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be 32 instead of 64

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. :D

}
sess := session.Must(session.NewSessionWithOptions(opts))
injectUserAgent(&sess.Handlers)
awsConfig, err := config.LoadDefaultConfig(context.TODO(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. cfg.AWSEndpoints seems dropped support? It's a flag used to override api endpoints (e.g. FIPS ones).
  2. seems endpoints.RegionalSTSEndpoint is not explicitly specified, is it the default behavior of AWSSDKv2? We don't want to use global STS endpoint.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have verified that the GO SDK v2 uses regional STS endpoints by default. https://docs.aws.amazon.com/sdkref/latest/guide/feature-sts-regionalized-endpoints.html#:~:text=SDK%20for%20Go%20V2,Request%20failure

Good catch. I have added support for custom AWSEndpoints now in recent commit. Please take a look.

pkg/aws/cloud.go Outdated
if metricsRegisterer != nil {
metricsCollector, err := metrics.NewCollector(metricsRegisterer)
if err != nil {
return nil, errors.Wrapf(err, "failed to initialize sdk metrics collector")
}
metricsCollector.InjectHandlers(&sess.Handlers)
awsConfig.APIOptions = append(awsConfig.APIOptions, func(stack *smithymiddleware.Stack) error {
return metrics.WithSDKCallMetricCollector(metricsCollector)(stack)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd prefer to have a single method like WithSDKMetricsCollector instead of two. If we want to support optional collect either call/request metrics only, we can pass the setting into WithSDKMetricsCollector.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I have fixed this in recent commit

@M00nF1sh
Copy link
Collaborator

M00nF1sh commented Sep 20, 2024

left a few comments.
The major one that must change is aws-api-endpoints support is dropped. Which is needed for FIPS endpoint support.
The rest are minor one.

I'm ok to merge this into main branch and fix those via follow-up PR to unblock other changes (since we don't do releases from main).

@shraddhabang
Copy link
Collaborator Author

/test pull-aws-load-balancer-controller-e2e-test

1 similar comment
@shraddhabang
Copy link
Collaborator Author

/test pull-aws-load-balancer-controller-e2e-test

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 23, 2024
@oliviassss oliviassss added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Sep 23, 2024
@oliviassss
Copy link
Collaborator

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Sep 23, 2024
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 23, 2024
@shraddhabang
Copy link
Collaborator Author

/test pull-aws-load-balancer-controller-e2e-test

@oliviassss
Copy link
Collaborator

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 23, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: oliviassss, shraddhabang

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit 356c904 into kubernetes-sigs:main Sep 24, 2024
9 checks passed
zac-nixon pushed a commit to zac-nixon/aws-load-balancer-controller that referenced this pull request Oct 1, 2024
* Migrate aws sdk go v1 to v2

* Migrate aws sdk go v1 to v2

* Adding pending tasks

* Fix the endpoint ports to avoid reconciles

* Addressing Yang's comments

* Resolve merge conflicts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants