-
Notifications
You must be signed in to change notification settings - Fork 204
update: support to wait to update function #4565
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
update: support to wait to update function #4565
Conversation
c9502f9 to
4380779
Compare
| "github.com/aws/aws-sdk-go-v2/service/lambda/types" | ||
| "go.uber.org/zap" | ||
|
|
||
| helper "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" |
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.
Let's not use hashicorp retry but pipecd package 👀
ref: https://github.com/pipe-cd/pipecd/blob/master/pkg/backoff/backoff.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.
I use retry package to get lambda function state.
a82e690 to
f20ea30
Compare
Codecov ReportPatch coverage has no change and project coverage change:
Additional details and impacted files@@ Coverage Diff @@
## master #4565 +/- ##
==========================================
- Coverage 29.91% 29.88% -0.03%
==========================================
Files 220 220
Lines 25873 25892 +19
==========================================
- Hits 7741 7739 -2
- Misses 17484 17506 +22
+ Partials 648 647 -1
☔ View full report in Codecov by Sentry. |
f20ea30 to
def49fe
Compare
|
@khanhtc1202 @kentakozuka |
|
@sivchari Could you remove grpc update and go packages update from this PR 👀 |
| retry := backoff.NewRetry(RequestRetryTime, backoff.NewConstant(RetryIntervalDuration)) | ||
| input := &lambda.GetFunctionInput{ | ||
| FunctionName: aws.String(functionName), | ||
| } | ||
| if _, err := retry.Do(ctx, func() (any, error) { | ||
| output, err := c.client.GetFunction(ctx, input) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if output.Configuration.LastUpdateStatus != types.LastUpdateStatusSuccessful { | ||
| return nil, fmt.Errorf("failed to update Lambda function %s, status code %v, error reason %s", | ||
| functionName, output.Configuration.LastUpdateStatus, *output.Configuration.LastUpdateStatusReason) | ||
| } | ||
| return nil, nil | ||
| }); err != nil { | ||
| return err | ||
| } |
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.
| retry := backoff.NewRetry(RequestRetryTime, backoff.NewConstant(RetryIntervalDuration)) | |
| input := &lambda.GetFunctionInput{ | |
| FunctionName: aws.String(functionName), | |
| } | |
| if _, err := retry.Do(ctx, func() (any, error) { | |
| output, err := c.client.GetFunction(ctx, input) | |
| if err != nil { | |
| return nil, err | |
| } | |
| if output.Configuration.LastUpdateStatus != types.LastUpdateStatusSuccessful { | |
| return nil, fmt.Errorf("failed to update Lambda function %s, status code %v, error reason %s", | |
| functionName, output.Configuration.LastUpdateStatus, *output.Configuration.LastUpdateStatusReason) | |
| } | |
| return nil, nil | |
| }); err != nil { | |
| return err | |
| } | |
| input := &lambda.GetFunctionInput{ | |
| FunctionName: aws.String(functionName), | |
| } | |
| retry := backoff.NewRetry(RequestRetryTime, backoff.NewConstant(RetryIntervalDuration)) | |
| _, err := retry.Do(ctx, func() (interface{}, error) { | |
| output, err := c.client.GetFunction(ctx, input) | |
| if err != nil { | |
| return nil, err | |
| } | |
| if output.Configuration.LastUpdateStatus != types.LastUpdateStatusSuccessful { | |
| return nil, fmt.Errorf("failed to get Lambda function %s, status code %v, error reason %s", | |
| functionName, output.Configuration.LastUpdateStatus, *output.Configuration.LastUpdateStatusReason) | |
| } | |
| return nil, nil | |
| }) | |
| return err | |
| } |
How about this?
| return nil | ||
| } | ||
|
|
||
| func (c *client) waitFunctionUpdated(ctx context.Context, functionName string, timeout time.Duration) error { |
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.
this timeout is not being used
9b0afdb to
f645600
Compare
|
@khanhtc1202 |
|
btw, @sivchari due to the comment here |
Signed-off-by: sivchari <[email protected]>
f645600 to
91f0475
Compare
|
@khanhtc1202 |
| // Update function configuration. | ||
| if err := c.updateFunctionConfiguration(ctx, fm); err != nil { | ||
| return err | ||
| } | ||
|
|
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.
Probably should be at the top of this function (before L230 reading zip) to avoid unnecessary disk read if the update function configuration returns error.
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.
You're right. Thnaks.
6a6e441 to
5f278a9
Compare
| return nil | ||
| } | ||
|
|
||
| func (c *client) waitFunctionUpdated(ctx context.Context, functionName string) error { |
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.
How about moving this function body to L298? Looks like this function is specified to be used only by updateFunctionConfiguration, so I don't think we have enough reason to separate it as an independent function 🤔 Also, the current function name is quite common, waitFunctionUpdated while we have many UpdateFunctionXXX, which could cause misleading. So removing this function and moving all of its body to be part of updateFunctionConfiguration could be a better choice if you only want to wait after updating function configuration. wdyt?
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.
Okay.
Also, the current function name is quite common, waitFunctionUpdated while we have many UpdateFunctionXXX, which could cause misleading.
I thinks so too.
5f278a9 to
c577c6e
Compare
khanhtc1202
left a 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.
Look neat, just left nits comments 😀
| if err != nil { | ||
| return err | ||
| } | ||
| return nil |
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.
return errnits
c577c6e to
32f955b
Compare
| input := &lambda.GetFunctionInput{ | ||
| FunctionName: aws.String(fm.Spec.Name), | ||
| } | ||
| _, err = retry.Do(ctx, func() (any, error) { |
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.
Sorry, I just noticed that we reused the previous retry object here. I think we should recreate a new one instead since the same object may contain previously updated backoff internal, thus the number of retry times is not as expected.
| _, err = retry.Do(ctx, func() (any, error) { | |
| retry = backoff.NewRetry(RequestRetryTime, backoff.NewConstant(RetryIntervalDuration)) | |
| _, err = retry.Do(ctx, func() (any, error) { |
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.
@khanhtc1202
I fixed it.
|
@sivchari After this got merge, I will release v0.45.3-rc1 then you can test it before we make release v0.45.3 😄 |
Signed-off-by: sivchari <[email protected]>
32f955b to
e3ed289
Compare
khanhtc1202
left a 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.
LGTM, thanks 🍏
* update: support to wait to update function Signed-off-by: sivchari <[email protected]> * rearrange: updatefunctionfromsource Signed-off-by: sivchari <[email protected]> --------- Signed-off-by: sivchari <[email protected]>
* update: support to wait to update function (#4565) * update: support to wait to update function Signed-off-by: sivchari <[email protected]> * rearrange: updatefunctionfromsource Signed-off-by: sivchari <[email protected]> --------- Signed-off-by: sivchari <[email protected]> * Wait ECS taskset stable (#4573) * Wait ECS taskset stable Signed-off-by: khanhtc1202 <[email protected]> * Change number of retry time Signed-off-by: khanhtc1202 <[email protected]> * No sleep required Signed-off-by: khanhtc1202 <[email protected]> --------- Signed-off-by: khanhtc1202 <[email protected]> --------- Signed-off-by: sivchari <[email protected]> Signed-off-by: khanhtc1202 <[email protected]> Co-authored-by: sivchari <[email protected]>
* update: support to wait to update function Signed-off-by: sivchari <[email protected]> * rearrange: updatefunctionfromsource Signed-off-by: sivchari <[email protected]> --------- Signed-off-by: sivchari <[email protected]> Signed-off-by: moko-poi <[email protected]>
* update: support to wait to update function Signed-off-by: sivchari <[email protected]> * rearrange: updatefunctionfromsource Signed-off-by: sivchari <[email protected]> --------- Signed-off-by: sivchari <[email protected]>
What this PR does / why we need it:
Last patch. I support to wait to update lambda function.
If lambda function state is pending, UpdateFunctionCode is failed. So I check the lambda satate.
Which issue(s) this PR fixes:
Fixes #
Does this PR introduce a user-facing change?: