-
Notifications
You must be signed in to change notification settings - Fork 610
✨ Migrate ssm code to AWS SDK v2 #5529
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
base: main
Are you sure you want to change the base?
Conversation
Hi @miyadav. 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. |
acf1453
to
0082989
Compare
/test ? |
@miyadav: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
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. |
0082989
to
4b07844
Compare
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.
Thanks for taking this on! I've left a few comments. As Punkaj suggested, review the PRs that have merged before and try to follow their structure.
Clients should go in pkg/cloud/scope/clients.go
and the interfaces should go in pkg/cloud/services/<service name>/service.go
.
a5f6060
to
124624c
Compare
updated , thanks @punkwalker , @nrb . |
124624c
to
6d18363
Compare
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.
Requesting another round of changes.
pkg/cloud/services/ssm/service.go
Outdated
type SSMAPI interface { | ||
PutParameter(ctx context.Context, input *ssm.PutParameterInput, optFns ...func(*ssm.Options)) (*ssm.PutParameterOutput, error) | ||
DeleteParameter(ctx context.Context, input *ssm.DeleteParameterInput, optFns ...func(*ssm.Options)) (*ssm.DeleteParameterOutput, error) | ||
GetParameter(ctx context.Context, input *ssm.GetParameterInput, optFns ...func(*ssm.Options)) (*ssm.GetParameterOutput, error) | ||
// Add more methods as needed | ||
} | ||
|
||
// NewService returns a new service given the api clients. | ||
// SSMClientV2 is a concrete implementation of the SSMAPI interface using AWS SDK v2. | ||
// It wraps PutParameter for potential custom logic while using the AWS SDK directly for other methods. | ||
type SSMClientV2 struct { | ||
Client *ssm.Client | ||
} | ||
|
||
// PutParameter adds or overwrites a parameter in AWS SSM Parameter Store. | ||
// This method is wrapped to allow for custom error handling or retry logic if needed. | ||
func (c *SSMClientV2) PutParameter(ctx context.Context, input *ssm.PutParameterInput, optFns ...func(*ssm.Options)) (*ssm.PutParameterOutput, error) { | ||
if c.Client == nil { | ||
return nil, errors.New("SSM client is not initialized") | ||
} | ||
return c.Client.PutParameter(ctx, input, optFns...) | ||
} | ||
|
||
// DeleteParameter deletes a parameter from AWS SSM Parameter Store. | ||
func (c *SSMClientV2) DeleteParameter(ctx context.Context, input *ssm.DeleteParameterInput, optFns ...func(*ssm.Options)) (*ssm.DeleteParameterOutput, error) { | ||
return c.Client.DeleteParameter(ctx, input, optFns...) | ||
} | ||
|
||
// GetParameter retrieves a parameter from AWS SSM Parameter Store. | ||
func (c *SSMClientV2) GetParameter(ctx context.Context, input *ssm.GetParameterInput, optFns ...func(*ssm.Options)) (*ssm.GetParameterOutput, error) { | ||
return c.Client.GetParameter(ctx, input, optFns...) | ||
} |
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.
@miyadav Any reason you still want to wrap the AWS SDK ssm client into custom struct? As I see, we do not have any custom logic per se in PutParameter
, DeleteParameter
or GetParameter
. I feel we can do this in future if really required.
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 might have missed to push the change properly , after making changes earlier , some ec2 tests were failing , reason might be incomplete changes , so this got reverted , I am working on it now .
func isErrorRetryable(err error, retryableCodes []string) bool { | ||
// Use the ParseSmithyError utility to parse the error | ||
smithyErr := awserrors.ParseSmithyError(err) | ||
if smithyErr == nil { | ||
return false | ||
} | ||
|
||
// Get the error code from the parsed error | ||
codeToCheck := smithyErr.ErrorCode() | ||
|
||
// Compare the extracted string with your list | ||
for _, code := range retryableCodes { | ||
if codeToCheck == code { | ||
return true // It's a match! | ||
} | ||
} | ||
return false | ||
} | ||
|
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.
Thanks @punkwalker , but , I am using ParseSmithyError from the awserrors package in the isErrorRetryable function, my intent was to rely on the centralized logic in ParseSmithyError , let me know if I have misunderstood , your comment.
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 guess I was looking at wrong commit!
1.Since ssm interface provided earlier is removed , new is now at pkg/cloud/services/ssm/service.go. 2.Modified client code for ssm client pkg/cloud/scope/clients.go. 3.In the ec2 package updated references of aws-sdk-go/ssm to point to aws-sdk-go-v2/ssm. 4.Types provided by aws-sdk-go-v2/ssm/types pacakage updated in ec2 (launchtemplate_test.go,ami.go,ami_test.go).
…dle in ssm/service as well)
… failed ,updated method signatures for tests to pass
func isErrorRetryable(err error, retryableCodes []string) bool { | ||
// Use the ParseSmithyError utility to parse the error | ||
smithyErr := awserrors.ParseSmithyError(err) | ||
if smithyErr == nil { | ||
return false | ||
} | ||
|
||
// Get the error code from the parsed error | ||
codeToCheck := smithyErr.ErrorCode() | ||
|
||
// Compare the extracted string with your list | ||
for _, code := range retryableCodes { | ||
if codeToCheck == code { | ||
return true // It's a match! | ||
} | ||
} | ||
return false | ||
} | ||
|
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.
Thanks @punkwalker , but , I am using ParseSmithyError from the awserrors package in the isErrorRetryable function, my intent was to rely on the centralized logic in ParseSmithyError , let me know if I have misunderstood , your comment.
a01df82
to
9b0502a
Compare
9b0502a
to
ab9a661
Compare
/test pull-cluster-api-provider-aws-e2e-blocking |
/test pull-cluster-api-provider-aws-build-docker |
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.
LGTM 🚀
/test pull-cluster-api-provider-aws-e2e |
/test pull-cluster-api-provider-aws-e2e |
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.
LGTM label has been added. Git tree hash: 30f2438df768fe37b39adcfe226249799ec0a67c
|
/test pull-cluster-api-provider-aws-build-docker |
2 similar comments
/test pull-cluster-api-provider-aws-build-docker |
/test pull-cluster-api-provider-aws-build-docker |
What type of PR is this?
/kind feature
/kind cleanup
What this PR does / why we need it:
Migrates ssm code to AWS SDK v2
Which issue(s) this PR fixes (optional, in fixes #(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #5412
Special notes for your reviewer:
Checklist:
squashed commits
includes documentation
includes emoji in title
adds unit tests
adds or updates e2e tests
Release note: