@@ -24,6 +24,8 @@ import (
24
24
svcapitypes "github.com/aws-controllers-k8s/lambda-controller/apis/v1alpha1"
25
25
)
26
26
27
+ // syncFunctionEventInvokeConfig calls `PutFunctionEventInvokeConfig` to update the fields
28
+ // or `DeleteFunctionEventInvokeConfig` if users removes the fields
27
29
func (rm * resourceManager ) syncEventInvokeConfig (
28
30
ctx context.Context ,
29
31
r * resource ,
@@ -32,42 +34,55 @@ func (rm *resourceManager) syncEventInvokeConfig(
32
34
exit := rlog .Trace ("rm.syncEventInvokeConfig" )
33
35
defer exit (err )
34
36
37
+ // Check if the user deleted the 'FunctionEventInvokeConfig' configuration
38
+ // If yes, delete FunctionEventInvokeConfig
39
+ if r .ko .Spec .FunctionEventInvokeConfig == nil {
40
+ input_delete := & svcsdk.DeleteFunctionEventInvokeConfigInput {
41
+ FunctionName : aws .String (* r .ko .Spec .FunctionName ),
42
+ Qualifier : aws .String (* r .ko .Spec .Name ),
43
+ }
44
+ _ , err = rm .sdkapi .DeleteFunctionEventInvokeConfigWithContext (ctx , input_delete )
45
+ rm .metrics .RecordAPICall ("DELETE" , "DeleteFunctionEventInvokeConfig" , err )
46
+ if err != nil {
47
+ return nil , err
48
+ }
49
+ return r , nil
50
+ }
51
+
35
52
dspec := r .ko .Spec
36
53
input := & svcsdk.PutFunctionEventInvokeConfigInput {
37
54
FunctionName : aws .String (* dspec .FunctionName ),
38
55
Qualifier : aws .String (* dspec .Name ),
39
56
}
40
57
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
- }
58
+ if dspec .FunctionEventInvokeConfig .DestinationConfig != nil {
59
+ destinations := & svcsdk.DestinationConfig {}
60
+ if dspec .FunctionEventInvokeConfig .DestinationConfig .OnFailure != nil {
61
+ destinations .OnFailure = & svcsdk.OnFailure {}
62
+ if dspec .FunctionEventInvokeConfig .DestinationConfig .OnFailure .Destination != nil {
63
+ destinations .OnFailure .Destination = aws .String (* dspec .FunctionEventInvokeConfig .DestinationConfig .OnFailure .Destination )
55
64
}
56
- input .DestinationConfig = destinations
57
- }
58
- if r .ko .Spec .FunctionEventInvokeConfig .MaximumEventAgeInSeconds != nil {
59
- input .MaximumEventAgeInSeconds = aws .Int64 (* r .ko .Spec .FunctionEventInvokeConfig .MaximumEventAgeInSeconds )
60
65
}
61
- if r .ko .Spec .FunctionEventInvokeConfig .MaximumRetryAttempts != nil {
62
- input .MaximumRetryAttempts = aws .Int64 (* r .ko .Spec .FunctionEventInvokeConfig .MaximumRetryAttempts )
66
+ if dspec .FunctionEventInvokeConfig .DestinationConfig .OnSuccess != nil {
67
+ destinations .OnSuccess = & svcsdk.OnSuccess {}
68
+ if dspec .FunctionEventInvokeConfig .DestinationConfig .OnSuccess .Destination != nil {
69
+ destinations .OnSuccess .Destination = aws .String (* dspec .FunctionEventInvokeConfig .DestinationConfig .OnSuccess .Destination )
70
+ }
63
71
}
72
+ input .DestinationConfig = destinations
73
+ }
74
+ if dspec .FunctionEventInvokeConfig .MaximumEventAgeInSeconds != nil {
75
+ input .MaximumEventAgeInSeconds = aws .Int64 (* dspec .FunctionEventInvokeConfig .MaximumEventAgeInSeconds )
76
+ }
77
+ if dspec .FunctionEventInvokeConfig .MaximumRetryAttempts != nil {
78
+ input .MaximumRetryAttempts = aws .Int64 (* dspec .FunctionEventInvokeConfig .MaximumRetryAttempts )
64
79
}
80
+
65
81
_ , err = rm .sdkapi .PutFunctionEventInvokeConfigWithContext (ctx , input )
66
82
rm .metrics .RecordAPICall ("UPDATE" , "SyncEventInvokeConfig" , err )
67
83
if err != nil {
68
84
return nil , err
69
85
}
70
-
71
86
return r , nil
72
87
}
73
88
@@ -108,7 +123,6 @@ func (rm *resourceManager) getProvisionedConcurrencyConfig(
108
123
ctx context.Context ,
109
124
ko * svcapitypes.Alias ,
110
125
) (err error ) {
111
-
112
126
var getProvisionedConcurrencyConfigOutput * svcsdk.GetProvisionedConcurrencyConfigOutput
113
127
getProvisionedConcurrencyConfigOutput , err = rm .sdkapi .GetProvisionedConcurrencyConfigWithContext (
114
128
ctx ,
@@ -132,10 +146,43 @@ func (rm *resourceManager) getProvisionedConcurrencyConfig(
132
146
return nil
133
147
}
134
148
135
- func (rm * resourceManager ) getFunctionEventInvokeConfig (
149
+ func (rm * resourceManager ) setFunctionEventInvokeConfigFromResponse (
150
+ ko * svcapitypes.Alias ,
151
+ getFunctionEventInvokeConfigOutput * svcsdk.GetFunctionEventInvokeConfigOutput ,
152
+ apiError error ,
153
+ ) (err error ) {
154
+
155
+ if apiError != nil {
156
+ if awserr , ok := ackerr .AWSError (apiError ); ok && (awserr .Code () == "EventInvokeConfigNotFoundException" || awserr .Code () == "ResourceNotFoundException" ) {
157
+ ko .Spec .FunctionEventInvokeConfig = nil
158
+ } else {
159
+ return apiError
160
+ }
161
+ } else {
162
+ // creating FunctionEventInvokeConfig object to store the values returned from `Get` call
163
+ cloudFunctionEventInvokeConfig := & svcapitypes.PutFunctionEventInvokeConfigInput {}
164
+ cloudFunctionEventInvokeConfig .DestinationConfig = & svcapitypes.DestinationConfig {}
165
+ cloudFunctionEventInvokeConfig .DestinationConfig .OnFailure = & svcapitypes.OnFailure {}
166
+ cloudFunctionEventInvokeConfig .DestinationConfig .OnSuccess = & svcapitypes.OnSuccess {}
167
+ cloudFunctionEventInvokeConfig .DestinationConfig .OnFailure .Destination = getFunctionEventInvokeConfigOutput .DestinationConfig .OnFailure .Destination
168
+ cloudFunctionEventInvokeConfig .DestinationConfig .OnSuccess .Destination = getFunctionEventInvokeConfigOutput .DestinationConfig .OnSuccess .Destination
169
+ cloudFunctionEventInvokeConfig .MaximumEventAgeInSeconds = getFunctionEventInvokeConfigOutput .MaximumEventAgeInSeconds
170
+ cloudFunctionEventInvokeConfig .MaximumRetryAttempts = getFunctionEventInvokeConfigOutput .MaximumRetryAttempts
171
+ ko .Spec .FunctionEventInvokeConfig = cloudFunctionEventInvokeConfig
172
+ }
173
+ return nil
174
+ }
175
+
176
+ // setFunctionEventInvokeConfig sets the fields to set asynchronous invocation
177
+ // for Function's Alias
178
+ func (rm * resourceManager ) setFunctionEventInvokeConfig (
136
179
ctx context.Context ,
137
180
ko * svcapitypes.Alias ,
138
181
) (err error ) {
182
+ rlog := ackrtlog .FromContext (ctx )
183
+ exit := rlog .Trace ("rm.setFunctionEventInvokeConfig" )
184
+ defer exit (err )
185
+
139
186
var getFunctionEventInvokeConfigOutput * svcsdk.GetFunctionEventInvokeConfigOutput
140
187
getFunctionEventInvokeConfigOutput , err = rm .sdkapi .GetFunctionEventInvokeConfigWithContext (
141
188
ctx ,
@@ -144,40 +191,11 @@ func (rm *resourceManager) getFunctionEventInvokeConfig(
144
191
Qualifier : ko .Spec .Name ,
145
192
},
146
193
)
147
-
148
194
rm .metrics .RecordAPICall ("GET" , "GetFunctionEventInvokeConfig" , err )
149
195
196
+ err = rm .setFunctionEventInvokeConfigFromResponse (ko , getFunctionEventInvokeConfigOutput , err )
150
197
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
- }
198
+ return err
181
199
}
182
200
183
201
return nil
@@ -191,14 +209,16 @@ func (rm *resourceManager) setResourceAdditionalFields(
191
209
exit := rlog .Trace ("rm.setResourceAdditionalFields" )
192
210
defer exit (err )
193
211
194
- eic_err := rm .getFunctionEventInvokeConfig (ctx , ko )
195
- if eic_err != nil {
196
- return eic_err
212
+ // To set Asynchronous Invocations for the function's alias
213
+ err = rm .setFunctionEventInvokeConfig (ctx , ko )
214
+ if err != nil {
215
+ return err
197
216
}
198
217
199
- pc_err := rm .getProvisionedConcurrencyConfig (ctx , ko )
200
- if pc_err != nil {
201
- return pc_err
218
+ // To set Provisioned Concurrency for the function's alias
219
+ err = rm .getProvisionedConcurrencyConfig (ctx , ko )
220
+ if err != nil {
221
+ return err
202
222
}
203
223
204
224
return nil
0 commit comments