{"record":{"id":"88f7dde024fef850","repo":"kubernetes/kops","slug":"unexpected-target-type-for-deletion-t-88f7dd","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/targetgroup.go","lineNumber":543,"sourceCode":"// It implements fi.CloudupDeletion\ntype deleteTargetGroup struct {\n\tobj *awsup.TargetGroupInfo\n}\n\nfunc buildDeleteTargetGroup(obj *awsup.TargetGroupInfo) *deleteTargetGroup {\n\td := &deleteTargetGroup{}\n\td.obj = obj\n\treturn d\n}\n\nvar _ fi.CloudupDeletion = (*deleteTargetGroup)(nil)\n\nfunc (d *deleteTargetGroup) Delete(t fi.CloudupTarget) error {\n\tctx := context.TODO()\n\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\tarn := d.obj.ARN\n\tklog.V(2).Infof(\"deleting target group %q\", arn)\n\tif _, err := awsTarget.Cloud.ELBV2().DeleteTargetGroup(ctx, &elbv2.DeleteTargetGroupInput{\n\t\tTargetGroupArn: &arn,\n\t}); err != nil {\n\t\treturn fmt.Errorf(\"error deleting ELB TargetGroup %q: %w\", arn, err)\n\t}\n\n\treturn nil\n}\n\n// String returns a string representation of the task\nfunc (d *deleteTargetGroup) String() string {\n\treturn d.TaskName() + \"-\" + d.Item()\n}\n","sourceCodeStart":525,"sourceCodeEnd":561,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/awstasks/targetgroup.go#L525-L561","documentation":"The deleteTargetGroup wrapper's Delete expects the standard AWSAPITarget; if the passed target is any other type it returns this error with the Go type. This is an internal invariant check — users should never hit it in normal kOps operation.","triggerScenarios":"kOps internal use: calling deleteTargetGroup.Delete with a target other than *awsup.AWSAPITarget (e.g. a terraform/test/dry-run target), usually only in custom code or tests.","commonSituations":"Custom tooling invoking fi CloudupTarget machinery directly; unit tests passing a mock target; refactoring after target interface changes.","solutions":["Pass an *awsup.AWSAPITarget built from the cloud to Delete","If in tests, construct AWSAPITarget with a mocked ELBV2/EC2 client","Update custom code to the current fi target API"],"exampleFix":"// before\ndeleteTargetGroup.Delete(myCustomTarget)\n// after\nawsTarget := awsup.NewAWSAPITarget(cloud)\ndeleteTargetGroup.Delete(awsTarget)","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":null,"preventionTips":["Only invoke task Delete with AWSAPITarget from awsup","In tests, construct AWSAPITarget with mocked ELBV2 clients","Re-check target API after kOps version upgrades"],"tags":["aws","target-group","type-mismatch","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"}