Skip to content

Function code + configuration updates applied in one change are no longer left partially unapplied - #237

Merged
ack-prow[bot] merged 4 commits into
aws-controllers-k8s:mainfrom
knottnt:fix/code-update-block-additional-changes
Aug 25, 2026
Merged

Function code + configuration updates applied in one change are no longer left partially unapplied#237
ack-prow[bot] merged 4 commits into
aws-controllers-k8s:mainfrom
knottnt:fix/code-update-block-additional-changes

Conversation

@knottnt

@knottnt knottnt commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Issue #, if available: 1968

Description of changes:

Problem

When a single kubectl apply updates both a Function's code (spec.code.sha256 / architectures / code.imageURI) and its configuration (e.g. spec.environment), only the code change was applied. The configuration change was silently dropped until the next full resync (~10h) or the next manual spec edit, even though the resource reported ACK.ResourceSynced=True.

Root cause

customUpdateFunction intentionally issues either UpdateFunctionCode or UpdateFunctionConfiguration in a single reconcile, never both, because either async call puts the function into an updating state and Lambda rejects a second concurrent update. After issuing the code update the Function's status is read as Active which is considered a synced state by the controller. As a result the controller failed to requeue to apply the configuration updates and instead waited the default re-sync duration.

Fix

Derive whether both a code and a configuration change were requested directly from the delta passed into customUpdateFunction, and requeue only in that combined case:

  • Reconcile 1 applies the code change and requeues after 30s (keeping ResourceSynced=False).
  • Reconcile 2 sees the code has settled (code delta gone) and applies the deferred configuration change; no requeue.
  • Reconcile 3 has an empty delta → ResourceSynced=True.

Code-only, config-only, and architectures-only updates each apply everything in a single call and do not requeue, so their behavior is unchanged.

Fix is similar to work done in #151

Testing

Added e2e regression test test_function_update_code_and_environment_variable, which patches code.sha256 + code.s3Key + environment in one update and waits on ACK.ResourceSynced=True (long enough to span the 30s requeue) before asserting both the new CodeSha256 and the environment variables are applied. This test fails on main (env var dropped) and passes with the fix. Test is based on #204 work done by @willthames

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

- Force requeue when both code and configuration are changed for a Function

- Add regression test that validates that a single spec update that includes both code and configuration changes converges.
@ack-prow

ack-prow Bot commented Aug 24, 2026

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@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 24, 2026
@ack-prow
ack-prow Bot requested review from gustavodiaz7722 and jlbutler August 24, 2026 22:44
@ack-prow ack-prow Bot added the approved label Aug 24, 2026
@knottnt

knottnt commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

/test all

@knottnt
knottnt marked this pull request as ready for review August 24, 2026 23:00
@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 24, 2026
@ack-prow
ack-prow Bot requested a review from sapphirew August 24, 2026 23:00

@michaelhtm michaelhtm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@ack-prow ack-prow Bot added the lgtm Indicates that a PR is ready to be merged. label Aug 24, 2026
@michaelhtm

Copy link
Copy Markdown
Member

/hold

@ack-prow ack-prow Bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 24, 2026
Comment thread pkg/resource/function/hooks.go Outdated
return updatedStatusResource, err
}
return rm.concreteResource(readOneLatest), nil
updated := rm.concreteResource(readOneLatest)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

returning readOneLatest might be an issue here. I see that we're doing a ReadOne during the update. Can we avoid doing that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm this PR doesn't add that ReadOne, but agree it isn't ideal. I've gone ahead and removed the ReadOne call. To retain a fresh post-update status read I've made the post-update requeue unconditional to force a re-read of the Function's status. Performing exploratory testing with Function updates it doesn't look like this was being used to suppress AWS defaults causing reconcile loops so I don't think we need to mark any additional fields as late_initialize.

@knottnt knottnt added the release/patch Indicates this PR should trigger a patch version release on merge. label Aug 24, 2026
- Remove call to rm.ReadOne(ctx, desired)
- Unconditionally force a requeue after field updates to pick-up fresh status and reconcile any deferred updates.
@ack-prow ack-prow Bot removed the lgtm Indicates that a PR is ready to be merged. label Aug 25, 2026
@knottnt

knottnt commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

/retest

- Add wait for synced state before checking post-create status fields to avoid race between resource creation and assertion.
@knottnt
knottnt force-pushed the fix/code-update-block-additional-changes branch from 5c5463a to 4f36108 Compare August 25, 2026 01:20
@michaelhtm

Copy link
Copy Markdown
Member

/lgtm
/unhold

@ack-prow ack-prow Bot added lgtm Indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Aug 25, 2026
@ack-prow

ack-prow Bot commented Aug 25, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: knottnt, michaelhtm

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

The pull request process is described 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 merged commit 05b4310 into aws-controllers-k8s:main Aug 25, 2026
8 checks passed
ack-prow Bot pushed a commit that referenced this pull request Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm Indicates that a PR is ready to be merged. release/patch Indicates this PR should trigger a patch version release on merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants