kubernetes/kops · error

unexpected target type for deletion: %T

Error message

unexpected target type for deletion: %T

What it means

deleteAutoscalingTargetGroupAttachment.Delete expects the target to be an *awsup.AWSAPITarget; any other fi.CloudupTarget type means the delete is being executed against the wrong target type (e.g. a Terraform or dry-run target). This is an internal type-assertion guard.

Source

Thrown at upup/pkg/fi/cloudup/awstasks/autoscalinggroup.go:1086

	autoScalingGroupName string
	targetGroupARN       string
}

var _ fi.CloudupDeletion = (*deleteAutoscalingTargetGroupAttachment)(nil)

func buildDeleteAutoscalingTargetGroupAttachment(autoScalingGroupName string, targetGroupARN string) *deleteAutoscalingTargetGroupAttachment {
	d := &deleteAutoscalingTargetGroupAttachment{}
	d.autoScalingGroupName = autoScalingGroupName
	d.targetGroupARN = targetGroupARN
	return d
}

func (d *deleteAutoscalingTargetGroupAttachment) 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)
	}

	req := &autoscaling.DetachLoadBalancerTargetGroupsInput{
		AutoScalingGroupName: aws.String(d.autoScalingGroupName),
		TargetGroupARNs:      []string{d.targetGroupARN},
	}
	if _, err := awsTarget.Cloud.Autoscaling().DetachLoadBalancerTargetGroups(ctx, req); err != nil {
		return fmt.Errorf("failed to detach target groups from autoscaling group: %v", err)
	}

	return nil
}

func (d *deleteAutoscalingTargetGroupAttachment) TaskName() string {
	return "autoscaling-elb-attachment"

}
func (d *deleteAutoscalingTargetGroupAttachment) Item() string {

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Run deletion with the AWS API target (omit --target terraform / use the default apply target) so ASG attachments can be detached via the API.
  2. With --target terraform, rely on plan output instead of expecting API-side deletion.
  3. If seen in tests, provide an awsup.AWSAPITarget (or a mocked equivalent) to the Delete call.

Example fix

// before
kops delete cluster --name cluster --target terraform
// after (actual API deletion)
kops delete cluster --name cluster --yes
Defensive patterns

Strategy: type-guard

Type guard

func isAWSAPITarget(t fi.CloudupTarget) (*awsup.AWSAPITarget, bool) {
  at, ok := t.(*awsup.AWSAPITarget)
  return at, ok
}

Try / catch

awsTarget, ok := t.(*awsup.AWSAPITarget)
if !ok {
  klog.V(2).Infof("skipping API deletion for target %T (terraform/dry-run)", t)
  return nil
}

Prevention

When it happens

Trigger: Running a deletion flow for the target group attachment with a target that is not AWSAPITarget — e.g. `kops delete cluster` with --targets terraform, or a custom target passed to fi apply/delete.

Common situations: Deletion during terraform-target runs where AWS API deletions are not applicable; unit/integration tests invoking Delete with mock targets; tooling that drives fi targets programmatically.

Related errors


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