Repository navigation
fix: key LaunchTemplate by Name so adopt-or-create works - #347
ack-prow[bot] merged 1 commit into
Conversation
3a993ca to
3a36dae
Compare
|
/retest |
3a36dae to
9845060
Compare
|
/label release/patch |
9845060 to
53de950
Compare
|
/retest |
|
/label release/patch |
53de950 to
ad03c27
Compare
|
/retest |
gustavodiaz7722
left a comment
There was a problem hiding this comment.
Comment, with one MUST FIX. Reading by name fixes aws-controllers-k8s/community#2932 live. However, a CR whose spec.name was edited on an older release creates a second template on upgrade, or takes over an existing template that has that name.
I tested the merge base, v1.15.0 (the issue reporter's version) and this PR on a dev EKS cluster. The controller was scoped to one namespace with a 60 s resync, and I counted AWS writes in CloudTrail.
| Scenario | Base / v1.15.0 | PR |
|---|---|---|
spec.name edited on base, then upgrade |
No write | New template created, or another template taken over |
adopt with {"name": …}, no spec |
Terminal required field missing: id |
Synced, spec filled from AWS, 0 writes |
adopt with {"id": …} |
Fails as in aws-controllers-k8s/community#3169 | Terminal required field missing: name |
MUST FIX: renamed CRs on upgrade (inline on hooks.go). Released versions accept a spec.name edit and ignore it. After the upgrade the controller reads by the new name. It then either creates a new template and orphans the original, or it takes over an unmanaged template that has that name, retags it, and deletes it when the CR is deleted. I reproduced both cases live.
SHOULD FIX: adoption by {"id": …} stops working (inline on generator.yaml).
Not verified: ec2-crd-compat-check printed "no changes" for this CRD, so it did not check the new CEL rule on spec.name.
| // gate on Status.ID, which is nil until the first successful read. | ||
| func (rm *resourceManager) checkForMissingRequiredFields(r *resource) bool { | ||
| return r.ko.Status.ID == nil | ||
| return r.ko.Spec.Name == nil |
There was a problem hiding this comment.
MUST FIX (reproduced live, upgrade path). On the base, spec.name is mutable and has no effect after create. The read goes by Status.ID and never compares the name, so a spec.name edit stays Synced, makes no AWS write, and the template keeps its old name. After upgrading to this PR, the read goes by the new name:
- No template has the new name. The controller makes one
CreateLaunchTemplatecall for the new name and replacesstatus.id. The original template is orphaned, and deleting the CR removes only the new one. - An unmanaged template already has the new name. The CR takes it over. On a dev cluster the controller deleted that template's own
ownertag and added the ACK tags. Deleting the CR then deleted that template, and the original was orphaned.
In both cases the new CEL rule rejects patching the name back.
Options (I haven't tested these):
- In the
sdk_read_many_post_set_outputhook, return a Terminal error whenr.ko.Status.IDis set and differs from the ID found by name. That stops the takeover. Deleting such a CR then waits on the error instead of deleting another template. The check can't live insidesetLatestLaunchTemplateAttributes, because the hook drops that function's error. - When the name lookup misses and
Status.IDis set, read by ID. That tells a renamed template apart from one deleted out of band ([ec2-controller] LaunchTemplate: the not-found code doesn't match a read by ID community#3172), which should still be recreated. - At minimum, add a release note: before upgrading, check that each LaunchTemplate CR's
spec.namematches its template's name in AWS.
There was a problem hiding this comment.
good catch, thanks for reproducing both of these! reads now go by status.id once it's set and only fall back to spec.name before the first read, so a CR renamed on an older release keeps reading its own template. tested the upgrade path live (main -> this branch) for both cases, no new template and the other template's tags/lifecycle were untouched.
| fields: | ||
| ID: | ||
| Name: | ||
| is_primary_key: true |
There was a problem hiding this comment.
SHOULD FIX (reproduced live, behavior change). Making Name the primary key also changes the adoption key. The generated PopulateResourceFromAnnotation now reads name. With adoption-policy: adopt, an annotation of services.k8s.aws/adoption-fields: {"id": "lt-…"} goes Terminal with Error populating adoption fields: required field missing: name and makes no AWS call. With adopt-or-create the runtime ignores that error, and the read by spec.name still adopts. I confirmed that live too.
{"name": …} works: with no spec at all, the CR adopted the template, filled its spec from AWS, and made no writes. That fixes the adopt-by-name form of aws-controllers-k8s/community#3169, but that issue's own repro adopts by ID.
Two ways to handle it:
- State the change in the PR body: adopt with
{"name": …}, because{"id": …}is no longer accepted. - Keep
idworking. That needs apre_populate_resource_from_annotationhook that acceptsidand returns early, plus a read by ID whenspec.nameis unset, becauseDescribeLaunchTemplatesInput.LaunchTemplateIdsis now ignored. I haven't tested this.
LaunchTemplate was keyed by Status.ID, so sdkFind short-circuited to
NotFound whenever the ID was unset and adopt-or-create looped on
CreateLaunchTemplate AlreadyExistsException. Make the unique Name the
primary key (immutable, since AWS cannot rename templates) so sdkFind
can find a pre-existing template by name, but read by Status.ID once it
is known so a CR renamed on an older release keeps its own template.
Adoption accepts either {"name": ...} or {"id": ...}. Also stop
DescribeLaunchTemplateVersions from running unfiltered when the
template identifier is unknown, which would clobber Spec.Data with
unrelated data.
Resolves aws-controllers-k8s/community#2932
ad03c27 to
f0370f7
Compare
|
/LGTM |
|
/label release/patch |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: gustavodiaz7722, michaelhtm The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Description of changes:
LaunchTemplate was keyed by Status.ID, so sdkFind short-circuited to
NotFound whenever the ID was unset and adopt-or-create looped on
CreateLaunchTemplate AlreadyExistsException. Make the unique Name the
primary key (immutable, since AWS cannot rename templates) so sdkFind
reads by name and adopts a pre-existing template. Also stop
DescribeLaunchTemplateVersions from running unfiltered when the template
identifier is unknown, which would clobber Spec.Data with unrelated data.
Resolves aws-controllers-k8s/community#2932
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.