fix: use the CR UID as the idempotency token of FileSystem and AccessPoint #91
All Vouch review confidence checks passed
Residual risk 0.30 = Change Risk (0.75) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.75 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Sensitive Paths
sensitive_paths
0.075
Real PR Conversation Timeline
1 comments
"Review active on #91"
general
weight: 0.35
blacksoxx
Issue #, if available: aws-controllers-k8s/community#3122 (the same problem in ec2-controller), aws-controllers-k8s/community#3143 (point 3: a stable idempotency token)
Description of changes:
CreateFileSystemgot itsCreationTokenfromtime.Now().UTC().Nanosecond(), andCreateAccessPointitsClientTokenfromtime.Now().UTC().Format("20060102150405000000"), which has a resolution of one second: the trailing zeros in the layout are literal. EachCreatesent a new token, so the token never protected anything. When the controller lost the response of aCreatethat went through (a client-side timeout, or a restart before the ID reached the status), the next reconcile found no ID, calledCreateagain and made a second file system or access point. The first one was left behind, unmanaged and still billed. Two access points created in the same second, on the other hand, shared a token.This change:
IssueCertificate. EveryCreatefor one CR sends the same token.Createwith a token EFS has already seen returnsFileSystemAlreadyExistsorAccessPointAlreadyExistswith the ID of the resource created the first time; EFS does not return the resource itself (see aws/aws-sdk#163). A newsdk_create_post_requesthook takes that ID into the status and returns the resource without an error; the reconciler reads the rest of it withReadOneright afterCreate, as for any new resource.Createthat replaces one deleted outside of the controller makes a new one with the same token.DescribeFileSystemswith theCreationToken, or the access points ofspec.fileSystemIDwith thatClientToken. Without it, a CR deleted before the response of a lostCreatereached the status lost its finalizer and left the resource behind (raised in review: https://github.com/aws-controllers-k8s/efs-controller/pull/91#discussion_r4611587767).- The file system lookup is one filtered call and runs on any read without an ID. The access point lookup pages through every access point of the file system, which can hold thousands, so it runs only for a CR being deleted; any other read without an ID returns NotFound, and the
Createthat follows gets the ID fromAccessPointAlreadyExists(raised in review: https://github.com/aws-controllers-k8s/efs-controller/pull/91#discussion_r4620222830).- The runtime ignores reference errors on delete, so for an
AccessPointwith afileSystemRefwhoseFileSystemCR is already gone or not synced,spec.fileSystemIDis empty and the lookup is skipped: an access point whoseCreateresponse was lost is then left behind.AccessPointAlreadyExistspassesrequeueWaitStatethe access point it read, andrequeueWaitStateno longer returns nil, so an access point that is stillcreatingis requeued instead of left without a state (raised in review: https://github.com/aws-controllers-k8s/efs-controller/pull/91#discussion_r4611174111).pkg/resource//sdk.gowas regenerated with code-generator v0.68.0; the only changes are the token call and the new hooks.Tests (new, against the real SDK client and an
httptestserver that answers like EFS):Createcalls;FileSystemAlreadyExists/AccessPointAlreadyExistswith an ID gives back the resource with that ID and no error;AccessPointAlreadyExists, the read of acreatingaccess point asks for a requeue after a non-zero duration;CreationToken, and the read of an access point being deleted finds it byClientToken; without a match it returns NotFound, and without a UID it sends no request;Against the current code, the first two fail for both resources; the read tests fail on cc18cf1, the head of this PR before the review, and the last one fails on 71b29ad.
go test ./...passes.Checked against real EFS in a sandbox account (ap-southeast-1). Runs 1 and 2 were made before the review; run 3 checks the first two review follow-ups (c66f4de, 71b29ad), and run 4 the last one (6f1e116).
1. The API itself, with a small program (source below) that calls it with
aws-sdk-go-v2/service/efsv1.34.7, the controller's version, and matches the errors witherrors.Ason the SDK types, as the hook does:| Call | Result |
|---|---|
|
CreateFileSystemtwice with the sameCreationToken| the second returnsFileSystemAlreadyExistswith the first file system'sFileSystemId||
CreateAccessPointtwice with the sameClientToken| the second returnsAccessPointAlreadyExistswith the first access point'sAccessPointId||
CreateAccessPointwith theClientTokenof a deleted access point | a new access point ||
CreateFileSystemwith theCreationTokenof a deleted file system | a new file system |2. The controller, killed right after
Create. On kind, this controller built frommainand from this branch, both against a runtime test build (diff below) that exits once per kind right afterCreatereturns, before the ID reaches the status, as a controller killed at that moment would. The scenario (script below): aFileSystem; once it is synced after the restart, anAccessPointwith afileSystemRefto it; once that is synced after the second restart, both CRs deleted.| |
main| this PR ||---|---|---|
|
FileSystemafter the restart | a second file system; the CR has its ID, the first one is in no CR |FileSystemAlreadyExists; the CR has the ID of the file system created before the exit; one file system ||
AccessPointafter the restart | a second access point on the same file system; the first one is in no CR |AccessPointAlreadyExists; the CR has the ID of the access point created before the exit; one access point || Conditions |
ACK.ResourceSynced=True,Ready=True: nothing shows the duplicate | the same || After deleting both CRs | the first file system is still in the account (the extra access point went away with its file system) | nothing is left |
CloudTrail has every
Createcall the controller made in both runs, with the tokens it sent:On
main, everyCreatesends a new token: nanoseconds for file systems, and for access points the time to the second with six literal zeros. With this PR, the token is the CR's UID, the same on the retry, and EFS answers with the resource it already made.Everything the runs created was deleted afterwards.
Not tested against moto: its
FileSystemAlreadyExistscarries noFileSystemId, and it does not check theClientTokenof access points at all.Raw output and sources (the account ID is replaced with 111122223333):
3. The review follow-ups. A test (source below, build tag
realefs) calls the controller's own code with the real SDK client: it creates a file system and an access point throughsdkCreate/Createwith a made-up UID as the token, callsCreateagain with the same UID, and then reads them without an ID in the status. The same test on cc18cf1, the head of this PR before the review, and on 71b29ad:| | cc18cf1 | 71b29ad |
|---|---|---|
| Second
Createwith the same UID |FileSystemAlreadyExists/AccessPointAlreadyExists, same ID | the same ||
ReadOneright after theAccessPointAlreadyExists, access pointcreating|(requeue.RequeueNeededAfter)(nil): no requeue | requeue after 10s, "accesspoint in 'creating' state" || Read without an ID in the status | NotFound, for both | finds the file system by
CreationTokenand the access point byClientToken, both stillcreating|| Read with an unknown UID, or for a file system that does not exist | not run | NotFound |
Everything the test created was deleted at the end of each run.
<details><summary>Run 3 output, 71b29ad</summary>
</details>
<details><summary>Run 3 output, cc18cf1</summary>
</details>
4. The access point lookup only for a CR being deleted (6f1e116). The same test, changed for it (the source below is this version;
beingDeletedis the helper fromhooks_test.go): the read without an ID is made once for a CR that is not being deleted (step 4a) and then for one with a deletion timestamp (steps 4 to 6), and step 7 does what the runtime'sdeleteResourcedoes for a CR deleted before the ID reached the status:ReadOnewithout an ID, thenDeleteof what it read. The file system test is unchanged and was run again on the same head.| | 6f1e116 |
|---|---|
| Read without an ID, CR not being deleted | NotFound, no lookup |
| Read without an ID, CR being deleted | finds the access point by
ClientToken|| The same with an unknown UID, or for a file system that does not exist | NotFound |
|
ReadOnewithout an ID, thenDelete, CR being deleted | deletes the access point created for the CR;DescribeAccessPointsthen returnsAccessPointNotFound|| File system: second
Create, read without an ID | as in run 3 |Everything the test created was deleted; afterwards the account had no file systems left in the region.
<details><summary>Run 4 output, 6f1e116</summary>
</details>
<details><summary>Run 3 and 4 test, <code>pkg/resource/access_point/realefs_test.go</code> (run 4 version; run 3 had no steps 4a and 7, and steps 4 to 6 read a CR not being deleted)</summary>
</details>
<details><summary>Run 3 and 4 test, <code>pkg/resource/file_system/realefs_test.go</code></summary>
</details>
<details><summary>Scenario output, <code>main</code></summary>
</details>
<details><summary>Scenario output, this PR</summary>
</details>
<details><summary>Controller log after the second restart, this PR</summary>
The runtime logs
created new resourcewheneversdkCreatereturns no error, here right after the hook took the existing ID.</details>
<details><summary>API check output</summary>
</details>
<details><summary>Runtime test build: exit once per kind right after <code>Create</code> (on runtime <code>main</code>, 283af82)</summary>
</details>
<details><summary>Controller deployment (credentials of the sandbox account in the <code>aws-creds</code> Secret; CRDs from <code>config/crd</code>)</summary>
</details>
<details><summary>Scenario script</summary>
</details>
<details><summary>API check program</summary>
</details>
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
🤖 Generated with Claude Code