kubernetes/kops · error
unexpected target type for deletion: %T
Error message
unexpected target type for deletion: %T
What it means
deleteNLB.Delete type-asserts the fi.CloudupTarget to *awsup.AWSAPITarget and returns this error when the assertion fails. It is a programming/assembly error: the delete delegator was invoked with a target type other than the AWS API target. The %T verb prints the actual dynamic type received.
Source
Thrown at upup/pkg/fi/cloudup/awstasks/network_load_balancer.go:725
// FindDeletions schedules deletion of load balancer revisions that are no longer in use.
func (e *NetworkLoadBalancer) FindDeletions(context *fi.CloudupContext) ([]fi.CloudupDeletion, error) {
return e.deletions, nil
}
// deleteNLB tracks a NLB that we're going to delete
// It implements fi.CloudupDeletion
type deleteNLB struct {
obj *awsup.LoadBalancerInfo
}
var _ fi.CloudupDeletion = (*deleteNLB)(nil)
func (d *deleteNLB) 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 load balancer %q", arn)
if _, err := awsTarget.Cloud.ELBV2().DeleteLoadBalancer(ctx, &elbv2.DeleteLoadBalancerInput{
LoadBalancerArn: &arn,
}); err != nil {
return fmt.Errorf("error deleting ELB LoadBalancer %q: %w", arn, err)
}
return nil
}
// String returns a string representation of the task
func (d *deleteNLB) String() string {
return d.TaskName() + "-" + d.Item()
}
View on GitHub (pinned to 4c8573c808)
Solutions
- Ensure NLB deletion is invoked with an *awsup.AWSAPITarget created for the cluster's cloud
- Check how the delete delegator is registered/assembled in the task map
- If writing tests, pass awsup.NewAWSAPITarget(cloud) rather than a mock target
Example fix
// before target := myMockTarget // not AWSAPITarget delegator.Delete(target) // after awsTarget := awsup.NewAWSAPITarget(cloud) delegator.Delete(awsTarget)
Defensive patterns
Strategy: type-guard
Validate before calling
if _, ok := target.(*awsup.AWSAPITarget); !ok {
return fmt.Errorf("deleteNLB requires *awsup.AWSAPITarget, got %T", target)
} Type guard
func asAWSAPITarget(t fi.CloudupTarget) (*awsup.AWSAPITarget, bool) {
at, ok := t.(*awsup.AWSAPITarget)
return at, ok
} Try / catch
awsTarget, ok := t.(*awsup.AWSAPITarget)
if !ok { return fmt.Errorf("unexpected target type for deletion: %T", t) } Prevention
- Always construct deletion delegators with awsup.NewAWSAPITarget(cloud)
- Don't pass dry-run or mock targets into real deletion paths
- Review target wiring after refactors of the apply machinery
When it happens
Trigger: Invoking deleteNLB.Delete with any fi.CloudupTarget that is not *awsup.AWSAPITarget — e.g. a dry-run/target passed into the deletion path, or a custom target type.
Common situations: Running deletion through a non-AWS target (e.g. a target built for a different cloud or a testing stub); code changes in kOps target wiring that route NLB deletion through the wrong target.
Related errors
- unexpected target type for deletion: %T
- unexpected target type for deletion: %T
- expected an AWS cloud, got %T
- DIGITALOCEAN_ACCESS_TOKEN is required
- the image for the hook exec action not set
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/cc8c0f74094fd4d8.
Report an issue: GitHub.