Skip to content

Commit 329e1d6

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

File tree

4 files changed

+103
-103
lines changed

4 files changed

+103
-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: 75 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,36 @@ 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+
// creating FunctionEventInvokeConfig object to store the values returned from `Get` call
162+
cloudFunctionEventInvokeConfig := &svcapitypes.PutFunctionEventInvokeConfigInput{}
163+
cloudFunctionEventInvokeConfig.DestinationConfig = &svcapitypes.DestinationConfig{}
164+
cloudFunctionEventInvokeConfig.DestinationConfig.OnFailure = &svcapitypes.OnFailure{}
165+
cloudFunctionEventInvokeConfig.DestinationConfig.OnSuccess = &svcapitypes.OnSuccess{}
166+
cloudFunctionEventInvokeConfig.DestinationConfig.OnFailure.Destination = getFunctionEventInvokeConfigOutput.DestinationConfig.OnFailure.Destination
167+
cloudFunctionEventInvokeConfig.DestinationConfig.OnSuccess.Destination = getFunctionEventInvokeConfigOutput.DestinationConfig.OnSuccess.Destination
168+
cloudFunctionEventInvokeConfig.MaximumEventAgeInSeconds = getFunctionEventInvokeConfigOutput.MaximumEventAgeInSeconds
169+
cloudFunctionEventInvokeConfig.MaximumRetryAttempts = getFunctionEventInvokeConfigOutput.MaximumRetryAttempts
170+
ko.Spec.FunctionEventInvokeConfig = cloudFunctionEventInvokeConfig
171+
}
172+
return nil
173+
}
174+
175+
// getFunctionEventInvokeConfig will describe the fields that are
176+
// custom to the Alias resource
177+
func (rm *resourceManager) setFunctionEventInvokeConfig(
136178
ctx context.Context,
137179
ko *svcapitypes.Alias,
138180
) (err error) {
@@ -144,40 +186,11 @@ func (rm *resourceManager) getFunctionEventInvokeConfig(
144186
Qualifier: ko.Spec.Name,
145187
},
146188
)
147-
148189
rm.metrics.RecordAPICall("GET", "GetFunctionEventInvokeConfig", err)
149190

191+
err = rm.setFunctionEventInvokeConfigFromResponse(ko, getFunctionEventInvokeConfigOutput, err)
150192
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-
}
193+
return err
181194
}
182195

183196
return nil
@@ -191,14 +204,16 @@ func (rm *resourceManager) setResourceAdditionalFields(
191204
exit := rlog.Trace("rm.setResourceAdditionalFields")
192205
defer exit(err)
193206

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

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

204219
return nil

pkg/resource/function/hooks.go

Lines changed: 16 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,23 @@ 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+
// creating FunctionEventInvokeConfig object to store the values returned from `Get` call
663+
cloudFunctionEventInvokeConfig := &svcapitypes.PutFunctionEventInvokeConfigInput{}
664+
cloudFunctionEventInvokeConfig.DestinationConfig = &svcapitypes.DestinationConfig{}
665+
cloudFunctionEventInvokeConfig.DestinationConfig.OnFailure = &svcapitypes.OnFailure{}
666+
cloudFunctionEventInvokeConfig.DestinationConfig.OnSuccess = &svcapitypes.OnSuccess{}
667+
cloudFunctionEventInvokeConfig.DestinationConfig.OnFailure.Destination = getFunctionEventInvokeConfigOutput.DestinationConfig.OnFailure.Destination
668+
cloudFunctionEventInvokeConfig.DestinationConfig.OnSuccess.Destination = getFunctionEventInvokeConfigOutput.DestinationConfig.OnSuccess.Destination
669+
cloudFunctionEventInvokeConfig.MaximumEventAgeInSeconds = getFunctionEventInvokeConfigOutput.MaximumEventAgeInSeconds
670+
cloudFunctionEventInvokeConfig.MaximumRetryAttempts = getFunctionEventInvokeConfigOutput.MaximumRetryAttempts
671+
ko.Spec.FunctionEventInvokeConfig = cloudFunctionEventInvokeConfig
698672
}
699673
return nil
700674
}
701675

702676
// getFunctionEventInvokeConfig will describe the fields that are
703677
// custom to the Function resource
704-
func (rm *resourceManager) getFunctionEventInvokeConfig(
678+
func (rm *resourceManager) setFunctionEventInvokeConfig(
705679
ctx context.Context,
706680
ko *svcapitypes.Function,
707681
) (err error) {
@@ -733,20 +707,20 @@ func (rm *resourceManager) setResourceAdditionalFields(
733707
defer exit(err)
734708

735709
// To set Function Concurrency for the function
736-
err = rm.getFunctionConcurrency(ctx, ko)
710+
err = rm.setFunctionConcurrency(ctx, ko)
737711
if err != nil {
738712
return err
739713
}
740714

741715
// To set Asynchronous Invocations for the function
742-
err = rm.getFunctionEventInvokeConfig(ctx, ko)
716+
err = rm.setFunctionEventInvokeConfig(ctx, ko)
743717
if err != nil {
744718
return err
745719
}
746720

747721
// To set Code Signing Config based on the PackageType for the function
748722
if ko.Spec.PackageType != nil && *ko.Spec.PackageType == "Zip" {
749-
err = rm.getFunctionCodeSigningConfig(ctx, ko)
723+
err = rm.setFunctionCodeSigningConfig(ctx, ko)
750724
if err != nil {
751725
return err
752726
}

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)