Skip to content

[ec2-controller] LaunchTemplate adopt-or-create silently fails with AlreadyExistsException when Status.ID is unset #2932

Closed
aws-controllers-k8s/ec2-controller
#347

Description

@jbreitenbaumer

Bug Description

When an EC2 LaunchTemplate CR is annotated with services.k8s.aws/adoption-policy: adopt-or-create and a LaunchTemplate with the same name already exists in AWS (but Status.ID is not yet populated in the CR), the controller enters a permanent Recoverable error loop instead of adopting the existing resource.

The root cause is that sdkFind returns NotFound early whenever Status.ID is nil, and newListRequestPayload never looks up by name — so adopt-or-create has no path to discover the pre-existing AWS resource by name.

Steps to Reproduce

  1. Have a LaunchTemplate already present in AWS (e.g. after a control-plane migration where the Kubernetes objects were lost but AWS resources were retained with deletion-policy: retain).

  2. Create a LaunchTemplate CR with the same name and the adopt-or-create annotation, but without a pre-populated Status.ID:

apiVersion: ec2.services.k8s.aws/v1alpha1
kind: LaunchTemplate
metadata:
  name: my-cluster-general-ng
  annotations:
    services.k8s.aws/adoption-policy: adopt-or-create
    services.k8s.aws/deletion-policy: retain
spec:
  name: my-cluster-general-ng
  launchTemplateData:
    instanceType: m6g.large
    # ... other fields
  1. Observe the CR status — the controller never adopts the existing LaunchTemplate and instead repeats CreateLaunchTemplate calls that fail:
status:
  conditions:
  - message: 'api error InvalidLaunchTemplateName.AlreadyExistsException: Launch template
      name already in use.'
    status: "True"
    type: ACK.Recoverable
  - message: Unable to determine if desired resource state matches latest observed state
    reason: 'operation error EC2: CreateLaunchTemplate, ..., InvalidLaunchTemplateName.AlreadyExistsException:
      Launch template name already in use.'
    status: Unknown
    type: ACK.ResourceSynced

This error loops indefinitely — the resource is never adopted.

Root Cause Analysis

hooks.go line 242–243 — checkForMissingRequiredFields gates sdkFind exclusively on Status.ID:

func (rm *resourceManager) checkForMissingRequiredFields(r *resource) bool {
    return r.ko.Status.ID == nil
}

sdk.go line 168–180 — newListRequestPayload only populates LaunchTemplateIds; when Status.ID is nil, the struct is empty and the function returns early from sdkFind:

func (rm *resourceManager) newListRequestPayload(r *resource) (*svcsdk.DescribeLaunchTemplatesInput, error) {
    res := &svcsdk.DescribeLaunchTemplatesInput{}
    if r.ko.Status.ID != nil {
        res.LaunchTemplateIds = []string{*r.ko.Status.ID}
    }
    return res, nil  // empty input when ID is nil — DescribeLaunchTemplates without filters returns ALL templates
}

sdk.go line 70–71 — sdkFind exits immediately with ackerr.NotFound before even calling DescribeLaunchTemplates:

if rm.requiredFieldsMissingFromReadManyInput(r) {
    return nil, ackerr.NotFound  // ← always true when Status.ID is nil
}

The failure chain with adopt-or-create:

CR created (Status.ID = nil)
  → sdkFind() → checkForMissingRequiredFields() = true → returns NotFound
  → adopt-or-create sees NotFound → calls sdkCreate()
  → AWS: InvalidLaunchTemplateName.AlreadyExistsException
  → ACK marks condition ACK.Recoverable, retries
  → loop forever

Note: DescribeLaunchTemplates supports filtering by LaunchTemplateNames, so a name-based lookup is possible. The hooks.go already uses Spec.Name in newUpdateLaunchTemplateVersionRequestPayload (line 204). But sdkFind / newListRequestPayload never use it.

Expected Behaviour

When adoption-policy: adopt-or-create is set and a LaunchTemplate with the same Spec.Name already exists in AWS, sdkFind should attempt a DescribeLaunchTemplates call filtered by LaunchTemplateNames: [Spec.Name] before concluding the resource doesn't exist. If found, the controller should adopt it (populate Status.ID, set ACK.ResourceSynced: True).

Suggested Fix

In checkForMissingRequiredFields / newListRequestPayload — when Status.ID is nil, fall through to a name-based DescribeLaunchTemplates lookup using Spec.Name instead of short-circuiting to NotFound.

Alternatively, a custom pre-create hook that resolves the existing LaunchTemplate ID by name and populates Status.ID before sdkCreate is called would achieve the same result.

Environment

  • ACK ec2-controller version: v1.15.0 (latest as of 2026-06-19)
  • Kubernetes: EKS 1.35
  • AWS Region: eu-central-1
  • Observed with: kro RGDs using adopt-or-create on LaunchTemplate resources (the annotation is set at the template level in the RGD, so Status.ID is never pre-populated)

Related Issues

Activity

  1. github-actions commented on Jun 19, 2026

    @github-actions

    Hello @jbreitenbaumer 👋 Thank you for opening an issue in ACK! A maintainer will triage this issue soon.

    We encourage community contributions, so if you're interested in tackling this yourself or suggesting a solution, please check out our Contribution and Code of Conduct guidelines.

    You can find more information about ACK on our website.

  2. added
    kind/bugCategorizes issue or PR as related to a bug.
    service/ec2Indicates issues or PRs that are related to ec2-controller.
    on Jun 19, 2026
  3. added 3 commits that reference this issue on Jun 24, 2026
    3a36dae
    9845060
    53de950
  4. added 2 commits that reference this issue on Nov 12, 2026
    ad03c27
    f0370f7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.service/ec2Indicates issues or PRs that are related to ec2-controller.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions