@@ -67,41 +67,18 @@ func (rm *resourceManager) customUpdateFunction(
67
67
return nil , requeueWaitWhilePending
68
68
}
69
69
70
- if delta .DifferentAt ("Spec.Code" ) {
71
- err = rm .updateFunctionCode (ctx , desired , delta )
72
- if err != nil {
73
- return nil , err
74
- }
75
- }
76
70
if delta .DifferentAt ("Spec.Tags" ) {
77
71
err = rm .updateFunctionTags (ctx , latest , desired )
78
72
if err != nil {
79
73
return nil , err
80
74
}
81
75
}
82
- if delta .DifferentAt ("Spec.Description" ) ||
83
- delta .DifferentAt ("Spec.Handler" ) ||
84
- delta .DifferentAt ("Spec.KMSKeyARN" ) ||
85
- delta .DifferentAt ("Spec.MemorySize" ) ||
86
- delta .DifferentAt ("Spec.Role" ) ||
87
- delta .DifferentAt ("Spec.Timeout" ) ||
88
- delta .DifferentAt ("Spec.Environement" ) ||
89
- delta .DifferentAt ("Spec.FileSystemConfigs" ) ||
90
- delta .DifferentAt ("Spec.ImageConfig" ) ||
91
- delta .DifferentAt ("Spec.TracingConfig" ) ||
92
- delta .DifferentAt ("Spec.VPCConfig" ) {
93
- err = rm .updateFunctionConfiguration (ctx , desired )
94
- if err != nil {
95
- return nil , err
96
- }
97
- }
98
76
if delta .DifferentAt ("Spec.ReservedConcurrentExecutions" ) {
99
77
err = rm .updateFunctionConcurrency (ctx , desired )
100
78
if err != nil {
101
79
return nil , err
102
80
}
103
81
}
104
-
105
82
if delta .DifferentAt ("Spec.CodeSigningConfigARN" ) {
106
83
if desired .ko .Spec .PackageType != nil && * desired .ko .Spec .PackageType == "Image" &&
107
84
desired .ko .Spec .CodeSigningConfigARN != nil && * desired .ko .Spec .CodeSigningConfigARN != "" {
@@ -114,6 +91,27 @@ func (rm *resourceManager) customUpdateFunction(
114
91
}
115
92
}
116
93
94
+ // Only try to update Spec.Code or Spec.Configuration at once. It is
95
+ // not correct to sequentially call UpdateFunctionConfiguration and
96
+ // UpdateFunctionCode because both of them can put the function in a
97
+ // Pending state.
98
+ switch {
99
+ case delta .DifferentAt ("Spec.Code" ):
100
+ err = rm .updateFunctionCode (ctx , desired , delta )
101
+ if err != nil {
102
+ return nil , err
103
+ }
104
+ case delta .DifferentExcept (
105
+ "Spec.Code" ,
106
+ "Spec.Tags" ,
107
+ "Spec.ReservedConcurrentExecutions" ,
108
+ "Spec.CodeSigningConfigARN" ):
109
+ err = rm .updateFunctionConfiguration (ctx , desired , delta )
110
+ if err != nil {
111
+ return nil , err
112
+ }
113
+ }
114
+
117
115
readOneLatest , err := rm .ReadOne (ctx , desired )
118
116
if err != nil {
119
117
return nil , err
@@ -126,6 +124,7 @@ func (rm *resourceManager) customUpdateFunction(
126
124
func (rm * resourceManager ) updateFunctionConfiguration (
127
125
ctx context.Context ,
128
126
desired * resource ,
127
+ delta * ackcompare.Delta ,
129
128
) error {
130
129
var err error
131
130
rlog := ackrtlog .FromContext (ctx )
@@ -137,86 +136,107 @@ func (rm *resourceManager) updateFunctionConfiguration(
137
136
FunctionName : aws .String (* dspec .Name ),
138
137
}
139
138
140
- if dspec .Description != nil {
141
- input .Description = aws .String (* dspec .Description )
142
- } else {
143
- input .Description = aws .String ("" )
144
- }
145
-
146
- if dspec .Handler != nil {
147
- input .Handler = aws .String (* dspec .Handler )
148
- } else {
149
- input .Handler = aws .String ("" )
139
+ if delta .DifferentAt ("Spec.Description" ) {
140
+ if dspec .Description != nil {
141
+ input .Description = aws .String (* dspec .Description )
142
+ } else {
143
+ input .Description = aws .String ("" )
144
+ }
150
145
}
151
146
152
- if dspec .KMSKeyARN != nil {
153
- input .KMSKeyArn = aws .String (* dspec .KMSKeyARN )
154
- } else {
155
- input .KMSKeyArn = aws .String ("" )
147
+ if delta .DifferentAt ("Spec.Handler" ) {
148
+ if dspec .Handler != nil {
149
+ input .Handler = aws .String (* dspec .Handler )
150
+ } else {
151
+ input .Handler = aws .String ("" )
152
+ }
156
153
}
157
154
158
- if dspec .Role != nil {
159
- input .Role = aws .String (* dspec .Role )
160
- } else {
161
- input .Role = aws .String ("" )
155
+ if delta .DifferentAt ("Spec.KMSKeyARN" ) {
156
+ if dspec .KMSKeyARN != nil {
157
+ input .KMSKeyArn = aws .String (* dspec .KMSKeyARN )
158
+ } else {
159
+ input .KMSKeyArn = aws .String ("" )
160
+ }
162
161
}
163
162
164
- if dspec .MemorySize != nil {
165
- input .MemorySize = aws .Int64 (* dspec .MemorySize )
166
- } else {
167
- input .MemorySize = aws .Int64 (0 )
163
+ if delta .DifferentAt ("Spec.Role" ) {
164
+ if dspec .Role != nil {
165
+ input .Role = aws .String (* dspec .Role )
166
+ } else {
167
+ input .Role = aws .String ("" )
168
+ }
168
169
}
169
170
170
- if dspec .Timeout != nil {
171
- input .Timeout = aws .Int64 (* dspec .Timeout )
172
- } else {
173
- input .Timeout = aws .Int64 (0 )
171
+ if delta .DifferentAt ("Spec.MemorySize" ) {
172
+ if dspec .MemorySize != nil {
173
+ input .MemorySize = aws .Int64 (* dspec .MemorySize )
174
+ } else {
175
+ input .MemorySize = aws .Int64 (0 )
176
+ }
174
177
}
175
178
176
- environment := & svcsdk.Environment {}
177
- if dspec .Environment != nil {
178
- environment .Variables = dspec .Environment .DeepCopy ().Variables
179
-
179
+ if delta .DifferentAt ("Spec.Timeout" ) {
180
+ if dspec .Timeout != nil {
181
+ input .Timeout = aws .Int64 (* dspec .Timeout )
182
+ } else {
183
+ input .Timeout = aws .Int64 (0 )
184
+ }
180
185
}
181
- input .Environment = environment
182
186
183
- fileSystemConfigs := []* svcsdk.FileSystemConfig {}
184
- if len (dspec .FileSystemConfigs ) > 0 {
185
- for _ , elem := range dspec .FileSystemConfigs {
186
- elemCopy := elem .DeepCopy ()
187
- fscElem := & svcsdk.FileSystemConfig {
188
- Arn : elemCopy .ARN ,
189
- LocalMountPath : elemCopy .LocalMountPath ,
187
+ if delta .DifferentAt ("Spec.Environment" ) {
188
+ environment := & svcsdk.Environment {}
189
+ if dspec .Environment != nil {
190
+ environment .Variables = dspec .Environment .DeepCopy ().Variables
191
+ }
192
+ input .Environment = environment
193
+ }
194
+
195
+ if delta .DifferentAt ("Spec.FileSystemConfigs" ) {
196
+ fileSystemConfigs := []* svcsdk.FileSystemConfig {}
197
+ if len (dspec .FileSystemConfigs ) > 0 {
198
+ for _ , elem := range dspec .FileSystemConfigs {
199
+ elemCopy := elem .DeepCopy ()
200
+ fscElem := & svcsdk.FileSystemConfig {
201
+ Arn : elemCopy .ARN ,
202
+ LocalMountPath : elemCopy .LocalMountPath ,
203
+ }
204
+ fileSystemConfigs = append (fileSystemConfigs , fscElem )
190
205
}
191
- fileSystemConfigs = append ( fileSystemConfigs , fscElem )
206
+ input . FileSystemConfigs = fileSystemConfigs
192
207
}
193
- input .FileSystemConfigs = fileSystemConfigs
194
208
}
195
209
196
- if dspec .ImageConfig != nil && dspec .Code .ImageURI != nil && * dspec .Code .ImageURI != "" {
197
- imageConfig := & svcsdk.ImageConfig {}
198
- if dspec .ImageConfig != nil {
199
- imageConfigCopy := dspec .ImageConfig .DeepCopy ()
200
- imageConfig .Command = imageConfigCopy .Command
201
- imageConfig .EntryPoint = imageConfigCopy .EntryPoint
202
- imageConfig .WorkingDirectory = imageConfigCopy .WorkingDirectory
210
+ if delta .DifferentAt ("Spec.ImageConfig" ) {
211
+ if dspec .ImageConfig != nil && dspec .Code .ImageURI != nil && * dspec .Code .ImageURI != "" {
212
+ imageConfig := & svcsdk.ImageConfig {}
213
+ if dspec .ImageConfig != nil {
214
+ imageConfigCopy := dspec .ImageConfig .DeepCopy ()
215
+ imageConfig .Command = imageConfigCopy .Command
216
+ imageConfig .EntryPoint = imageConfigCopy .EntryPoint
217
+ imageConfig .WorkingDirectory = imageConfigCopy .WorkingDirectory
218
+ }
219
+ input .ImageConfig = imageConfig
203
220
}
204
- input .ImageConfig = imageConfig
205
221
}
206
222
207
- tracingConfig := & svcsdk.TracingConfig {}
208
- if dspec .TracingConfig != nil {
209
- tracingConfig .Mode = aws .String (* dspec .TracingConfig .Mode )
223
+ if delta .DifferentAt ("Spec.TracingConfig" ) {
224
+ tracingConfig := & svcsdk.TracingConfig {}
225
+ if dspec .TracingConfig != nil {
226
+ tracingConfig .Mode = aws .String (* dspec .TracingConfig .Mode )
227
+ }
228
+ input .TracingConfig = tracingConfig
210
229
}
211
- input .TracingConfig = tracingConfig
212
230
213
- VPCConfig := & svcsdk.VpcConfig {}
214
- if dspec .VPCConfig != nil {
215
- vpcConfigCopy := dspec .VPCConfig .DeepCopy ()
216
- VPCConfig .SubnetIds = vpcConfigCopy .SubnetIDs
217
- VPCConfig .SecurityGroupIds = vpcConfigCopy .SecurityGroupIDs
231
+ if delta .DifferentAt ("Spec.VPCConfig" ) {
232
+ VPCConfig := & svcsdk.VpcConfig {}
233
+ if dspec .VPCConfig != nil {
234
+ vpcConfigCopy := dspec .VPCConfig .DeepCopy ()
235
+ VPCConfig .SubnetIds = vpcConfigCopy .SubnetIDs
236
+ VPCConfig .SecurityGroupIds = vpcConfigCopy .SecurityGroupIDs
237
+ }
238
+ input .VpcConfig = VPCConfig
218
239
}
219
- input .VpcConfig = VPCConfig
220
240
221
241
_ , err = rm .sdkapi .UpdateFunctionConfigurationWithContext (ctx , input )
222
242
rm .metrics .RecordAPICall ("UPDATE" , "UpdateFunctionConfiguration" , err )
0 commit comments