Skip to content

Commit b5c1f7c

Browse files
committed
Adding EventInvokeConfig support for Alias
1 parent d5ed5df commit b5c1f7c

18 files changed

+1149
-758
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-07T18:16:37Z"
2+
build_date: "2023-06-08T17:57:24Z"
33
build_hash: dcb9fd6c564ce817a48abd6f7b9ee4308aa1d13f
44
go_version: go1.19
55
version: v0.26.1-4-gdcb9fd6
6-
api_directory_checksum: ca34c731b281f29e80984c872002e220ddee5133
6+
api_directory_checksum: abfe23d485db47621d97ad80a1ad317ae31185f1
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.44.181
99
generator_config_info:
10-
file_checksum: d53a6ae44af0a12af854385908c6e09355b3a126
10+
file_checksum: 078c1abb3b467f21efb3fb928d13066402397f89
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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ resources:
102102
path: Spec.Name
103103
FunctionVersion:
104104
is_required: true
105+
FunctionEventInvokeConfig:
106+
from:
107+
operation: PutFunctionEventInvokeConfig
108+
path: .
109+
hooks:
110+
sdk_update_pre_build_request:
111+
template_path: hooks/alias/sdk_update_pre_build_request.go.tpl
112+
sdk_read_one_post_set_output:
113+
template_path: hooks/alias/sdk_read_one_post_set_output.go.tpl
105114
tags:
106115
ignore: true
107116
CodeSigningConfig:

apis/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,37 @@ spec:
3737
description:
3838
description: A description of the alias.
3939
type: string
40+
functionEventInvokeConfig:
41+
properties:
42+
destinationConfig:
43+
description: A configuration object that specifies the destination
44+
of an event after Lambda processes it.
45+
properties:
46+
onFailure:
47+
description: A destination for events that failed processing.
48+
properties:
49+
destination:
50+
type: string
51+
type: object
52+
onSuccess:
53+
description: A destination for events that were processed
54+
successfully.
55+
properties:
56+
destination:
57+
type: string
58+
type: object
59+
type: object
60+
functionName:
61+
type: string
62+
maximumEventAgeInSeconds:
63+
format: int64
64+
type: integer
65+
maximumRetryAttempts:
66+
format: int64
67+
type: integer
68+
qualifier:
69+
type: string
70+
type: object
4071
functionName:
4172
description: "The name of the Lambda function. \n Name formats \n
4273
* Function name - MyFunction. \n * Function ARN - arn:aws:lambda:us-west-2:123456789012:function:MyFunction.

generator.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ resources:
102102
path: Spec.Name
103103
FunctionVersion:
104104
is_required: true
105+
FunctionEventInvokeConfig:
106+
from:
107+
operation: PutFunctionEventInvokeConfig
108+
path: .
109+
hooks:
110+
sdk_update_pre_build_request:
111+
template_path: hooks/alias/sdk_update_pre_build_request.go.tpl
112+
sdk_read_one_post_set_output:
113+
template_path: hooks/alias/sdk_read_one_post_set_output.go.tpl
105114
tags:
106115
ignore: true
107116
CodeSigningConfig:

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,37 @@ spec:
3737
description:
3838
description: A description of the alias.
3939
type: string
40+
functionEventInvokeConfig:
41+
properties:
42+
destinationConfig:
43+
description: A configuration object that specifies the destination
44+
of an event after Lambda processes it.
45+
properties:
46+
onFailure:
47+
description: A destination for events that failed processing.
48+
properties:
49+
destination:
50+
type: string
51+
type: object
52+
onSuccess:
53+
description: A destination for events that were processed
54+
successfully.
55+
properties:
56+
destination:
57+
type: string
58+
type: object
59+
type: object
60+
functionName:
61+
type: string
62+
maximumEventAgeInSeconds:
63+
format: int64
64+
type: integer
65+
maximumRetryAttempts:
66+
format: int64
67+
type: integer
68+
qualifier:
69+
type: string
70+
type: object
4071
functionName:
4172
description: "The name of the Lambda function. \n Name formats \n
4273
- Function name - MyFunction. \n - Function ARN - arn:aws:lambda:us-west-2:123456789012:function:MyFunction.

pkg/resource/alias/delta.go

