Skip to content

Commit c596c26

Browse files
committed
Adding ProvisionedConcurrency Support for Alias
1 parent f6ee249 commit c596c26

21 files changed

+1680
-1411
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
ack_generate_info:
2-
build_date: "2023-06-28T18:32:11Z"
2+
build_date: "2023-07-12T16:21:57Z"
33
build_hash: e9b68590da73ce9143ba1e4361cebdc1d876c81e
44
go_version: go1.19
55
version: v0.26.1-7-ge9b6859
6-
api_directory_checksum: 5f162746e8495943dae5e96f48f4a3ab887b5be5
6+
api_directory_checksum: e8290d4489213bc48136215f33af8cae03f4e2a9
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.44.181
99
generator_config_info:
10-
file_checksum: ed4abfc994c2c47465801d301604c584bd743d41
10+
file_checksum: 0982d74c1a222e29260dbf276136ba99fcb856e2
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

apis/v1alpha1/alias.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha1/generator.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ resources:
106106
from:
107107
operation: PutFunctionEventInvokeConfig
108108
path: .
109+
ProvisionedConcurrencyConfig:
110+
from:
111+
operation: PutProvisionedConcurrencyConfig
112+
path: .
109113
hooks:
110114
sdk_update_pre_build_request:
111115
template_path: hooks/alias/sdk_update_pre_build_request.go.tpl

apis/v1alpha1/types.go

