Skip to content

fix: Update support for Layers #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apis/v1alpha1/ack-generate-metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ack_generate_info:
build_date: "2024-04-16T23:40:41Z"
build_date: "2024-04-18T22:18:38Z"
build_hash: 37f4ba2b5a121a8786bc516e9ec4aa0b8b590c7d
go_version: go1.21.6
version: v0.33.0-1-g37f4ba2
Expand Down
125 changes: 68 additions & 57 deletions pkg/resource/function/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,38 @@ func (rm *resourceManager) updateFunctionConfiguration(
}
}

if delta.DifferentAt("Spec.Environment") {
environment := &svcsdk.Environment{}
if dspec.Environment != nil {
environment.Variables = dspec.Environment.DeepCopy().Variables
}
input.Environment = environment
}

if delta.DifferentAt("Spec.EphemeralStorage") {
ephemeralStorage := &svcsdk.EphemeralStorage{}
if dspec.EphemeralStorage != nil {
ephemeralStorageCopy := dspec.EphemeralStorage.DeepCopy()
ephemeralStorage.Size = ephemeralStorageCopy.Size
}
input.EphemeralStorage = ephemeralStorage
}

if delta.DifferentAt("Spec.FileSystemConfigs") {
fileSystemConfigs := []*svcsdk.FileSystemConfig{}
if len(dspec.FileSystemConfigs) > 0 {
for _, elem := range dspec.FileSystemConfigs {
elemCopy := elem.DeepCopy()
fscElem := &svcsdk.FileSystemConfig{
Arn: elemCopy.ARN,
LocalMountPath: elemCopy.LocalMountPath,
}
fileSystemConfigs = append(fileSystemConfigs, fscElem)
}
input.FileSystemConfigs = fileSystemConfigs
}
}
Comment on lines +182 to +212
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Vandita2020 ! How are environement/ephemeralStorage/FileSystemConfigs/Timeouts affecting to layers?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, I have just rearranged them according to the order in the API. Please ignore them, no changes for them.


