kubernetes/kops · error
error deleting TargetGroup %q: %v
Error message
error deleting TargetGroup %q: %v
What it means
DeleteTargetGroup wraps a failed ELBV2 DeleteTargetGroup API call with the target group ARN. As with the sibling deleters, dependency violations are returned unwrapped so the resource tracker can retry after dependents are removed.
Source
Thrown at pkg/resources/aws/aws.go:1504
}
return nil
}
func DeleteTargetGroup(cloud fi.Cloud, r *resources.Resource) error {
ctx := context.TODO()
c := cloud.(awsup.AWSCloud)
id := r.ID
klog.V(2).Infof("Deleting TargetGroup %q", id)
request := &elbv2.DeleteTargetGroupInput{
TargetGroupArn: aws.String(id),
}
_, err := c.ELBV2().DeleteTargetGroup(ctx, request)
if err != nil {
if IsDependencyViolation(err) {
return err
}
return fmt.Errorf("error deleting TargetGroup %q: %v", id, err)
}
return nil
}
func DumpELB(op *resources.DumpOperation, r *resources.Resource) error {
data := make(map[string]interface{})
data["id"] = r.ID
data["type"] = TypeLoadBalancer
data["raw"] = r.Obj
op.Dump.Resources = append(op.Dump.Resources, data)
if lb, ok := r.Obj.(elbv2types.LoadBalancer); ok {
op.Dump.LoadBalancers = append(op.Dump.LoadBalancers, &resources.LoadBalancer{
Name: fi.ValueOf(lb.LoadBalancerName),
DNSName: fi.ValueOf(lb.DNSName),
})
}View on GitHub (pinned to 4c8573c808)
Solutions
- Ensure the ALB/NLB listeners referencing the target group are deleted first, then retry — order matters and the tracker retries dependency violations.
- Retry the teardown after a short wait; ELB deletion is asynchronous.
- Verify IAM permissions include elasticloadbalancing:DeleteTargetGroup.
- Check with aws elbv2 describe-target-groups whether the TG still exists; if gone, continue.
- Reduce API concurrency if throttling errors appear in the wrapped message.
Defensive patterns
Strategy: retry
Validate before calling
// Ensure no listeners still reference the target group
lbs, _ := c.ELBV2().DescribeLoadBalancers(ctx, &elbv2.DescribeLoadBalancersInput{})
for _, lb := range lbs.LoadBalancers {
ls, _ := c.ELBV2().DescribeListeners(ctx, &elbv2.DescribeListenersInput{LoadBalancerArn: lb.LoadBalancerArn})
for _, l := range ls.Listeners {
for _, tg := range l.DefaultActions { if *tg.TargetGroupArn == arn { /* delete listener first */ } }
}
} Try / catch
for attempt := 0; attempt < 5; attempt++ {
err := DeleteTargetGroup(cloud, r)
if err == nil || awsup.AWSErrorCode(err) == "TargetGroupInUse" && attempt < 4 {
time.Sleep(time.Duration(1<<attempt) * time.Second); continue
}
return err
} Prevention
- Always delete listeners before target groups.
- Retry on TargetGroupInUse; ALB deletion is asynchronous.
- Grant elasticloadbalancing:DeleteTargetGroup in IAM.
- Verify TG ARN/region correctness.
- Batch teardowns with pacing to avoid throttling.
When it happens
Trigger: DeleteTargetGroup fails because the target group is still referenced by a listener (TargetGroupInUse), is still associated with an ALB/NLB being deleted concurrently, IAM denies elasticloadbalancing:DeleteTargetGroup, or throttling occurs.
Common situations: Cluster teardown order where the ALB deletion hasn't completed before target group deletion; leftover listeners still pointing at the TG; API throttling across many resources.
Related errors
- error deleting ELB TargetGroup %q: %w
- error deleting V2 LoadBalancer %q: %v
- failed to detach target groups from autoscaling group: %v
- error deleting ELB LoadBalancer %q: %w
- error deleting load balancer listener with arn=%q: %w
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/542ed71a5b949594.
Report an issue: GitHub.