@@ -24,6 +24,8 @@ import (
24
24
svcapitypes "github.com/aws-controllers-k8s/lambda-controller/apis/v1alpha1"
25
25
)
26
26
27
+ // syncEventInvokeConfig 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
65
}
58
- if r . ko . Spec . FunctionEventInvokeConfig .MaximumEventAgeInSeconds != nil {
59
- input . MaximumEventAgeInSeconds = aws . Int64 ( * r . ko . Spec . FunctionEventInvokeConfig . MaximumEventAgeInSeconds )
60
- }
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
64
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 )
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
@@ -148,12 +163,33 @@ func (rm *resourceManager) setProvisionedConcurrencyConfig(
148
163
return nil
149
164
}
150
165
151
- // getFunctionEventInvokeConfig will describe the fields that are
152
- // custom to the Alias resource
153
- func (rm * resourceManager ) getFunctionEventInvokeConfig (
166
+ func (rm * resourceManager ) setFunctionEventInvokeConfigFromResponse (
167
+ ko * svcapitypes.Alias ,
168
+ getFunctionEventInvokeConfigOutput * svcsdk.GetFunctionEventInvokeConfigOutput ,
169
+ ) {
170
+ // creating FunctionEventInvokeConfig object to store the values returned from `Get` call
171
+ cloudFunctionEventInvokeConfig := & svcapitypes.PutFunctionEventInvokeConfigInput {}
172
+ cloudFunctionEventInvokeConfig .DestinationConfig = & svcapitypes.DestinationConfig {}
173
+ cloudFunctionEventInvokeConfig .DestinationConfig .OnFailure = & svcapitypes.OnFailure {}
174
+ cloudFunctionEventInvokeConfig .DestinationConfig .OnSuccess = & svcapitypes.OnSuccess {}
175
+ cloudFunctionEventInvokeConfig .DestinationConfig .OnFailure .Destination = getFunctionEventInvokeConfigOutput .DestinationConfig .OnFailure .Destination
176
+ cloudFunctionEventInvokeConfig .DestinationConfig .OnSuccess .Destination = getFunctionEventInvokeConfigOutput .DestinationConfig .OnSuccess .Destination
177
+ cloudFunctionEventInvokeConfig .MaximumEventAgeInSeconds = getFunctionEventInvokeConfigOutput .MaximumEventAgeInSeconds
178
+ cloudFunctionEventInvokeConfig .MaximumRetryAttempts = getFunctionEventInvokeConfigOutput .MaximumRetryAttempts
179
+ ko .Spec .FunctionEventInvokeConfig = cloudFunctionEventInvokeConfig
180
+
181
+ }
182
+
183
+ // setFunctionEventInvokeConfig sets the fields to set asynchronous invocation
184
+ // for Function's Alias
185
+ func (rm * resourceManager ) setFunctionEventInvokeConfig (
154
186
ctx context.Context ,
155
187
ko * svcapitypes.Alias ,
156
188
) (err error ) {
189
+ rlog := ackrtlog .FromContext (ctx )
190
+ exit := rlog .Trace ("rm.setFunctionEventInvokeConfig" )
191
+ defer exit (err )
192
+
157
193
var getFunctionEventInvokeConfigOutput * svcsdk.GetFunctionEventInvokeConfigOutput
158
194
getFunctionEventInvokeConfigOutput , err = rm .sdkapi .GetFunctionEventInvokeConfigWithContext (
159
195
ctx ,
@@ -162,7 +198,6 @@ func (rm *resourceManager) getFunctionEventInvokeConfig(
162
198
Qualifier : ko .Spec .Name ,
163
199
},
164
200
)
165
-
166
201
rm .metrics .RecordAPICall ("GET" , "GetFunctionEventInvokeConfig" , err )
167
202
168
203
if err != nil {
@@ -172,30 +207,7 @@ func (rm *resourceManager) getFunctionEventInvokeConfig(
172
207
return err
173
208
}
174
209
} else {
175
- if getFunctionEventInvokeConfigOutput .DestinationConfig != nil {
176
- if getFunctionEventInvokeConfigOutput .DestinationConfig .OnFailure != nil {
177
- if getFunctionEventInvokeConfigOutput .DestinationConfig .OnFailure .Destination != nil {
178
- ko .Spec .FunctionEventInvokeConfig .DestinationConfig .OnFailure .Destination = getFunctionEventInvokeConfigOutput .DestinationConfig .OnFailure .Destination
179
- }
180
- }
181
- if getFunctionEventInvokeConfigOutput .DestinationConfig .OnSuccess != nil {
182
- if getFunctionEventInvokeConfigOutput .DestinationConfig .OnSuccess .Destination != nil {
183
- ko .Spec .FunctionEventInvokeConfig .DestinationConfig .OnSuccess .Destination = getFunctionEventInvokeConfigOutput .DestinationConfig .OnSuccess .Destination
184
- }
185
- }
186
- } else {
187
- ko .Spec .FunctionEventInvokeConfig .DestinationConfig = nil
188
- }
189
- if getFunctionEventInvokeConfigOutput .MaximumEventAgeInSeconds != nil {
190
- ko .Spec .FunctionEventInvokeConfig .MaximumEventAgeInSeconds = getFunctionEventInvokeConfigOutput .MaximumEventAgeInSeconds
191
- } else {
192
- ko .Spec .FunctionEventInvokeConfig .MaximumEventAgeInSeconds = nil
193
- }
194
- if getFunctionEventInvokeConfigOutput .DestinationConfig != nil {
195
- ko .Spec .FunctionEventInvokeConfig .MaximumRetryAttempts = getFunctionEventInvokeConfigOutput .MaximumRetryAttempts
196
- } else {
197
- ko .Spec .FunctionEventInvokeConfig .MaximumRetryAttempts = nil
198
- }
210
+ rm .setFunctionEventInvokeConfigFromResponse (ko , getFunctionEventInvokeConfigOutput )
199
211
}
200
212
201
213
return nil
@@ -212,9 +224,9 @@ func (rm *resourceManager) setResourceAdditionalFields(
212
224
defer exit (err )
213
225
214
226
// To set Asynchronous Invocations for the function's alias
215
- eic_err : = rm .getFunctionEventInvokeConfig (ctx , ko )
216
- if eic_err != nil {
217
- return eic_err
227
+ err = rm .setFunctionEventInvokeConfig (ctx , ko )
228
+ if err != nil {
229
+ return err
218
230
}
219
231
220
232
// To set Provisioned Concurrency for the function's alias
0 commit comments