Lines changed: 58 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: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
14+
package alias
15+
16+
import (
17+
"context"
18+
19+
svcapitypes "github.com/aws-controllers-k8s/lambda-controller/apis/v1alpha1"
20+
// svcresource "github.com/aws-controllers-k8s/lambda-controller/pkg/resource"
21+
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
22+
ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log"
23+
"github.com/aws/aws-sdk-go/aws"
24+
svcsdk "github.com/aws/aws-sdk-go/service/lambda"
25+
)
26+
27+
func (rm *resourceManager) customUpdateAlias(
28+
ctx context.Context,
29+
desired *resource,
30+
latest *resource,
31+
delta *ackcompare.Delta,
32+
) (*resource, error) {
33+
var err error
34+
rlog := ackrtlog.FromContext(ctx)
35+
exit := rlog.Trace("rm.customUpdateAlias")
36+
defer exit(err)
37+
38+
if delta.DifferentAt("Spec.FunctionEventInvokeConfig") {
39+
err = rm.updateFunctionEventInvokeConfig(ctx, desired)
40+
if err != nil {
41+
return nil, err
42+
}
43+
}
44+
45+
readOneLatest, err := rm.ReadOne(ctx, desired)
46+
if err != nil {
47+
return nil, err
48+
}
49+
return rm.concreteResource(readOneLatest), nil
50+
}
51+
52+
func (rm *resourceManager) updateFunctionEventInvokeConfig(
53+
ctx context.Context,
54+
desired *resource,
55+
) error {
56+
var err error
57+
rlog := ackrtlog.FromContext(ctx)
58+
exit := rlog.Trace("rm.updateFunctionEventInvokeConfig")
59+
defer exit(err)
60+
61+
dspec := desired.ko.Spec
62+
input := &svcsdk.PutFunctionEventInvokeConfigInput{
63+
FunctionName: aws.String(*dspec.FunctionName),
64+
Qualifier: aws.String(*dspec.Name),
65+
}
66+
// svcresource.UpdateEventInvokeConfig(desired, input)
67+
if desired.ko.Spec.FunctionEventInvokeConfig != nil {
68+
if desired.ko.Spec.FunctionEventInvokeConfig.MaximumEventAgeInSeconds != nil {
69+
input.MaximumEventAgeInSeconds = aws.Int64(*desired.ko.Spec.FunctionEventInvokeConfig.MaximumEventAgeInSeconds)
70+
}
71+
if desired.ko.Spec.FunctionEventInvokeConfig.MaximumRetryAttempts != nil {
72+
input.MaximumRetryAttempts = aws.Int64(*desired.ko.Spec.FunctionEventInvokeConfig.MaximumRetryAttempts)
73+
}
74+
if desired.ko.Spec.FunctionEventInvokeConfig.DestinationConfig != nil {
75+
destinations := &svcsdk.DestinationConfig{}
76+
if desired.ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnFailure != nil {
77+
destinations.OnFailure = &svcsdk.OnFailure{}
78+
if desired.ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnFailure.Destination != nil {
79+
destinations.OnFailure.Destination = aws.String(*desired.ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnFailure.Destination)
80+
}
81+
}
82+
if desired.ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnSuccess != nil {
83+
destinations.OnSuccess = &svcsdk.OnSuccess{}
84+
if desired.ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnSuccess.Destination != nil {
85+
destinations.OnSuccess.Destination = aws.String(*desired.ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnSuccess.Destination)
86+
}
87+
}
88+
input.DestinationConfig = destinations
89+
}
90+
}
91+
92+
_, err = rm.sdkapi.PutFunctionEventInvokeConfigWithContext(ctx, input)
93+
rm.metrics.RecordAPICall("UPDATE", "PutFunctionEventInvokeConfig", err)
94+
if err != nil {
95+
return err
96+
}
97+
return nil
98+
}
99+
100+
func (rm *resourceManager) setResourceAdditionalFields(
101+
ctx context.Context,
102+
ko *svcapitypes.Alias,
103+
) (err error) {
104+
rlog := ackrtlog.FromContext(ctx)
105+
exit := rlog.Trace("rm.setResourceAdditionalFields")
106+
defer exit(err)
107+
108+
var getFunctionEventInvokeConfigOutput *svcsdk.GetFunctionEventInvokeConfigOutput
109+
getFunctionEventInvokeConfigOutput, err = rm.sdkapi.GetFunctionEventInvokeConfigWithContext(
110+
ctx,
111+
&svcsdk.GetFunctionEventInvokeConfigInput{
112+
FunctionName: ko.Spec.FunctionName,
113+
Qualifier: ko.Spec.Name,
114+
},
115+
)
116+
117+
rm.metrics.RecordAPICall("GET", "GetFunctionEventInvokeConfig", err)
118+
// svcresource.SetEventInvokeConfig(getFunctionEventInvokeConfigOutput, ko)
119+
if err != nil {
120+
ko.Spec.FunctionEventInvokeConfig = nil
121+
} else {
122+
if getFunctionEventInvokeConfigOutput.DestinationConfig != nil {
123+
if getFunctionEventInvokeConfigOutput.DestinationConfig.OnFailure != nil {
124+
if getFunctionEventInvokeConfigOutput.DestinationConfig.OnFailure.Destination != nil {
125+
ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnFailure.Destination = getFunctionEventInvokeConfigOutput.DestinationConfig.OnFailure.Destination
126+
}
127+
}
128+
if getFunctionEventInvokeConfigOutput.DestinationConfig.OnSuccess != nil {
129+
if getFunctionEventInvokeConfigOutput.DestinationConfig.OnSuccess.Destination != nil {
130+
ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnSuccess.Destination = getFunctionEventInvokeConfigOutput.DestinationConfig.OnSuccess.Destination
131+
}
132+
}
133+
} else {
134+
ko.Spec.FunctionEventInvokeConfig.DestinationConfig = nil
135+
}
136+
if getFunctionEventInvokeConfigOutput.MaximumEventAgeInSeconds != nil {
137+
ko.Spec.FunctionEventInvokeConfig.MaximumEventAgeInSeconds = getFunctionEventInvokeConfigOutput.MaximumEventAgeInSeconds
138+
} else {
139+
ko.Spec.FunctionEventInvokeConfig.MaximumEventAgeInSeconds = nil
140+
}
141+
if getFunctionEventInvokeConfigOutput.DestinationConfig != nil {
142+
ko.Spec.FunctionEventInvokeConfig.MaximumRetryAttempts = getFunctionEventInvokeConfigOutput.MaximumRetryAttempts
143+
} else {
144+
ko.Spec.FunctionEventInvokeConfig.MaximumRetryAttempts = nil
145+
}
146+
}
147+
return nil
148+
}

pkg/resource/alias/sdk.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if err := rm.setResourceAdditionalFields(ctx, ko); err != nil {
2+
return nil, err
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rm.customUpdateAlias(ctx,desired,latest,delta)

0 commit comments

Comments
 (0)