Skip to content

Layers added to a Function that has no layers in AWS are no longer ignored - #239

Open
suprahh wants to merge 2 commits into
aws-controllers-k8s:mainfrom
suprahh:main
Open

Layers added to a Function that has no layers in AWS are no longer ignored#239
suprahh wants to merge 2 commits into
aws-controllers-k8s:mainfrom
suprahh:main

Conversation

@suprahh

@suprahh suprahh commented Aug 27, 2026

Copy link
Copy Markdown

Issue #, if available: aws-controllers-k8s/community#3010

Description of changes

Adding layers to a Function that has no layers in AWS had no effect: the resource
was marked as synced and UpdateFunctionConfiguration was never called with the
Layers parameter.

sdkFind() builds the latest resource from a deep copy of the desired one. When
GetFunction returns no layer, the else branch only cleared
Status.LayerStatuses and left Spec.Layers holding the desired value inherited
from that deep copy. desired and latest were then identical, so
delta.DifferentAt("Spec.Layers") never became true and the guard in
updateFunctionConfiguration skipped the field.

Clearing Spec.Layers as well makes the latest resource reflect the actual state
in AWS, so the delta is computed. The code lives in the
sdk_read_one_post_set_output hook template and is injected into
pkg/resource/function/sdk.go, so both files carry the same change. Nothing was
regenerated, so ack-generate-metadata.yaml is untouched (same approach as #174).

Why the existing e2e test did not catch it

test_function_layers creates the function with layers already attached and only
replaces them, so the else branch is never exercised. This adds
test_function_add_layers_to_function_without_layers, which starts from a
function without layers and then adds them.

Verification

Run against a real AWS account in us-west-2. Before the fix the new test fails
with KeyError: 'Layers'; after the fix it passes. test_function_layers still
passes, so replacing existing layers is unaffected.

Also reproduced the original adoption scenario by hand: a Function adopted with no
layers in AWS and patched with spec.layers reported ACK.ResourceSynced=True
with an empty status.layerStatuses while AWS still had Layers: null. Running
the fixed controller against the same CR, without touching it, attached the layers.

By submitting this pull request, I confirm that my contribution is made under the
terms of the Apache 2.0 license.

sdkFind() builds the latest resource from a deep copy of the desired one.
When GetFunction returns no layer, only Status.LayerStatuses was cleared,
so Spec.Layers kept the desired value. desired and latest were then
identical, no delta was computed for Spec.Layers and
updateFunctionConfiguration skipped the field, leaving the resource marked
as synced while AWS was never updated.

Clear Spec.Layers as well, so the latest resource reflects the actual
state in AWS and the delta is computed.

The existing e2e test creates the function with layers already attached,
so it never covered this path. Add a test that starts from a function
without layers and then adds them.

Issue #, if available: aws-controllers-k8s/community#3010

Signed-off-by: Carlos Gonzalez <carlos.gonzalezp838@gmail.com>
@ack-prow ack-prow Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 27, 2026
@ack-prow
ack-prow Bot requested review from a-hilaly and sapphirew August 27, 2026 14:13
@ack-prow

ack-prow Bot commented Aug 27, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: suprahh
Once this PR has been reviewed and has the lgtm label, please assign a-hilaly for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ack-prow ack-prow Bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 27, 2026
@ack-prow

ack-prow Bot commented Aug 27, 2026

Copy link
Copy Markdown

Hi @suprahh. Thanks for your PR.

I'm waiting for a aws-controllers-k8s member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@suprahh
suprahh marked this pull request as ready for review August 27, 2026 14:19
@ack-prow ack-prow Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 27, 2026
@ack-prow
ack-prow Bot requested review from gustavodiaz7722 and knottnt August 27, 2026 14:19
@knottnt knottnt self-assigned this Aug 27, 2026
@bugbuilder

Copy link
Copy Markdown

Cool to have it in the next release! Kudos @suprahh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants