Skip to content

Commit fe01416

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

17 files changed

+430
-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-19T16:50:06Z"
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: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
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+
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
20+
ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log"
21+
"github.com/aws/aws-sdk-go/aws"
22+
svcsdk "github.com/aws/aws-sdk-go/service/lambda"
23+
24+
svcapitypes "github.com/aws-controllers-k8s/lambda-controller/apis/v1alpha1"
25+
)
26+
27+
func (rm *resourceManager) customUpdateEventInvokeConfig(
28+
ctx context.Context,
29+
desired *resource,
30+
delta *ackcompare.Delta,
31+
) (*resource, error) {
32+
var err error
33+
rlog := ackrtlog.FromContext(ctx)
34+
exit := rlog.Trace("rm.customUpdateEventInvokeConfig")
35+
defer exit(err)
36+
37+
if delta.DifferentAt("Spec.FunctionEventInvokeConfig") {
38+
_, err = rm.syncEventInvokeConfig(ctx, desired)
39+
if err != nil {
40+
return nil, err
41+
}
42+
}
43+
44+
readOneLatest, err := rm.ReadOne(ctx, desired)
45+
if err != nil {
46+
return nil, err
47+
}
48+
return rm.concreteResource(readOneLatest), nil
49+
}
50+
51+
func (rm *resourceManager) customCreateEventInvokeConfig(
52+
ctx context.Context,
53+
desired *resource,
54+
) (created *resource, err error) {
55+
rlog := ackrtlog.FromContext(ctx)
56+
exit := rlog.Trace("rm.customCreateEventInvokeConfig")
57+
defer exit(err)
58+
59+
input, err := rm.syncEventInvokeConfig(ctx, desired)
60+
if err != nil {
61+
return nil, err
62+
}
63+
64+
return input, nil
65+
}
66+
67+
func (rm *resourceManager) syncEventInvokeConfig(
68+
ctx context.Context,
69+
r *resource,
70+
) (created *resource, err error) {
71+
rlog := ackrtlog.FromContext(ctx)
72+
exit := rlog.Trace("rm.syncEventInvokeConfig")
73+
defer exit(err)
74+
75+
dspec := r.ko.Spec
76+
input := &svcsdk.PutFunctionEventInvokeConfigInput{
77+
FunctionName: aws.String(*dspec.FunctionName),
78+
Qualifier: aws.String(*dspec.Name),
79+
}
80+
81+
if r.ko.Spec.FunctionEventInvokeConfig != nil {
82+
if r.ko.Spec.FunctionEventInvokeConfig.DestinationConfig != nil {
83+
destinations := &svcsdk.DestinationConfig{}
84+
if r.ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnFailure != nil {
85+
destinations.OnFailure = &svcsdk.OnFailure{}
86+
if r.ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnFailure.Destination != nil {
87+
destinations.OnFailure.Destination = aws.String(*r.ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnFailure.Destination)
88+
}
89+
}
90+
if r.ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnSuccess != nil {
91+
destinations.OnSuccess = &svcsdk.OnSuccess{}
92+
if r.ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnSuccess.Destination != nil {
93+
destinations.OnSuccess.Destination = aws.String(*r.ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnSuccess.Destination)
94+
}
95+
}
96+
input.DestinationConfig = destinations
97+
}
98+
if r.ko.Spec.FunctionEventInvokeConfig.MaximumEventAgeInSeconds != nil {
99+
input.MaximumEventAgeInSeconds = aws.Int64(*r.ko.Spec.FunctionEventInvokeConfig.MaximumEventAgeInSeconds)
100+
}
101+
if r.ko.Spec.FunctionEventInvokeConfig.MaximumRetryAttempts != nil {
102+
input.MaximumRetryAttempts = aws.Int64(*r.ko.Spec.FunctionEventInvokeConfig.MaximumRetryAttempts)
103+
}
104+
}
105+
_, err = rm.sdkapi.PutFunctionEventInvokeConfigWithContext(ctx, input)
106+
rm.metrics.RecordAPICall("SYNC", "SyncEventInvokeConfig", err)
107+
if err != nil {
108+
return nil, err
109+
}
110+
111+
return r, nil
112+
}
113+
114+
func (rm *resourceManager) setResourceAdditionalFields(
115+
ctx context.Context,
116+
ko *svcapitypes.Alias,
117+
) (err error) {
118+
rlog := ackrtlog.FromContext(ctx)
119+
exit := rlog.Trace("rm.setResourceAdditionalFields")
120+
defer exit(err)
121+
122+
var getFunctionEventInvokeConfigOutput *svcsdk.GetFunctionEventInvokeConfigOutput
123+
getFunctionEventInvokeConfigOutput, err = rm.sdkapi.GetFunctionEventInvokeConfigWithContext(
124+
ctx,
125+
&svcsdk.GetFunctionEventInvokeConfigInput{
126+
FunctionName: ko.Spec.FunctionName,
127+
Qualifier: ko.Spec.Name,
128+
},
129+
)
130+
131+
rm.metrics.RecordAPICall("GET", "GetFunctionEventInvokeConfig", err)
132+
if err != nil {
133+
ko.Spec.FunctionEventInvokeConfig = nil
134+
} else {
135+
if getFunctionEventInvokeConfigOutput.DestinationConfig != nil {
136+
if getFunctionEventInvokeConfigOutput.DestinationConfig.OnFailure != nil {
137+
if getFunctionEventInvokeConfigOutput.DestinationConfig.OnFailure.Destination != nil {
138+
ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnFailure.Destination = getFunctionEventInvokeConfigOutput.DestinationConfig.OnFailure.Destination
139+
}
140+
}
141+
if getFunctionEventInvokeConfigOutput.DestinationConfig.OnSuccess != nil {
142+
if getFunctionEventInvokeConfigOutput.DestinationConfig.OnSuccess.Destination != nil {
143+
ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnSuccess.Destination = getFunctionEventInvokeConfigOutput.DestinationConfig.OnSuccess.Destination
144+
}
145+
}
146+
} else {
147+
ko.Spec.FunctionEventInvokeConfig.DestinationConfig = nil
148+
}
149+
if getFunctionEventInvokeConfigOutput.MaximumEventAgeInSeconds != nil {
150+
ko.Spec.FunctionEventInvokeConfig.MaximumEventAgeInSeconds = getFunctionEventInvokeConfigOutput.MaximumEventAgeInSeconds
151+
} else {
152+
ko.Spec.FunctionEventInvokeConfig.MaximumEventAgeInSeconds = nil
153+
}
154+
if getFunctionEventInvokeConfigOutput.DestinationConfig != nil {
155+
ko.Spec.FunctionEventInvokeConfig.MaximumRetryAttempts = getFunctionEventInvokeConfigOutput.MaximumRetryAttempts
156+
} else {
157+
ko.Spec.FunctionEventInvokeConfig.MaximumRetryAttempts = nil
158+
}
159+
}
160+
return nil
161+
}

0 commit comments

Comments
 (0)