Skip to content

Adding ProvisionedConcurrency Support for Alias #97

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

Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions apis/v1alpha1/ack-generate-metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
ack_generate_info:
build_date: "2023-07-17T23:54:05Z"
build_date: "2023-07-24T18:19:28Z"
build_hash: e9b68590da73ce9143ba1e4361cebdc1d876c81e
go_version: go1.20.5
go_version: go1.19
version: v0.26.1-7-ge9b6859
api_directory_checksum: 5d5c7aea8863c47e7303cc870aad4250267d93d2
api_directory_checksum: 8f80588f678cbcff979aa67cf82e547315fdb2b8
api_version: v1alpha1
aws_sdk_go_version: v1.44.181
generator_config_info:
file_checksum: a3a0fb7f87067244de99c0b37aaaf917b026f03d
file_checksum: 8b0c7bd625c74c9a471db45bbf8697069d35b218
original_file_name: generator.yaml
last_modification:
reason: API generation
6 changes: 6 additions & 0 deletions apis/v1alpha1/alias.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions apis/v1alpha1/generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ resources:
from:
operation: PutFunctionEventInvokeConfig
path: .
ProvisionedConcurrencyConfig:
from:
operation: PutProvisionedConcurrencyConfig
path: .
hooks:
sdk_update_pre_build_request:
template_path: hooks/alias/sdk_update_pre_build_request.go.tpl
Expand Down
13 changes: 10 additions & 3 deletions apis/v1alpha1/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions config/crd/bases/lambda.services.k8s.aws_aliases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ spec:
name:
description: The name of the alias.
type: string
provisionedConcurrencyConfig:
description: "Configures provisioned concurrency to a function's alias
\n - ProvisionedConcurrentExecutions The amount of provisioned concurrency
to allocate for the version or alias. Minimum value of 1 is required"
properties:
functionName:
type: string
provisionedConcurrentExecutions:
format: int64
type: integer
qualifier:
type: string
type: object
routingConfig:
description: The routing configuration (https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html#configuring-alias-routing)
of the alias.
Expand Down
8 changes: 8 additions & 0 deletions documentation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@ resources:

- MaximumRetryAttempts
The maximum number of times to retry when the function returns an error.

ProvisionedConcurrencyConfig:
prepend: |
Configures provisioned concurrency to a function's alias

- ProvisionedConcurrentExecutions
The amount of provisioned concurrency to allocate for the version or alias.
Minimum value of 1 is required
4 changes: 4 additions & 0 deletions generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ resources:
from:
operation: PutFunctionEventInvokeConfig
path: .
ProvisionedConcurrencyConfig:
from:
operation: PutProvisionedConcurrencyConfig
path: .
hooks:
sdk_update_pre_build_request:
template_path: hooks/alias/sdk_update_pre_build_request.go.tpl
Expand Down
13 changes: 13 additions & 0 deletions helm/crds/lambda.services.k8s.aws_aliases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ spec:
name:
description: The name of the alias.
type: string
provisionedConcurrencyConfig:
description: "Configures provisioned concurrency to a function's alias
\n - ProvisionedConcurrentExecutions The amount of provisioned concurrency
to allocate for the version or alias. Minimum value of 1 is required"
properties:
functionName:
type: string
provisionedConcurrentExecutions:
format: int64
type: integer
qualifier:
type: string
type: object
routingConfig:
description: The routing configuration (https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html#configuring-alias-routing)
of the alias.
Expand Down
25 changes: 25 additions & 0 deletions pkg/resource/alias/delta.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

95 changes: 90 additions & 5 deletions pkg/resource/alias/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package alias
import (
"context"

ackerr "github.com/aws-controllers-k8s/runtime/pkg/errors"
ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log"
"github.com/aws/aws-sdk-go/aws"
svcsdk "github.com/aws/aws-sdk-go/service/lambda"
Expand Down Expand Up @@ -70,14 +71,71 @@ func (rm *resourceManager) syncEventInvokeConfig(
return r, nil
}

func (rm *resourceManager) setResourceAdditionalFields(
func (rm *resourceManager) updateProvisionedConcurrency(
ctx context.Context,
ko *svcapitypes.Alias,
) (err error) {
desired *resource,
) error {
var err error
rlog := ackrtlog.FromContext(ctx)
exit := rlog.Trace("rm.setResourceAdditionalFields")
exit := rlog.Trace("rm.updateProvisionedConcurrency")
defer exit(err)

dspec := desired.ko.Spec
input := &svcsdk.PutProvisionedConcurrencyConfigInput{
FunctionName: aws.String(*dspec.FunctionName),
Qualifier: aws.String(*dspec.Name),
}

if desired.ko.Spec.ProvisionedConcurrencyConfig != nil {
if desired.ko.Spec.ProvisionedConcurrencyConfig.ProvisionedConcurrentExecutions != nil {
input.ProvisionedConcurrentExecutions = aws.Int64(*desired.ko.Spec.ProvisionedConcurrencyConfig.ProvisionedConcurrentExecutions)
} else {
input.ProvisionedConcurrentExecutions = aws.Int64(0)
}
} else {
input.ProvisionedConcurrentExecutions = aws.Int64(0)
}

_, err = rm.sdkapi.PutProvisionedConcurrencyConfigWithContext(ctx, input)
rm.metrics.RecordAPICall("UPDATE", "UpdateProvisionedConcurrency", err)
if err != nil {
return err
}
return nil
}

func (rm *resourceManager) getProvisionedConcurrencyConfig(
ctx context.Context,
ko *svcapitypes.Alias,
) (err error) {

var getProvisionedConcurrencyConfigOutput *svcsdk.GetProvisionedConcurrencyConfigOutput
getProvisionedConcurrencyConfigOutput, err = rm.sdkapi.GetProvisionedConcurrencyConfigWithContext(
ctx,
&svcsdk.GetProvisionedConcurrencyConfigInput{
FunctionName: ko.Spec.FunctionName,
Qualifier: ko.Spec.Name,
},
)
rm.metrics.RecordAPICall("GET", "GetProvisionedConcurrencyConfig", err)

if err != nil {
if awserr, ok := ackerr.AWSError(err); ok && (awserr.Code() == "ProvisionedConcurrencyConfigNotFoundException" || awserr.Code() == "ResourceNotFoundException") {
ko.Spec.ProvisionedConcurrencyConfig = nil
} else {
return err
}
} else {
ko.Spec.ProvisionedConcurrencyConfig.ProvisionedConcurrentExecutions = getProvisionedConcurrencyConfigOutput.RequestedProvisionedConcurrentExecutions
}

return nil
}

func (rm *resourceManager) getFunctionEventInvokeConfig(
ctx context.Context,
ko *svcapitypes.Alias,
) (err error) {
var getFunctionEventInvokeConfigOutput *svcsdk.GetFunctionEventInvokeConfigOutput
getFunctionEventInvokeConfigOutput, err = rm.sdkapi.GetFunctionEventInvokeConfigWithContext(
ctx,
Expand All @@ -88,8 +146,13 @@ func (rm *resourceManager) setResourceAdditionalFields(
)

rm.metrics.RecordAPICall("GET", "GetFunctionEventInvokeConfig", err)

if err != nil {
ko.Spec.FunctionEventInvokeConfig = nil
if awserr, ok := ackerr.AWSError(err); ok && (awserr.Code() == "EventInvokeConfigNotFoundException" || awserr.Code() == "ResourceNotFoundException") {
ko.Spec.FunctionEventInvokeConfig = nil
} else {
return err
}
} else {
if getFunctionEventInvokeConfigOutput.DestinationConfig != nil {
if getFunctionEventInvokeConfigOutput.DestinationConfig.OnFailure != nil {
Expand All @@ -116,5 +179,27 @@ func (rm *resourceManager) setResourceAdditionalFields(
ko.Spec.FunctionEventInvokeConfig.MaximumRetryAttempts = nil
}
}

return nil
}

func (rm *resourceManager) setResourceAdditionalFields(
ctx context.Context,
ko *svcapitypes.Alias,
) (err error) {
rlog := ackrtlog.FromContext(ctx)
exit := rlog.Trace("rm.setResourceAdditionalFields")
defer exit(err)

eic_err := rm.getFunctionEventInvokeConfig(ctx, ko)
if eic_err != nil {
return eic_err
}

pc_err := rm.getProvisionedConcurrencyConfig(ctx, ko)
if pc_err != nil {
return pc_err
}

return nil
Copy link
Member

Choose a reason for hiding this comment

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

👍

}
15 changes: 14 additions & 1 deletion pkg/resource/alias/sdk.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion pkg/resource/function/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,11 @@ func (rm *resourceManager) setResourceAdditionalFields(
)
rm.metrics.RecordAPICall("GET", "GetFunctionEventInvokeConfig", err)
if err != nil {
ko.Spec.FunctionEventInvokeConfig = nil
if awserr, ok := ackerr.AWSError(err); ok && (awserr.Code() == "EventInvokeConfigNotFoundException" || awserr.Code() == "ResourceNotFoundException") {
ko.Spec.FunctionEventInvokeConfig = nil
} else {
return err
}
} else {
if getFunctionEventInvokeConfigOutput.DestinationConfig != nil {
if getFunctionEventInvokeConfigOutput.DestinationConfig.OnFailure != nil {
Expand Down
Loading