Skip to content

Commit 506f38e

Browse files
committed
Add support for updating Layers
1 parent a9250ad commit 506f38e

File tree

4 files changed

+76
-65
lines changed

4 files changed

+76
-65
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: "2024-04-16T23:40:41Z"
2+
build_date: "2024-04-18T22:18:38Z"
33
build_hash: 37f4ba2b5a121a8786bc516e9ec4aa0b8b590c7d
44
go_version: go1.21.6
55
version: v0.33.0-1-g37f4ba2

pkg/resource/function/hooks.go

Lines changed: 68 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,38 @@ func (rm *resourceManager) updateFunctionConfiguration(
179179
}
180180
}
181181

182+
if delta.DifferentAt("Spec.Environment") {
183+
environment := &svcsdk.Environment{}
184+
if dspec.Environment != nil {
185+
environment.Variables = dspec.Environment.DeepCopy().Variables
186+
}
187+
input.Environment = environment
188+
}
189+
190+
if delta.DifferentAt("Spec.EphemeralStorage") {
191+
ephemeralStorage := &svcsdk.EphemeralStorage{}
192+
if dspec.EphemeralStorage != nil {
193+
ephemeralStorageCopy := dspec.EphemeralStorage.DeepCopy()
194+
ephemeralStorage.Size = ephemeralStorageCopy.Size
195+
}
196+
input.EphemeralStorage = ephemeralStorage
197+
}
198+
199+
if delta.DifferentAt("Spec.FileSystemConfigs") {
200+
fileSystemConfigs := []*svcsdk.FileSystemConfig{}
201+
if len(dspec.FileSystemConfigs) > 0 {
202+
for _, elem := range dspec.FileSystemConfigs {
203+
elemCopy := elem.DeepCopy()
204+
fscElem := &svcsdk.FileSystemConfig{
205+
Arn: elemCopy.ARN,
206+
LocalMountPath: elemCopy.LocalMountPath,
207+
}
208+
fileSystemConfigs = append(fileSystemConfigs, fscElem)
209+
}
210+
input.FileSystemConfigs = fileSystemConfigs
211+
}
212+
}
213+
182214
if delta.DifferentAt("Spec.Handler") {
183215
if dspec.Handler != nil {
184216
input.Handler = aws.String(*dspec.Handler)
@@ -187,6 +219,19 @@ func (rm *resourceManager) updateFunctionConfiguration(
187219
}
188220
}
189221

222+
if delta.DifferentAt("Spec.ImageConfig") {
223+
if dspec.ImageConfig != nil && dspec.Code.ImageURI != nil && *dspec.Code.ImageURI != "" {
224+
imageConfig := &svcsdk.ImageConfig{}
225+
if dspec.ImageConfig != nil {
226+
imageConfigCopy := dspec.ImageConfig.DeepCopy()
227+
imageConfig.Command = imageConfigCopy.Command
228+
imageConfig.EntryPoint = imageConfigCopy.EntryPoint
229+
imageConfig.WorkingDirectory = imageConfigCopy.WorkingDirectory
230+
}
231+
input.ImageConfig = imageConfig
232+
}
233+
}
234+
190235
if delta.DifferentAt("Spec.KMSKeyARN") {
191236
if dspec.KMSKeyARN != nil {
192237
input.KMSKeyArn = aws.String(*dspec.KMSKeyARN)
@@ -195,11 +240,14 @@ func (rm *resourceManager) updateFunctionConfiguration(
195240
}
196241
}
197242

198-
if delta.DifferentAt("Spec.Role") {
199-
if dspec.Role != nil {
200-
input.Role = aws.String(*dspec.Role)
201-
} else {
202-
input.Role = aws.String("")
243+
if delta.DifferentAt("Spec.Layers") {
244+
layers := []*string{}
245+
if len(dspec.Layers) > 0 {
246+
for _, iter := range dspec.Layers {
247+
var elem string = *iter
248+
layers = append(layers, &elem)
249+
}
250+
input.Layers = layers
203251
}
204252
}
205253

@@ -211,47 +259,28 @@ func (rm *resourceManager) updateFunctionConfiguration(
211259
}
212260
}
213261

214-
if delta.DifferentAt("Spec.Timeout") {
215-
if dspec.Timeout != nil {
216-
input.Timeout = aws.Int64(*dspec.Timeout)
262+
if delta.DifferentAt("Spec.Role") {
263+
if dspec.Role != nil {
264+
input.Role = aws.String(*dspec.Role)
217265
} else {
218-
input.Timeout = aws.Int64(0)
219-
}
220-
}
221-
222-
if delta.DifferentAt("Spec.Environment") {
223-
environment := &svcsdk.Environment{}
224-
if dspec.Environment != nil {
225-
environment.Variables = dspec.Environment.DeepCopy().Variables
266+
input.Role = aws.String("")
226267
}
227-
input.Environment = environment
228268
}
229269

230-
if delta.DifferentAt("Spec.FileSystemConfigs") {
231-
fileSystemConfigs := []*svcsdk.FileSystemConfig{}
232-
if len(dspec.FileSystemConfigs) > 0 {
233-
for _, elem := range dspec.FileSystemConfigs {
234-
elemCopy := elem.DeepCopy()
235-
fscElem := &svcsdk.FileSystemConfig{
236-
Arn: elemCopy.ARN,
237-
LocalMountPath: elemCopy.LocalMountPath,
238-
}
239-
fileSystemConfigs = append(fileSystemConfigs, fscElem)
240-
}
241-
input.FileSystemConfigs = fileSystemConfigs
270+
if delta.DifferentAt(("Spec.SnapStart")) {
271+
snapStart := &svcsdk.SnapStart{}
272+
if dspec.SnapStart != nil {
273+
snapStartCopy := dspec.SnapStart.DeepCopy()
274+
snapStart.ApplyOn = snapStartCopy.ApplyOn
242275
}
276+
input.SnapStart = snapStart
243277
}
244278

245-
if delta.DifferentAt("Spec.ImageConfig") {
246-
if dspec.ImageConfig != nil && dspec.Code.ImageURI != nil && *dspec.Code.ImageURI != "" {
247-
imageConfig := &svcsdk.ImageConfig{}
248-
if dspec.ImageConfig != nil {
249-
imageConfigCopy := dspec.ImageConfig.DeepCopy()
250-
imageConfig.Command = imageConfigCopy.Command
251-
imageConfig.EntryPoint = imageConfigCopy.EntryPoint
252-
imageConfig.WorkingDirectory = imageConfigCopy.WorkingDirectory
253-
}
254-
input.ImageConfig = imageConfig
279+
if delta.DifferentAt("Spec.Timeout") {
280+
if dspec.Timeout != nil {
281+
input.Timeout = aws.Int64(*dspec.Timeout)
282+
} else {
283+
input.Timeout = aws.Int64(0)
255284
}
256285
}
257286

@@ -273,24 +302,6 @@ func (rm *resourceManager) updateFunctionConfiguration(
273302
input.VpcConfig = VPCConfig
274303
}
275304

276-
if delta.DifferentAt("Spec.EphemeralStorage") {
277-
ephemeralStorage := &svcsdk.EphemeralStorage{}
278-
if dspec.EphemeralStorage != nil {
279-
ephemeralStorageCopy := dspec.EphemeralStorage.DeepCopy()
280-
ephemeralStorage.Size = ephemeralStorageCopy.Size
281-
}
282-
input.EphemeralStorage = ephemeralStorage
283-
}
284-
285-
if delta.DifferentAt(("Spec.SnapStart")) {
286-
snapStart := &svcsdk.SnapStart{}
287-
if dspec.SnapStart != nil {
288-
snapStartCopy := dspec.SnapStart.DeepCopy()
289-
snapStart.ApplyOn = snapStartCopy.ApplyOn
290-
}
291-
input.SnapStart = snapStart
292-
}
293-
294305
_, err = rm.sdkapi.UpdateFunctionConfigurationWithContext(ctx, input)
295306
rm.metrics.RecordAPICall("UPDATE", "UpdateFunctionConfiguration", err)
296307
if err != nil {

pkg/resource/function/sdk.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/hooks/function/sdk_read_one_post_set_output.go.tpl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
if resp.Code != nil {
2-
// We need to keep the desired .Code s3Bucket s3Key and s3ObjectVersion
3-
// part of the function's spec. So instead of setting Spec.Code to nil
4-
// we only set ImageURI
5-
//
6-
// When adopting a Function resource, Spec.Code field should be manually
7-
// initialised before injecting ImageURI.
82
if ko.Spec.Code == nil {
93
ko.Spec.Code = &svcapitypes.FunctionCode{}
104
}
@@ -13,7 +7,8 @@
137
}
148
}
159
if resp.Configuration.Layers != nil {
16-
f16 := []*svcapitypes.Layer{}
10+
f17 := []*svcapitypes.Layer{}
11+
layer := []*string{}
1712
for _, f16iter := range resp.Configuration.Layers {
1813
f16elem := &svcapitypes.Layer{}
1914
if f16iter.Arn != nil {
@@ -29,7 +24,9 @@
2924
f16elem.SigningProfileVersionARN = f16iter.SigningProfileVersionArn
3025
}
3126
f16 = append(f16, f16elem)
27+
layer = append(layer, f16iter.Arn)
3228
}
29+
ko.Spec.Layers = layer
3330
ko.Status.LayerStatuses = f16
3431
} else {
3532
ko.Status.LayerStatuses = nil

0 commit comments

Comments
 (0)