kubernetes/kops · error

error deleting LaunchTemplate %s: error: %s

Error message

error deleting LaunchTemplate %s: error: %s

What it means

Wraps an error returned by ec2:DeleteLaunchTemplate when deleteLaunchTemplate.Delete removes an orphaned launch template. The template could not be deleted, so FindDeletions cleanup fails and the error is surfaced with the task name and underlying message.

Source

Thrown at upup/pkg/fi/cloudup/awstasks/launchtemplate_target_api.go:441

	return "LaunchTemplate"
}

// Item returns the launch template name
func (d *deleteLaunchTemplate) Item() string {
	return fi.ValueOf(d.lc.LaunchTemplateName)
}

func (d *deleteLaunchTemplate) Delete(t fi.CloudupTarget) error {
	ctx := context.TODO()
	awsTarget, ok := t.(*awsup.AWSAPITarget)
	if !ok {
		return fmt.Errorf("unexpected target type for deletion: %T", t)
	}

	if _, err := awsTarget.Cloud.EC2().DeleteLaunchTemplate(ctx, &ec2.DeleteLaunchTemplateInput{
		LaunchTemplateName: d.lc.LaunchTemplateName,
	}); err != nil {
		return fmt.Errorf("error deleting LaunchTemplate %s: error: %s", d.Item(), err)
	}

	return nil
}

// String returns a string representation of the task
func (d *deleteLaunchTemplate) String() string {
	return d.TaskName() + "-" + d.Item()
}

func (d *deleteLaunchTemplate) DeferDeletion() bool {
	return false // TODO: Should we defer deletion?
}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Read the wrapped error: 'InvalidLaunchTemplateId.InUse' means detach/delete the referencing ASG first
  2. Confirm no Auto Scaling Groups reference the template (aws autoscaling describe-auto-scaling-groups)
  3. Grant ec2:DeleteLaunchTemplates to the kOps IAM role
  4. Re-run kops update if the template was already deleted (error will be NotFound — safe to ignore/retry)
  5. Retry after throttling backoff

Example fix

// before
aws autoscaling create-auto-scaling-group --launch-template LaunchTemplateName=my-template
// after
aws autoscaling update-auto-scaling-group --auto-scaling-group-name my-asg --launch-template LaunchTemplateName=new-template
# then re-run: kops update cluster
Defensive patterns

Strategy: retry

Validate before calling

out, err := cloud.EC2().DescribeLaunchTemplates(ctx, &ec2.DescribeLaunchTemplatesInput{
  LaunchTemplateNames: []string{*d.lc.LaunchTemplateName},
})
if err != nil || len(out.LaunchTemplates) == 0 { return nil } // nothing to delete
// also check referencing ASGs before deleting

Try / catch

if _, err := ec2().DeleteLaunchTemplate(ctx, input); err != nil {
  var awsErr smithy.APIError
  if errors.As(err, &awsErr) && strings.Contains(awsErr.ErrorCode(), "NotFound") {
    return nil // already deleted
  }
  return fmt.Errorf("error deleting LaunchTemplate: %w", err)
}

Prevention

When it happens

Trigger: DeleteLaunchTemplate fails: launch template in use by an Auto Scaling Group, AccessDenied on ec2:DeleteLaunchTemplates, template already deleted, throttling, or invalid launch template name/ID.

Common situations: Orphaned template still referenced by an ASG created outside kOps or by a scaled node group; IAM role missing delete permission; concurrent kOps runs deleting the same template.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/8fd72d7ac59842a3. Report an issue: GitHub.