kubernetes/kops · error
unexpected target type for deletion: %T
Error message
unexpected target type for deletion: %T
What it means
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.
Source
Thrown at upup/pkg/fi/cloudup/awstasks/targetgroup.go:543
// It implements fi.CloudupDeletion
type deleteTargetGroup struct {
obj *awsup.TargetGroupInfo
}
func buildDeleteTargetGroup(obj *awsup.TargetGroupInfo) *deleteTargetGroup {
d := &deleteTargetGroup{}
d.obj = obj
return d
}
var _ fi.CloudupDeletion = (*deleteTargetGroup)(nil)
func (d *deleteTargetGroup) 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)
}
arn := d.obj.ARN
klog.V(2).Infof("deleting target group %q", arn)
if _, err := awsTarget.Cloud.ELBV2().DeleteTargetGroup(ctx, &elbv2.DeleteTargetGroupInput{
TargetGroupArn: &arn,
}); err != nil {
return fmt.Errorf("error deleting ELB TargetGroup %q: %w", arn, err)
}
return nil
}
// String returns a string representation of the task
func (d *deleteTargetGroup) String() string {
return d.TaskName() + "-" + d.Item()
}
View on GitHub (pinned to 4c8573c808)
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
Example fix
// before deleteTargetGroup.Delete(myCustomTarget) // after awsTarget := awsup.NewAWSAPITarget(cloud) deleteTargetGroup.Delete(awsTarget)
Defensive patterns
Strategy: type-guard
Type guard
awsTarget, ok := t.(*awsup.AWSAPITarget)
if !ok {
return fmt.Errorf("unexpected target type for deletion: %T", t)
} Prevention
- Only invoke task Delete with AWSAPITarget from awsup
- In tests, construct AWSAPITarget with mocked ELBV2 clients
- Re-check target API after kOps version upgrades
When it happens
Trigger: 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.
Common situations: Custom tooling invoking fi CloudupTarget machinery directly; unit tests passing a mock target; refactoring after target interface changes.
Related errors
- error deleting TargetGroup %q: %v
- failed to attach target groups: %v
- failed to detach target groups from autoscaling group: %v
- unexpected target type for deletion: %T
- target group not yet created (arn not set)
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/88f7dde024fef850.
Report an issue: GitHub.