Skip to content

Commit b99efad

Browse files
committed
Bug fix for EventInvokeConfig in Alias
1 parent 807eecc commit b99efad

File tree

4 files changed

+101
-103
lines changed

4 files changed

+101
-103
lines changed

apis/v1alpha1/ack-generate-metadata.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ack_generate_info:
2-
build_date: "2023-08-02T22:43:32Z"
2+
build_date: "2023-08-16T22:02:43Z"
33
build_hash: e9b68590da73ce9143ba1e4361cebdc1d876c81e
44
go_version: go1.19
55
version: v0.26.1-7-ge9b6859

pkg/resource/alias/hooks.go

Lines changed: 74 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -32,42 +32,55 @@ func (rm *resourceManager) syncEventInvokeConfig(
3232
exit := rlog.Trace("rm.syncEventInvokeConfig")
3333
defer exit(err)
3434

35+
// Check if the user deleted the 'FunctionEventInvokeConfig' configuration
36+
// If yes, delete FunctionEventInvokeConfig
37+
if r.ko.Spec.FunctionEventInvokeConfig == nil {
38+
input_delete := &svcsdk.DeleteFunctionEventInvokeConfigInput{
39+
FunctionName: aws.String(*r.ko.Spec.FunctionName),
40+
Qualifier: aws.String(*r.ko.Spec.Name),
41+
}
42+
_, err = rm.sdkapi.DeleteFunctionEventInvokeConfigWithContext(ctx, input_delete)
43+
rm.metrics.RecordAPICall("DELETE", "DeleteFunctionEventInvokeConfig", err)
44+
if err != nil {
45+
return nil, err
46+
}
47+
return r, nil
48+
}
49+
3550
dspec := r.ko.Spec
3651
input := &svcsdk.PutFunctionEventInvokeConfigInput{
3752
FunctionName: aws.String(*dspec.FunctionName),
3853
Qualifier: aws.String(*dspec.Name),
3954
}
4055

41-
if r.ko.Spec.FunctionEventInvokeConfig != nil {
42-
if r.ko.Spec.FunctionEventInvokeConfig.DestinationConfig != nil {
43-
destinations := &svcsdk.DestinationConfig{}
44-
if r.ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnFailure != nil {
45-
destinations.OnFailure = &svcsdk.OnFailure{}
46-
if r.ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnFailure.Destination != nil {
47-
destinations.OnFailure.Destination = aws.String(*r.ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnFailure.Destination)
48-
}
49-
}
50-
if r.ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnSuccess != nil {
51-
destinations.OnSuccess = &svcsdk.OnSuccess{}
52-
if r.ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnSuccess.Destination != nil {
53-
destinations.OnSuccess.Destination = aws.String(*r.ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnSuccess.Destination)
54-
}
56+
if dspec.FunctionEventInvokeConfig.DestinationConfig != nil {
57+
destinations := &svcsdk.DestinationConfig{}
58+
if dspec.FunctionEventInvokeConfig.DestinationConfig.OnFailure != nil {
59+
destinations.OnFailure = &svcsdk.OnFailure{}
60+
if dspec.FunctionEventInvokeConfig.DestinationConfig.OnFailure.Destination != nil {
61+
destinations.OnFailure.Destination = aws.String(*dspec.FunctionEventInvokeConfig.DestinationConfig.OnFailure.Destination)
5562
}
56-
input.DestinationConfig = destinations
57-
}
58-
if r.ko.Spec.FunctionEventInvokeConfig.MaximumEventAgeInSeconds != nil {
59-
input.MaximumEventAgeInSeconds = aws.Int64(*r.ko.Spec.FunctionEventInvokeConfig.MaximumEventAgeInSeconds)
6063
}
61-
if r.ko.Spec.FunctionEventInvokeConfig.MaximumRetryAttempts != nil {
62-
input.MaximumRetryAttempts = aws.Int64(*r.ko.Spec.FunctionEventInvokeConfig.MaximumRetryAttempts)
64+
if dspec.FunctionEventInvokeConfig.DestinationConfig.OnSuccess != nil {
65+
destinations.OnSuccess = &svcsdk.OnSuccess{}
66+
if dspec.FunctionEventInvokeConfig.DestinationConfig.OnSuccess.Destination != nil {
67+
destinations.OnSuccess.Destination = aws.String(*dspec.FunctionEventInvokeConfig.DestinationConfig.OnSuccess.Destination)
68+
}
6369
}
70+
input.DestinationConfig = destinations
71+
}
72+
if dspec.FunctionEventInvokeConfig.MaximumEventAgeInSeconds != nil {
73+
input.MaximumEventAgeInSeconds = aws.Int64(*dspec.FunctionEventInvokeConfig.MaximumEventAgeInSeconds)
74+
}
75+
if dspec.FunctionEventInvokeConfig.MaximumRetryAttempts != nil {
76+
input.MaximumRetryAttempts = aws.Int64(*dspec.FunctionEventInvokeConfig.MaximumRetryAttempts)
6477
}
78+
6579
_, err = rm.sdkapi.PutFunctionEventInvokeConfigWithContext(ctx, input)
6680
rm.metrics.RecordAPICall("UPDATE", "SyncEventInvokeConfig", err)
6781
if err != nil {
6882
return nil, err
6983
}
70-
7184
return r, nil
7285
}
7386

@@ -104,7 +117,7 @@ func (rm *resourceManager) updateProvisionedConcurrency(
104117
return nil
105118
}
106119

107-
func (rm *resourceManager) getProvisionedConcurrencyConfig(
120+
func (rm *resourceManager) setProvisionedConcurrencyConfig(
108121
ctx context.Context,
109122
ko *svcapitypes.Alias,
110123
) (err error) {
@@ -132,7 +145,35 @@ func (rm *resourceManager) getProvisionedConcurrencyConfig(
132145
return nil
133146
}
134147

135-
func (rm *resourceManager) getFunctionEventInvokeConfig(
148+
func (rm *resourceManager) setFunctionEventInvokeConfigFromResponse(
149+
ko *svcapitypes.Alias,
150+
getFunctionEventInvokeConfigOutput *svcsdk.GetFunctionEventInvokeConfigOutput,
151+
apiError error,
152+
) (err error) {
153+
154+
if apiError != nil {
155+
if awserr, ok := ackerr.AWSError(apiError); ok && (awserr.Code() == "EventInvokeConfigNotFoundException" || awserr.Code() == "ResourceNotFoundException") {
156+
ko.Spec.FunctionEventInvokeConfig = nil
157+
} else {
158+
return apiError
159+
}
160+
} else {
161+
cloudFunctionEventInvokeConfig := &svcapitypes.PutFunctionEventInvokeConfigInput{}
162+
cloudFunctionEventInvokeConfig.DestinationConfig = &svcapitypes.DestinationConfig{}
163+
cloudFunctionEventInvokeConfig.DestinationConfig.OnFailure = &svcapitypes.OnFailure{}
164+
cloudFunctionEventInvokeConfig.DestinationConfig.OnSuccess = &svcapitypes.OnSuccess{}
165+
cloudFunctionEventInvokeConfig.DestinationConfig.OnFailure.Destination = getFunctionEventInvokeConfigOutput.DestinationConfig.OnFailure.Destination
166+
cloudFunctionEventInvokeConfig.DestinationConfig.OnSuccess.Destination = getFunctionEventInvokeConfigOutput.DestinationConfig.OnSuccess.Destination
167+
cloudFunctionEventInvokeConfig.MaximumEventAgeInSeconds = getFunctionEventInvokeConfigOutput.MaximumEventAgeInSeconds
168+
cloudFunctionEventInvokeConfig.MaximumRetryAttempts = getFunctionEventInvokeConfigOutput.MaximumRetryAttempts
169+
ko.Spec.FunctionEventInvokeConfig = cloudFunctionEventInvokeConfig
170+
}
171+
return nil
172+
}
173+
174+
// getFunctionEventInvokeConfig will describe the fields that are
175+
// custom to the Alias resource
176+
func (rm *resourceManager) setFunctionEventInvokeConfig(
136177
ctx context.Context,
137178
ko *svcapitypes.Alias,
138179
) (err error) {
@@ -144,40 +185,11 @@ func (rm *resourceManager) getFunctionEventInvokeConfig(
144185
Qualifier: ko.Spec.Name,
145186
},
146187
)
147-
148188
rm.metrics.RecordAPICall("GET", "GetFunctionEventInvokeConfig", err)
149189

190+
err = rm.setFunctionEventInvokeConfigFromResponse(ko, getFunctionEventInvokeConfigOutput, err)
150191
if err != nil {
151-
if awserr, ok := ackerr.AWSError(err); ok && (awserr.Code() == "EventInvokeConfigNotFoundException" || awserr.Code() == "ResourceNotFoundException") {
152-
ko.Spec.FunctionEventInvokeConfig = nil
153-
} else {
154-
return err
155-
}
156-
} else {
157-
if getFunctionEventInvokeConfigOutput.DestinationConfig != nil {
158-
if getFunctionEventInvokeConfigOutput.DestinationConfig.OnFailure != nil {
159-
if getFunctionEventInvokeConfigOutput.DestinationConfig.OnFailure.Destination != nil {
160-
ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnFailure.Destination = getFunctionEventInvokeConfigOutput.DestinationConfig.OnFailure.Destination
161-
}
162-
}
163-
if getFunctionEventInvokeConfigOutput.DestinationConfig.OnSuccess != nil {
164-
if getFunctionEventInvokeConfigOutput.DestinationConfig.OnSuccess.Destination != nil {
165-
ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnSuccess.Destination = getFunctionEventInvokeConfigOutput.DestinationConfig.OnSuccess.Destination
166-
}
167-
}
168-
} else {
169-
ko.Spec.FunctionEventInvokeConfig.DestinationConfig = nil
170-
}
171-
if getFunctionEventInvokeConfigOutput.MaximumEventAgeInSeconds != nil {
172-
ko.Spec.FunctionEventInvokeConfig.MaximumEventAgeInSeconds = getFunctionEventInvokeConfigOutput.MaximumEventAgeInSeconds
173-
} else {
174-
ko.Spec.FunctionEventInvokeConfig.MaximumEventAgeInSeconds = nil
175-
}
176-
if getFunctionEventInvokeConfigOutput.DestinationConfig != nil {
177-
ko.Spec.FunctionEventInvokeConfig.MaximumRetryAttempts = getFunctionEventInvokeConfigOutput.MaximumRetryAttempts
178-
} else {
179-
ko.Spec.FunctionEventInvokeConfig.MaximumRetryAttempts = nil
180-
}
192+
return err
181193
}
182194

183195
return nil
@@ -191,14 +203,16 @@ func (rm *resourceManager) setResourceAdditionalFields(
191203
exit := rlog.Trace("rm.setResourceAdditionalFields")
192204
defer exit(err)
193205

194-
eic_err := rm.getFunctionEventInvokeConfig(ctx, ko)
195-
if eic_err != nil {
196-
return eic_err
206+
// To set Asynchronous Invocations for the function's alias
207+
err = rm.setFunctionEventInvokeConfig(ctx, ko)
208+
if err != nil {
209+
return err
197210
}
198211

199-
pc_err := rm.getProvisionedConcurrencyConfig(ctx, ko)
200-
if pc_err != nil {
201-
return pc_err
212+
// To set Provisioned Concurrency for the function's alias
213+
err = rm.setProvisionedConcurrencyConfig(ctx, ko)
214+
if err != nil {
215+
return err
202216
}
203217

204218
return nil

pkg/resource/function/hooks.go

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ func (rm *resourceManager) deleteFunctionCodeSigningConfig(
604604
}
605605

606606
// getFunctionConcurrency will describe the fields that are not return by GetFunctionConcurrency calls
607-
func (rm *resourceManager) getFunctionConcurrency(
607+
func (rm *resourceManager) setFunctionConcurrency(
608608
ctx context.Context,
609609
ko *svcapitypes.Function,
610610
) (err error) {
@@ -626,7 +626,7 @@ func (rm *resourceManager) getFunctionConcurrency(
626626

627627
// getFunctionCodeSigningConfig will describe the code signing
628628
// fields for the Function resource
629-
func (rm *resourceManager) getFunctionCodeSigningConfig(
629+
func (rm *resourceManager) setFunctionCodeSigningConfig(
630630
ctx context.Context,
631631
ko *svcapitypes.Function,
632632
) (err error) {
@@ -659,49 +659,22 @@ func (rm *resourceManager) setFunctionEventInvokeConfigFromResponse(
659659
return apiError
660660
}
661661
} else {
662-
if ko.Spec.FunctionEventInvokeConfig != nil {
663-
if getFunctionEventInvokeConfigOutput.DestinationConfig != nil {
664-
if getFunctionEventInvokeConfigOutput.DestinationConfig.OnFailure != nil {
665-
if getFunctionEventInvokeConfigOutput.DestinationConfig.OnFailure.Destination != nil {
666-
ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnFailure.Destination = getFunctionEventInvokeConfigOutput.DestinationConfig.OnFailure.Destination
667-
}
668-
}
669-
if getFunctionEventInvokeConfigOutput.DestinationConfig.OnSuccess != nil {
670-
if getFunctionEventInvokeConfigOutput.DestinationConfig.OnSuccess.Destination != nil {
671-
ko.Spec.FunctionEventInvokeConfig.DestinationConfig.OnSuccess.Destination = getFunctionEventInvokeConfigOutput.DestinationConfig.OnSuccess.Destination
672-
}
673-
}
674-
} else {
675-
ko.Spec.FunctionEventInvokeConfig.DestinationConfig = nil
676-
}
677-
if getFunctionEventInvokeConfigOutput.MaximumEventAgeInSeconds != nil {
678-
ko.Spec.FunctionEventInvokeConfig.MaximumEventAgeInSeconds = getFunctionEventInvokeConfigOutput.MaximumEventAgeInSeconds
679-
} else {
680-
ko.Spec.FunctionEventInvokeConfig.MaximumEventAgeInSeconds = nil
681-
}
682-
if getFunctionEventInvokeConfigOutput.DestinationConfig != nil {
683-
ko.Spec.FunctionEventInvokeConfig.MaximumRetryAttempts = getFunctionEventInvokeConfigOutput.MaximumRetryAttempts
684-
} else {
685-
ko.Spec.FunctionEventInvokeConfig.MaximumRetryAttempts = nil
686-
}
687-
} else {
688-
cloudFunctionEventInvokeConfig := &svcapitypes.PutFunctionEventInvokeConfigInput{}
689-
cloudFunctionEventInvokeConfig.DestinationConfig = &svcapitypes.DestinationConfig{}
690-
cloudFunctionEventInvokeConfig.DestinationConfig.OnFailure = &svcapitypes.OnFailure{}
691-
cloudFunctionEventInvokeConfig.DestinationConfig.OnSuccess = &svcapitypes.OnSuccess{}
692-
cloudFunctionEventInvokeConfig.DestinationConfig.OnFailure.Destination = getFunctionEventInvokeConfigOutput.DestinationConfig.OnFailure.Destination
693-
cloudFunctionEventInvokeConfig.DestinationConfig.OnSuccess.Destination = getFunctionEventInvokeConfigOutput.DestinationConfig.OnSuccess.Destination
694-
cloudFunctionEventInvokeConfig.MaximumEventAgeInSeconds = getFunctionEventInvokeConfigOutput.MaximumEventAgeInSeconds
695-
cloudFunctionEventInvokeConfig.MaximumRetryAttempts = getFunctionEventInvokeConfigOutput.MaximumRetryAttempts
696-
ko.Spec.FunctionEventInvokeConfig = cloudFunctionEventInvokeConfig
697-
}
662+
cloudFunctionEventInvokeConfig := &svcapitypes.PutFunctionEventInvokeConfigInput{}
663+
cloudFunctionEventInvokeConfig.DestinationConfig = &svcapitypes.DestinationConfig{}
664+
cloudFunctionEventInvokeConfig.DestinationConfig.OnFailure = &svcapitypes.OnFailure{}
665+
cloudFunctionEventInvokeConfig.DestinationConfig.OnSuccess = &svcapitypes.OnSuccess{}
666+
cloudFunctionEventInvokeConfig.DestinationConfig.OnFailure.Destination = getFunctionEventInvokeConfigOutput.DestinationConfig.OnFailure.Destination
667+
cloudFunctionEventInvokeConfig.DestinationConfig.OnSuccess.Destination = getFunctionEventInvokeConfigOutput.DestinationConfig.OnSuccess.Destination
668+
cloudFunctionEventInvokeConfig.MaximumEventAgeInSeconds = getFunctionEventInvokeConfigOutput.MaximumEventAgeInSeconds
669+
cloudFunctionEventInvokeConfig.MaximumRetryAttempts = getFunctionEventInvokeConfigOutput.MaximumRetryAttempts
670+
ko.Spec.FunctionEventInvokeConfig = cloudFunctionEventInvokeConfig
698671
}
699672
return nil
700673
}
701674

702675
// getFunctionEventInvokeConfig will describe the fields that are
703676
// custom to the Function resource
704-
func (rm *resourceManager) getFunctionEventInvokeConfig(
677+
func (rm *resourceManager) setFunctionEventInvokeConfig(
705678
ctx context.Context,
706679
ko *svcapitypes.Function,
707680
) (err error) {
@@ -733,20 +706,20 @@ func (rm *resourceManager) setResourceAdditionalFields(
733706
defer exit(err)
734707

735708
// To set Function Concurrency for the function
736-
err = rm.getFunctionConcurrency(ctx, ko)
709+
err = rm.setFunctionConcurrency(ctx, ko)
737710
if err != nil {
738711
return err
739712
}
740713

741714
// To set Asynchronous Invocations for the function
742-
err = rm.getFunctionEventInvokeConfig(ctx, ko)
715+
err = rm.setFunctionEventInvokeConfig(ctx, ko)
743716
if err != nil {
744717
return err
745718
}
746719

747720
// To set Code Signing Config based on the PackageType for the function
748721
if ko.Spec.PackageType != nil && *ko.Spec.PackageType == "Zip" {
749-
err = rm.getFunctionCodeSigningConfig(ctx, ko)
722+
err = rm.setFunctionCodeSigningConfig(ctx, ko)
750723
if err != nil {
751724
return err
752725
}

test/e2e/tests/test_alias.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,17 @@ def test_function_event_invoke_config(self, lambda_client, lambda_function):
324324
assert function_event_invoke_config["MaximumEventAgeInSeconds"] == 200
325325
assert function_event_invoke_config["MaximumRetryAttempts"] == 2
326326

327+
# Delete FunctionEventInvokeConfig
328+
cr = k8s.wait_resource_consumed_by_controller(ref)
329+
cr["spec"]["functionEventInvokeConfig"] = None
330+
331+
# Patch k8s resource
332+
k8s.patch_custom_resource(ref, cr)
333+
time.sleep(UPDATE_WAIT_AFTER_SECONDS)
334+
335+
# Check if FunctionEventInvokeConfig is deleted
336+
assert not lambda_validator.get_function_event_invoke_config_alias(lambda_function_name,resource_name)
337+
327338
# Delete k8s resource
328339
_, deleted = k8s.delete_custom_resource(ref)
329340
assert deleted

0 commit comments

Comments
 (0)