if delta.DifferentAt("Spec.Handler") {
if dspec.Handler != nil {
input.Handler = aws.String(*dspec.Handler)
Expand All @@ -187,6 +219,19 @@ func (rm *resourceManager) updateFunctionConfiguration(
}
}

if delta.DifferentAt("Spec.ImageConfig") {
if dspec.ImageConfig != nil && dspec.Code.ImageURI != nil && *dspec.Code.ImageURI != "" {
imageConfig := &svcsdk.ImageConfig{}
if dspec.ImageConfig != nil {
imageConfigCopy := dspec.ImageConfig.DeepCopy()
imageConfig.Command = imageConfigCopy.Command
imageConfig.EntryPoint = imageConfigCopy.EntryPoint
imageConfig.WorkingDirectory = imageConfigCopy.WorkingDirectory
}
input.ImageConfig = imageConfig
}
}

if delta.DifferentAt("Spec.KMSKeyARN") {
if dspec.KMSKeyARN != nil {
input.KMSKeyArn = aws.String(*dspec.KMSKeyARN)
Expand All @@ -195,11 +240,14 @@ func (rm *resourceManager) updateFunctionConfiguration(
}
}

if delta.DifferentAt("Spec.Role") {
if dspec.Role != nil {
input.Role = aws.String(*dspec.Role)
} else {
input.Role = aws.String("")
if delta.DifferentAt("Spec.Layers") {
layers := []*string{}
if len(dspec.Layers) > 0 {
for _, iter := range dspec.Layers {
var elem string = *iter
layers = append(layers, &elem)
}
input.Layers = layers
}
}

Expand All @@ -211,47 +259,28 @@ func (rm *resourceManager) updateFunctionConfiguration(
}
}

if delta.DifferentAt("Spec.Timeout") {
if dspec.Timeout != nil {
input.Timeout = aws.Int64(*dspec.Timeout)
if delta.DifferentAt("Spec.Role") {
if dspec.Role != nil {
input.Role = aws.String(*dspec.Role)
} else {
input.Timeout = aws.Int64(0)
}
}

if delta.DifferentAt("Spec.Environment") {
environment := &svcsdk.Environment{}
if dspec.Environment != nil {
environment.Variables = dspec.Environment.DeepCopy().Variables
input.Role = aws.String("")
}
input.Environment = environment
}

if delta.DifferentAt("Spec.FileSystemConfigs") {
fileSystemConfigs := []*svcsdk.FileSystemConfig{}
if len(dspec.FileSystemConfigs) > 0 {
for _, elem := range dspec.FileSystemConfigs {
elemCopy := elem.DeepCopy()
fscElem := &svcsdk.FileSystemConfig{
Arn: elemCopy.ARN,
LocalMountPath: elemCopy.LocalMountPath,
}
fileSystemConfigs = append(fileSystemConfigs, fscElem)
}
input.FileSystemConfigs = fileSystemConfigs
if delta.DifferentAt(("Spec.SnapStart")) {
snapStart := &svcsdk.SnapStart{}
if dspec.SnapStart != nil {
snapStartCopy := dspec.SnapStart.DeepCopy()
snapStart.ApplyOn = snapStartCopy.ApplyOn
}
input.SnapStart = snapStart
}

if delta.DifferentAt("Spec.ImageConfig") {
if dspec.ImageConfig != nil && dspec.Code.ImageURI != nil && *dspec.Code.ImageURI != "" {
imageConfig := &svcsdk.ImageConfig{}
if dspec.ImageConfig != nil {
imageConfigCopy := dspec.ImageConfig.DeepCopy()
imageConfig.Command = imageConfigCopy.Command
imageConfig.EntryPoint = imageConfigCopy.EntryPoint
imageConfig.WorkingDirectory = imageConfigCopy.WorkingDirectory
}
input.ImageConfig = imageConfig
if delta.DifferentAt("Spec.Timeout") {
if dspec.Timeout != nil {
input.Timeout = aws.Int64(*dspec.Timeout)
} else {
input.Timeout = aws.Int64(0)
}
}

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

if delta.DifferentAt("Spec.EphemeralStorage") {
ephemeralStorage := &svcsdk.EphemeralStorage{}
if dspec.EphemeralStorage != nil {
ephemeralStorageCopy := dspec.EphemeralStorage.DeepCopy()
ephemeralStorage.Size = ephemeralStorageCopy.Size
}
input.EphemeralStorage = ephemeralStorage
}

if delta.DifferentAt(("Spec.SnapStart")) {
snapStart := &svcsdk.SnapStart{}
if dspec.SnapStart != nil {
snapStartCopy := dspec.SnapStart.DeepCopy()
snapStart.ApplyOn = snapStartCopy.ApplyOn
}
input.SnapStart = snapStart
}

_, err = rm.sdkapi.UpdateFunctionConfigurationWithContext(ctx, input)
rm.metrics.RecordAPICall("UPDATE", "UpdateFunctionConfiguration", err)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/resource/function/sdk.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions templates/hooks/function/sdk_read_one_post_set_output.go.tpl
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
if resp.Code != nil {
// We need to keep the desired .Code s3Bucket s3Key and s3ObjectVersion
// part of the function's spec. So instead of setting Spec.Code to nil
// we only set ImageURI
//
// When adopting a Function resource, Spec.Code field should be manually
// initialised before injecting ImageURI.
if ko.Spec.Code == nil {
ko.Spec.Code = &svcapitypes.FunctionCode{}
}
Expand All @@ -13,7 +7,8 @@
}
}
if resp.Configuration.Layers != nil {
f16 := []*svcapitypes.Layer{}
f17 := []*svcapitypes.Layer{}
layer := []*string{}
for _, f16iter := range resp.Configuration.Layers {
f16elem := &svcapitypes.Layer{}
if f16iter.Arn != nil {
Expand All @@ -29,7 +24,9 @@
f16elem.SigningProfileVersionARN = f16iter.SigningProfileVersionArn
}
f16 = append(f16, f16elem)
layer = append(layer, f16iter.Arn)
}
ko.Spec.Layers = layer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have some smoke tests around layers updates?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

ko.Status.LayerStatuses = f16
} else {
ko.Status.LayerStatuses = nil
Expand Down