{"record":{"id":"444c80774e64d0e7","repo":"kubernetes/kops","slug":"unexpected-target-type-for-deletion-t-444c80","errorCode":null,"errorMessage":"unexpected target type for deletion: %T","messagePattern":"unexpected target type for deletion: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/awstasks/launchtemplate_target_api.go","lineNumber":435,"sourceCode":"}\n\nvar _ fi.CloudupDeletion = (*deleteLaunchTemplate)(nil)\n\n// TaskName returns the task name\nfunc (d *deleteLaunchTemplate) TaskName() string {\n\treturn \"LaunchTemplate\"\n}\n\n// Item returns the launch template name\nfunc (d *deleteLaunchTemplate) Item() string {\n\treturn fi.ValueOf(d.lc.LaunchTemplateName)\n}\n\nfunc (d *deleteLaunchTemplate) Delete(t fi.CloudupTarget) error {\n\tctx := context.TODO()\n\tawsTarget, ok := t.(*awsup.AWSAPITarget)\n\tif !ok {\n\t\treturn fmt.Errorf(\"unexpected target type for deletion: %T\", t)\n\t}\n\n\tif _, err := awsTarget.Cloud.EC2().DeleteLaunchTemplate(ctx, &ec2.DeleteLaunchTemplateInput{\n\t\tLaunchTemplateName: d.lc.LaunchTemplateName,\n\t}); err != nil {\n\t\treturn fmt.Errorf(\"error deleting LaunchTemplate %s: error: %s\", d.Item(), err)\n\t}\n\n\treturn nil\n}\n\n// String returns a string representation of the task\nfunc (d *deleteLaunchTemplate) String() string {\n\treturn d.TaskName() + \"-\" + d.Item()\n}\n\nfunc (d *deleteLaunchTemplate) DeferDeletion() bool {\n\treturn false // TODO: Should we defer deletion?","sourceCodeStart":417,"sourceCodeEnd":453,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/awstasks/launchtemplate_target_api.go#L417-L453","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before (test)\ndeleteTask.Delete(myTerraformTarget)\n// after\ntarget := awsup.NewAWSAPITarget(cloud)\ndeleteTask.Delete(target)","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"awsTarget, ok := t.(*awsup.AWSAPITarget)\nif !ok {\n  return fmt.Errorf(\"unexpected target type for deletion: %T\", t)\n}","tryCatchPattern":"if err := deleteTask.Delete(target); err != nil {\n  if strings.Contains(err.Error(), \"unexpected target type\") {\n    return fmt.Errorf(\"launch template deletion requires an AWS API target, got %T\", target)\n  }\n  return err\n}","preventionTips":["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"],"tags":["aws","ec2","launch-template","type-assertion","internal"],"backgroundTag":"unexpected-target-type","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}