kubernetes/kops · error
unexpected target type for deletion: %T
Error message
unexpected target type for deletion: %T
What it means
deleteLaunchTemplate.Delete asserts the passed target is an *awsup.AWSAPITarget before issuing the DeleteLaunchTemplate call. This error means the target was some other CloudupTarget implementation, an internal type-safety failure rather than an AWS-side problem. It indicates the task is being run against an unexpected target, so deletion is refused before touching AWS.
Source
Thrown at upup/pkg/fi/cloudup/awstasks/launchtemplate_target_api.go:435
}
var _ fi.CloudupDeletion = (*deleteLaunchTemplate)(nil)
// TaskName returns the task name
func (d *deleteLaunchTemplate) TaskName() string {
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
- Ensure the launch template deletion is run via `kops update cluster` against an AWS cluster so an AWSAPITarget is used
- Check custom code/tests constructing the target — pass awsup.NewAWSAPITarget(cloud)
- Inspect recent modifications to the target plumbing if this appears after a kOps upgrade
- File a kOps bug if triggered by stock kOps on an AWS cluster
Example fix
// before (test) deleteTask.Delete(myTerraformTarget) // after target := awsup.NewAWSAPITarget(cloud) deleteTask.Delete(target)
Defensive patterns
Strategy: type-guard
Type guard
awsTarget, ok := t.(*awsup.AWSAPITarget)
if !ok {
return fmt.Errorf("unexpected target type for deletion: %T", t)
} Try / catch
if err := deleteTask.Delete(target); err != nil {
if strings.Contains(err.Error(), "unexpected target type") {
return fmt.Errorf("launch template deletion requires an AWS API target, got %T", target)
}
return err
} Prevention
- Always run awstasks against awsup.NewAWSAPITarget(cloud)
- In tests use awsup.BuildAWSAPITarget mock rather than ad-hoc targets
- Don't route AWS tasks through terraform/baremetal targets
When it happens
Trigger: The fi.CloudupTarget passed to Delete is not *awsup.AWSAPITarget — e.g. running under a different cloud target (terraform/baremetal-style target) or a test/mock target injected into the apply loop for this AWS task.
Common situations: Custom code or tests invoking task Delete with a mock target; plugin/patch code routing awstasks through a non-AWS target; internal kOps bug after target refactor.
Related errors
- timed out waiting for volume to detach
- error listing AutoScaling LaunchTemplates: %v
- error deleting ec2 LaunchTemplate %q: %v
- error creating LaunchTemplate %q: %v
- error creating LaunchTemplateVersion: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/444c80774e64d0e7.
Report an issue: GitHub.