Skip to content

Commit 65b22fc

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

17 files changed

+405
-11
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-20T17:53:33Z"
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: ed4abfc994c2c47465801d301604c584bd743d41
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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ 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
114+
sdk_create_post_set_output:
115+
template_path: hooks/alias/sdk_create_post_set_output.go.tpl
105116
tags:
106117
ignore: true
107118
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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ 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
114+
sdk_create_post_set_output:
115+
template_path: hooks/alias/sdk_create_post_set_output.go.tpl
105116
tags:
106117
ignore: true
107118
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: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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+
ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log"
20+
"github.com/aws/aws-sdk-go/aws"
21+
svcsdk "github.com/aws/aws-sdk-go/service/lambda"
22+
23+
svcapitypes "github.com/aws-controllers-k8s/lambda-controller/apis/v1alpha1"
24+
)
25+
26+
func (rm *resourceManager) syncEventInvokeConfig(
27+
ctx context.Context,
28+
r *resource,
29+
) (created *resource, err error) {
30+
rlog := ackrtlog.FromContext(ctx)
31+
exit := rlog.Trace("rm.syncEventInvokeConfig")
32+
defer exit(err)
33+
34+
dspec := r.ko.Spec
35+
input := &svcsdk.PutFunctionEventInvokeConfigInput{
36+
FunctionName: aws.String(*dspec.FunctionName),
37+
Qualifier: aws.String(*dspec.Name),
38+
}
39+
40+
if r.ko.Spec.FunctionEventInvokeConfig != nil {
41+
if r.ko.Spec.FunctionEventInvokeConfig.DestinationConfig != nil {
42+
destinations := &svcsdk.DestinationConfig{}
43+
if r.ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnFailure != nil {
44+
destinations.OnFailure = &svcsdk.OnFailure{}
45+
if r.ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnFailure.Destination != nil {
46+
destinations.OnFailure.Destination = aws.String(*r.ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnFailure.Destination)
47+
}
48+
}
49+
if r.ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnSuccess != nil {
50+
destinations.OnSuccess = &svcsdk.OnSuccess{}
51+
if r.ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnSuccess.Destination != nil {
52+
destinations.OnSuccess.Destination = aws.String(*r.ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnSuccess.Destination)
53+
}
54+
}
55+
input.DestinationConfig = destinations
56+
}
57+
if r.ko.Spec.FunctionEventInvokeConfig.MaximumEventAgeInSeconds != nil {
58+
input.MaximumEventAgeInSeconds = aws.Int64(*r.ko.Spec.FunctionEventInvokeConfig.MaximumEventAgeInSeconds)
59+
}
60+
if r.ko.Spec.FunctionEventInvokeConfig.MaximumRetryAttempts != nil {
61+
input.MaximumRetryAttempts = aws.Int64(*r.ko.Spec.FunctionEventInvokeConfig.MaximumRetryAttempts)
62+
}
63+
}
64+
_, err = rm.sdkapi.PutFunctionEventInvokeConfigWithContext(ctx, input)
65+
rm.metrics.RecordAPICall("SYNC", "SyncEventInvokeConfig", err)
66+
if err != nil {
67+
return nil, err
68+
}
69+
70+
return r, nil
71+
}
72+
73+
func (rm *resourceManager) setResourceAdditionalFields(
74+
ctx context.Context,
75+
ko *svcapitypes.Alias,
76+
) (err error) {
77+
rlog := ackrtlog.FromContext(ctx)
78+
exit := rlog.Trace("rm.setResourceAdditionalFields")
79+
defer exit(err)
80+
81+
var getFunctionEventInvokeConfigOutput *svcsdk.GetFunctionEventInvokeConfigOutput
82+
getFunctionEventInvokeConfigOutput, err = rm.sdkapi.GetFunctionEventInvokeConfigWithContext(
83+
ctx,
84+
&svcsdk.GetFunctionEventInvokeConfigInput{
85+
FunctionName: ko.Spec.FunctionName,
86+
Qualifier: ko.Spec.Name,
87+
},
88+
)
89+
90+
rm.metrics.RecordAPICall("GET", "GetFunctionEventInvokeConfig", err)
91+
if err != nil {
92+
ko.Spec.FunctionEventInvokeConfig = nil
93+
} else {
94+
if getFunctionEventInvokeConfigOutput.DestinationConfig != nil {
95+
if getFunctionEventInvokeConfigOutput.DestinationConfig.OnFailure != nil {
96+
if getFunctionEventInvokeConfigOutput.DestinationConfig.OnFailure.Destination != nil {
97+
ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnFailure.Destination = getFunctionEventInvokeConfigOutput.DestinationConfig.OnFailure.Destination
98+
}
99+
}
100+
if getFunctionEventInvokeConfigOutput.DestinationConfig.OnSuccess != nil {
101+
if getFunctionEventInvokeConfigOutput.DestinationConfig.OnSuccess.Destination != nil {
102+
ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnSuccess.Destination = getFunctionEventInvokeConfigOutput.DestinationConfig.OnSuccess.Destination
103+
}
104+
}
105+
} else {
106+
ko.Spec.FunctionEventInvokeConfig.DestinationConfig = nil
107+
}
108+
if getFunctionEventInvokeConfigOutput.MaximumEventAgeInSeconds != nil {
109+
ko.Spec.FunctionEventInvokeConfig.MaximumEventAgeInSeconds = getFunctionEventInvokeConfigOutput.MaximumEventAgeInSeconds
110+
} else {
111+
ko.Spec.FunctionEventInvokeConfig.MaximumEventAgeInSeconds = nil
112+
}
113+
if getFunctionEventInvokeConfigOutput.DestinationConfig != nil {
114+
ko.Spec.FunctionEventInvokeConfig.MaximumRetryAttempts = getFunctionEventInvokeConfigOutput.MaximumRetryAttempts
115+
} else {
116+
ko.Spec.FunctionEventInvokeConfig.MaximumRetryAttempts = nil
117+
}
118+
}
119+
return nil
120+
}

pkg/resource/alias/sdk.go

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

pkg/resource/function/hooks.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package function
1616
import (
1717
"context"
1818
"errors"
19-
"fmt"
2019
"time"
2120

2221
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
@@ -612,7 +611,6 @@ func (rm *resourceManager) setResourceAdditionalFields(
612611
if err != nil {
613612
ko.Spec.FunctionEventInvokeConfig = nil
614613
} else {
615-
fmt.Println(ko.Spec.FunctionEventInvokeConfig.DestinationConfig)
616614
if getFunctionEventInvokeConfigOutput.DestinationConfig != nil {
617615
if getFunctionEventInvokeConfigOutput.DestinationConfig.OnFailure != nil {
618616
if getFunctionEventInvokeConfigOutput.DestinationConfig.OnFailure.Destination != nil {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
if ko.Spec.FunctionEventInvokeConfig != nil {
2+
_, err = rm.syncEventInvokeConfig(ctx,desired)
3+
if err != nil{
4+
return nil, err
5+
}
6+
}

0 commit comments

Comments
 (0)