kubernetes/kops · error

unexpected target type for deletion: %T

Error message

unexpected target type for deletion: %T

What it means

deleteVPCCIDRBlock.Delete is only implemented for the AWS API target. If the deletion runner passes any other target type, the type assertion fails and this error reports the unexpected concrete type. It is an internal invariant violation, not an AWS error.

Source

Thrown at upup/pkg/fi/cloudup/awstasks/vpc.go:383

		return terraformWriter.LiteralFromStringValue(*e.ID)
	}

	return terraformWriter.LiteralProperty("aws_vpc", *e.Name, "id")
}

type deleteVPCCIDRBlock struct {
	vpcID         *string
	cidrBlock     *string
	associationID *string
}

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

func (d *deleteVPCCIDRBlock) 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)
	}
	request := &ec2.DisassociateVpcCidrBlockInput{
		AssociationId: d.associationID,
	}
	_, err := awsTarget.Cloud.EC2().DisassociateVpcCidrBlock(ctx, request)
	return err
}

func (d *deleteVPCCIDRBlock) TaskName() string {
	return "VPCCIDRBlock"
}

func (d *deleteVPCCIDRBlock) Item() string {
	return fmt.Sprintf("%v: cidr=%v", *d.vpcID, *d.cidrBlock)
}

func (d *deleteVPCCIDRBlock) DeferDeletion() bool {
	return false // TODO: should we defer this?

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Ensure deletion is executed with an AWSAPITarget (real AWS apply/delete path)
  2. If a new target type exists, implement Delete support for it or exclude it from VPC CIDR deletion
  3. Report a bug with the %T output if it occurs in stock kOps

Example fix

// before: generic target passed
err := d.Delete(someGenericTarget)
// after
awsTarget, ok := t.(*awsup.AWSAPITarget); if !ok { return fmt.Errorf(...) } // ensure correct target wired
Defensive patterns

Strategy: type-guard

Validate before calling

if _, ok := target.(*awsup.AWSAPITarget); !ok {
	return errors.New("VPC CIDR deletion requires an AWS API target")
}

Type guard

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

Try / catch

err := d.Delete(t)
if err != nil && strings.Contains(err.Error(), "unexpected target type") {
	// bug/invariant violation: log target type and report
}

Prevention

When it happens

Trigger: Delete invoked with a target other than *awsup.AWSAPITarget, e.g. a dry-run/mock target or a new target type wired into deletion without implementing this path.

Common situations: Custom forks adding target types; running deletion through a target intended for terraform/cloudspec outputs; internal refactors changing the target passed to deletion actions.

Related errors


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