Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions pkg/app/piped/platformprovider/lambda/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ func (c *client) UpdateFunction(ctx context.Context, fm FunctionManifest) error
}

func (c *client) UpdateFunctionFromSource(ctx context.Context, fm FunctionManifest, zip io.Reader) error {
// Update function configuration.
if err := c.updateFunctionConfiguration(ctx, fm); err != nil {
return err
}

data, err := io.ReadAll(zip)
if err != nil {
return err
Expand All @@ -249,11 +254,6 @@ func (c *client) UpdateFunctionFromSource(ctx context.Context, fm FunctionManife
return fmt.Errorf("failed to update function code for Lambda function %s: %w", fm.Spec.Name, err)
}

// Update function configuration.
if err = c.updateFunctionConfiguration(ctx, fm); err != nil {
return err
}

// Tag/Untag function if necessary.
return c.updateTagsConfig(ctx, fm)
}
Expand Down Expand Up @@ -295,7 +295,24 @@ func (c *client) updateFunctionConfiguration(ctx context.Context, fm FunctionMan
if !updateFunctionConfigurationSucceed {
return fmt.Errorf("failed to update configuration for Lambda function %s: %w", fm.Spec.Name, err)
}
return nil

// Wait until function updated successfully.
retry = backoff.NewRetry(RequestRetryTime, backoff.NewConstant(RetryIntervalDuration))
input := &lambda.GetFunctionInput{
FunctionName: aws.String(fm.Spec.Name),
}
_, err = retry.Do(ctx, func() (any, error) {
Copy link
Member

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.

Suggested change
_, err = retry.Do(ctx, func() (any, error) {
retry = backoff.NewRetry(RequestRetryTime, backoff.NewConstant(RetryIntervalDuration))
_, err = retry.Do(ctx, func() (any, error) {

Copy link
Member Author

Choose a reason for hiding this comment

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

@khanhtc1202
I fixed it.

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",
fm.Spec.Name, output.Configuration.LastUpdateStatus, *output.Configuration.LastUpdateStatusReason)
}
return nil, nil
})
return err
}

func (c *client) PublishFunction(ctx context.Context, fm FunctionManifest) (string, error) {
Expand Down