Skip to content

Commit 1814ecf

Browse files
committed
Adding ProvisionedConcurrency Support for Alias
1 parent 24be866 commit 1814ecf

17 files changed

+324
-12
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-17T22:59:48Z"
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: e80cb2007eb08a463d2e6ea5aa006563bd5c42ed
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: 6 additions & 0 deletions
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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@ spec:
104104
name:
105105
description: The name of the alias.
106106
type: string
107+
provisionedConcurrencyConfig:
108+
description: "Configures provisioned concurrency to a function's alias
109+
\n - ProvisionedConcurrentExecutions The amount of provisioned concurrency
110+
to allocate for the version or alias. Minimum value of 1 is required"
111+
properties:
112+
functionName:
113+
type: string
114+
provisionedConcurrentExecutions:
115+
format: int64
116+
type: integer
117+
qualifier:
118+
type: string
119+
type: object
107120
routingConfig:
108121
description: The routing configuration (https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html#configuring-alias-routing)
109122
of the alias.

documentation.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,11 @@ resources:
3939
4040
- MaximumRetryAttempts
4141
The maximum number of times to retry when the function returns an error.
42+
43+
ProvisionedConcurrencyConfig:
44+
prepend: |
45+
Configures provisioned concurrency to a function's alias
46+
47+
- ProvisionedConcurrentExecutions
48+
The amount of provisioned concurrency to allocate for the version or alias.
49+
Minimum value of 1 is required

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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@ spec:
104104
name:
105105
description: The name of the alias.
106106
type: string
107+
provisionedConcurrencyConfig:
108+
description: "Configures provisioned concurrency to a function's alias
109+
\n - ProvisionedConcurrentExecutions The amount of provisioned concurrency
110+
to allocate for the version or alias. Minimum value of 1 is required"
111+
properties:
112+
functionName:
113+
type: string
114+
provisionedConcurrentExecutions:
115+
format: int64
116+
type: integer
117+
qualifier:
118+
type: string
119+
type: object
107120
routingConfig:
108121
description: The routing configuration (https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html#configuring-alias-routing)
109122
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: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,65 @@ func (rm *resourceManager) syncEventInvokeConfig(
7070
return r, nil
7171
}
7272

73-
func (rm *resourceManager) setResourceAdditionalFields(
73+
func (rm *resourceManager) updateProvisionedConcurrency(
7474
ctx context.Context,
75-
ko *svcapitypes.Alias,
76-
) (err error) {
75+
desired *resource,
76+
) error {
77+
var err error
7778
rlog := ackrtlog.FromContext(ctx)
78-
exit := rlog.Trace("rm.setResourceAdditionalFields")
79+
exit := rlog.Trace("rm.updateProvisionedConcurrency")
7980
defer exit(err)
8081

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+
} else {
95+
input.ProvisionedConcurrentExecutions = aws.Int64(0)
96+
}
97+
98+
_, err = rm.sdkapi.PutProvisionedConcurrencyConfigWithContext(ctx, input)
99+
rm.metrics.RecordAPICall("UPDATE", "UpdateProvisionedConcurrency", err)
100+
if err != nil {
101+
return err
102+
}
103+
return nil
104+
}
105+
106+
func (rm *resourceManager) getProvisionedConcurrencyConfig(
107+
ctx context.Context,
108+
ko *svcapitypes.Alias,
109+
) (err error) {
110+
111+
var getProvisionedConcurrencyConfigOutput *svcsdk.GetProvisionedConcurrencyConfigOutput
112+
getProvisionedConcurrencyConfigOutput, err = rm.sdkapi.GetProvisionedConcurrencyConfigWithContext(
113+
ctx,
114+
&svcsdk.GetProvisionedConcurrencyConfigInput{
115+
FunctionName: ko.Spec.FunctionName,
116+
Qualifier: ko.Spec.Name,
117+
},
118+
)
119+
rm.metrics.RecordAPICall("GET", "GetProvisionedConcurrencyConfig", err)
120+
if err != nil {
121+
ko.Spec.ProvisionedConcurrencyConfig = nil
122+
} else {
123+
ko.Spec.ProvisionedConcurrencyConfig.ProvisionedConcurrentExecutions = getProvisionedConcurrencyConfigOutput.RequestedProvisionedConcurrentExecutions
124+
}
125+
return nil
126+
}
127+
128+
func (rm *resourceManager) getFunctionEventInvokeConfig(
129+
ctx context.Context,
130+
ko *svcapitypes.Alias,
131+
) (err error) {
81132
var getFunctionEventInvokeConfigOutput *svcsdk.GetFunctionEventInvokeConfigOutput
82133
getFunctionEventInvokeConfigOutput, err = rm.sdkapi.GetFunctionEventInvokeConfigWithContext(
83134
ctx,
@@ -116,5 +167,27 @@ func (rm *resourceManager) setResourceAdditionalFields(
116167
ko.Spec.FunctionEventInvokeConfig.MaximumRetryAttempts = nil
117168
}
118169
}
170+
171+
return nil
172+
}
173+
174+
func (rm *resourceManager) setResourceAdditionalFields(
175+
ctx context.Context,
176+
ko *svcapitypes.Alias,
177+
) (err error) {
178+
rlog := ackrtlog.FromContext(ctx)
179+
exit := rlog.Trace("rm.setResourceAdditionalFields")
180+
defer exit(err)
181+
182+
err = rm.getProvisionedConcurrencyConfig(ctx, ko)
183+
if err != nil {
184+
return nil
185+
}
186+
187+
err = rm.getFunctionEventInvokeConfig(ctx, ko)
188+
if err != nil {
189+
return nil
190+
}
191+
119192
return nil
120193
}

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

0 commit comments

Comments
 (0)