Lines changed: 10 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha1/zz_generated.deepcopy.go

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/lambda.services.k8s.aws_aliases.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ spec:
104104
name:
105105
description: The name of the alias.
106106
type: string
107+
provisionedConcurrencyConfig:
108+
properties:
109+
functionName:
110+
type: string
111+
provisionedConcurrentExecutions:
112+
format: int64
113+
type: integer
114+
qualifier:
115+
type: string
116+
type: object
107117
routingConfig:
108118
description: The routing configuration (https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html#configuring-alias-routing)
109119
of the alias.

generator.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ resources:
106106
from:
107107
operation: PutFunctionEventInvokeConfig
108108
path: .
109+
ProvisionedConcurrencyConfig:
110+
from:
111+
operation: PutProvisionedConcurrencyConfig
112+
path: .
109113
hooks:
110114
sdk_update_pre_build_request:
111115
template_path: hooks/alias/sdk_update_pre_build_request.go.tpl

helm/crds/lambda.services.k8s.aws_aliases.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ spec:
104104
name:
105105
description: The name of the alias.
106106
type: string
107+
provisionedConcurrencyConfig:
108+
properties:
109+
functionName:
110+
type: string
111+
provisionedConcurrentExecutions:
112+
format: int64
113+
type: integer
114+
qualifier:
115+
type: string
116+
type: object
107117
routingConfig:
108118
description: The routing configuration (https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html#configuring-alias-routing)
109119
of the alias.

pkg/resource/alias/delta.go

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/resource/alias/hooks.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,37 @@ func (rm *resourceManager) syncEventInvokeConfig(
7070
return r, nil
7171
}
7272

73+
func (rm *resourceManager) updateProvisionedConcurrency(
74+
ctx context.Context,
75+
desired *resource,
76+
) error {
77+
var err error
78+
rlog := ackrtlog.FromContext(ctx)
79+
exit := rlog.Trace("rm.updateProvisionedConcurrency")
80+
defer exit(err)
81+
82+
dspec := desired.ko.Spec
83+
input := &svcsdk.PutProvisionedConcurrencyConfigInput{
84+
FunctionName: aws.String(*dspec.FunctionName),
85+
Qualifier: aws.String(*dspec.Name),
86+
}
87+
88+
if desired.ko.Spec.ProvisionedConcurrencyConfig != nil {
89+
if desired.ko.Spec.ProvisionedConcurrencyConfig.ProvisionedConcurrentExecutions != nil {
90+
input.ProvisionedConcurrentExecutions = aws.Int64(*desired.ko.Spec.ProvisionedConcurrencyConfig.ProvisionedConcurrentExecutions)
91+
} else {
92+
input.ProvisionedConcurrentExecutions = aws.Int64(0)
93+
}
94+
}
95+
96+
_, err = rm.sdkapi.PutProvisionedConcurrencyConfigWithContext(ctx, input)
97+
rm.metrics.RecordAPICall("UPDATE", "UpdateProvisionedConcurrency", err)
98+
if err != nil {
99+
return err
100+
}
101+
return nil
102+
}
103+
73104
func (rm *resourceManager) setResourceAdditionalFields(
74105
ctx context.Context,
75106
ko *svcapitypes.Alias,
@@ -78,6 +109,21 @@ func (rm *resourceManager) setResourceAdditionalFields(
78109
exit := rlog.Trace("rm.setResourceAdditionalFields")
79110
defer exit(err)
80111

112+
var getProvisionedConcurrencyConfigOutput *svcsdk.GetProvisionedConcurrencyConfigOutput
113+
getProvisionedConcurrencyConfigOutput, err = rm.sdkapi.GetProvisionedConcurrencyConfigWithContext(
114+
ctx,
115+
&svcsdk.GetProvisionedConcurrencyConfigInput{
116+
FunctionName: ko.Spec.FunctionName,
117+
Qualifier: ko.Spec.Name,
118+
},
119+
)
120+
rm.metrics.RecordAPICall("GET", "GetProvisionedConcurrencyConfig", err)
121+
if err != nil {
122+
ko.Spec.ProvisionedConcurrencyConfig = nil
123+
} else {
124+
ko.Spec.ProvisionedConcurrencyConfig.ProvisionedConcurrentExecutions = getProvisionedConcurrencyConfigOutput.RequestedProvisionedConcurrentExecutions
125+
}
126+
81127
var getFunctionEventInvokeConfigOutput *svcsdk.GetFunctionEventInvokeConfigOutput
82128
getFunctionEventInvokeConfigOutput, err = rm.sdkapi.GetFunctionEventInvokeConfigWithContext(
83129
ctx,

pkg/resource/alias/sdk.go

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/hooks/alias/sdk_create_post_set_output.go.tpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,11 @@ if ko.Spec.FunctionEventInvokeConfig != nil {
33
if err != nil{
44
return nil, err
55
}
6+
}
7+
8+
if ko.Spec.ProvisionedConcurrencyConfig != nil {
9+
err = rm.updateProvisionedConcurrency(ctx,desired)
10+
if err != nil{
11+
return nil, err
12+
}
613
}

templates/hooks/alias/sdk_update_pre_build_request.go.tpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,10 @@ if delta.DifferentAt("Spec.FunctionEventInvokeConfig"){
66
}
77
if !delta.DifferentExcept("Spec.FunctionEventInvokeConfig"){
88
return desired, nil
9+
}
10+
if delta.DifferentAt("Spec.ProvisionedConcurrencyConfig.ProvisionedConcurrentExecutions"){
11+
err = rm.updateProvisionedConcurrency(ctx, desired)
12+
if err != nil {
13+
return nil, err
14+
}
915
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: lambda.services.k8s.aws/v1alpha1
2+
kind: Alias
3+
metadata:
4+
name: $ALIAS_NAME
5+
annotations:
6+
services.k8s.aws/region: $AWS_REGION
7+
spec:
8+
name: $ALIAS_NAME
9+
functionName: $FUNCTION_NAME
10+
functionVersion: $FUNCTION_VERSION
11+
description: alias created by ACK lambda-controller e2e tests
12+
provisionedConcurrencyConfig:
13+
provisionedConcurrentExecutions: $PROVISIONED_CONCURRENT_EXECUTIONS

test/e2e/tests/helper.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,15 @@ def get_function_event_invoke_config_alias(self, function_name:str, qualifier:st
160160
return None
161161

162162
def function_event_invoke_config_exists(self, function_name: str) -> bool:
163-
return self.get_function_event_invoke_config(function_name) is not None
163+
return self.get_function_event_invoke_config(function_name) is not None
164+
165+
def get_provisioned_concurrency_config(self, function_name: str, qualifier:str) -> dict:
166+
try:
167+
resp = self.lambda_client.get_provisioned_concurrency_config(
168+
FunctionName = function_name,
169+
Qualifier = qualifier
170+
)
171+
return resp
172+
except Exception as e:
173+
logging.debug(e)
174+
return None

0 commit comments

Comments
 (0)