kubernetes/kops · error
unexpected target type for deletion: %T
Error message
unexpected target type for deletion: %T
What it means
deleteSecurityGroup.Delete performs a runtime type assertion that the fi.CloudupTarget passed by the provisioning framework is an *openstack.OpenstackAPITarget. This error is returned when the target is any other concrete type, which would mean the deletion is being run against the wrong cloud's target. It is an internal invariant check rather than a cloud API failure.
Source
Thrown at upup/pkg/fi/cloudup/openstacktasks/securitygroup.go:244
if perm.RemoteIPPrefix != fi.ValueOf(t.RemoteIPPrefix) {
return false
}
return true
}
type deleteSecurityGroup struct {
securityGroup *SecurityGroup
}
var _ fi.CloudupDeletion = (*deleteSecurityGroup)(nil)
func (d *deleteSecurityGroup) Delete(t fi.CloudupTarget) error {
klog.V(2).Infof("deleting security group: %v", fi.DebugAsJsonString(d.securityGroup.Name))
os, ok := t.(*openstack.OpenstackAPITarget)
if !ok {
return fmt.Errorf("unexpected target type for deletion: %T", t)
}
err := os.Cloud.DeleteSecurityGroup(fi.ValueOf(d.securityGroup.ID))
if err != nil {
return fmt.Errorf("error revoking SecurityGroup: %v", err)
}
return nil
}
func (d *deleteSecurityGroup) TaskName() string {
return "SecurityGroup"
}
func (d *deleteSecurityGroup) Item() string {
s := fmt.Sprintf("securitygroup=%s", fi.ValueOf(d.securityGroup.Name))
return s
}
func (d *deleteSecurityGroup) DeferDeletion() bool {View on GitHub (pinned to 4c8573c808)
Solutions
- Check that the cluster spec's cloudProvider is openstack and that you are running the intended kops command against the right cluster.
- Ensure deletions are only created/executed within an OpenStack apply context (the OpenstackAPITarget built by cloudup).
- In tests or custom code, pass an *openstack.OpenstackAPITarget (construct via openstack.NewOpenstackAPITarget) instead of a generic target.
Example fix
// before: wrong target type passed
target := myCustomTarget{}
del.Delete(target) // unexpected target type for deletion: main.myCustomTarget
// after
target, err := openstack.NewOpenstackAPITarget(cloud)
del.Delete(target) Defensive patterns
Strategy: type-guard
Validate before calling
// confirm the cluster targets openstack before executing deletions
if cluster.Spec.CloudProvider.Openstack == nil {
return fmt.Errorf("deletion requires an openstack cluster")
} Type guard
os, ok := t.(*openstack.OpenstackAPITarget)
if !ok {
return fmt.Errorf("unexpected target type for deletion: %T", t)
}
_ = os Try / catch
if err := deletion.Delete(target); err != nil {
if strings.Contains(err.Error(), "unexpected target type") {
// rebuild the correct *openstack.OpenstackAPITarget and retry
osTarget, terr := openstack.NewOpenstackAPITarget(cloud)
if terr == nil {
err = deletion.Delete(osTarget)
}
}
return err
} Prevention
- Never change cloudProvider on an existing cluster spec; create a new cluster instead.
- Use kops CLI entry points rather than invoking deletion tasks manually.
- In tests, always pass an *openstack.OpenstackAPITarget to Delete.
When it happens
Trigger: The fi.CloudupDeletion framework invokes Delete(t) with a target that is not *openstack.OpenstackAPITarget — e.g. running an OpenStack task's deletion on an AWS/GCP/DigitalOcean/Liiklus target, or a custom/test target implementation.
Common situations: Running kOps against a cluster whose cloud provider was changed in the spec (cross-cloud apply); unit tests passing a mock fi.CloudupTarget; bespoke tooling invoking deletion tasks directly with the wrong target.
Related errors
- %T is not a *compute.BackendService
- error deleting subnet: %v
- Fixed IP was not a string: %v
- error deleting volume: %v
- error revoking SecurityGroup: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/c3b7c9dfd0025b71.
Report an issue: GitHub.