{"record":{"id":"c3b7c9dfd0025b71","repo":"kubernetes/kops","slug":"unexpected-target-type-for-deletion-t-c3b7c9","errorCode":null,"errorMessage":"unexpected target type for deletion: %T","messagePattern":"unexpected target type for deletion: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/openstacktasks/securitygroup.go","lineNumber":244,"sourceCode":"\tif perm.RemoteIPPrefix != fi.ValueOf(t.RemoteIPPrefix) {\n\t\treturn false\n\t}\n\n\treturn true\n}\n\ntype deleteSecurityGroup struct {\n\tsecurityGroup *SecurityGroup\n}\n\nvar _ fi.CloudupDeletion = (*deleteSecurityGroup)(nil)\n\nfunc (d *deleteSecurityGroup) Delete(t fi.CloudupTarget) error {\n\tklog.V(2).Infof(\"deleting security group: %v\", fi.DebugAsJsonString(d.securityGroup.Name))\n\n\tos, ok := t.(*openstack.OpenstackAPITarget)\n\tif !ok {\n\t\treturn fmt.Errorf(\"unexpected target type for deletion: %T\", t)\n\t}\n\terr := os.Cloud.DeleteSecurityGroup(fi.ValueOf(d.securityGroup.ID))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error revoking SecurityGroup: %v\", err)\n\t}\n\treturn nil\n}\n\nfunc (d *deleteSecurityGroup) TaskName() string {\n\treturn \"SecurityGroup\"\n}\n\nfunc (d *deleteSecurityGroup) Item() string {\n\ts := fmt.Sprintf(\"securitygroup=%s\", fi.ValueOf(d.securityGroup.Name))\n\treturn s\n}\n\nfunc (d *deleteSecurityGroup) DeferDeletion() bool {","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/openstacktasks/securitygroup.go#L226-L262","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: wrong target type passed\ntarget := myCustomTarget{}\ndel.Delete(target) // unexpected target type for deletion: main.myCustomTarget\n// after\ntarget, err := openstack.NewOpenstackAPITarget(cloud)\ndel.Delete(target)","handlingStrategy":"type-guard","validationCode":"// confirm the cluster targets openstack before executing deletions\nif cluster.Spec.CloudProvider.Openstack == nil {\n\treturn fmt.Errorf(\"deletion requires an openstack cluster\")\n}","typeGuard":"os, ok := t.(*openstack.OpenstackAPITarget)\nif !ok {\n\treturn fmt.Errorf(\"unexpected target type for deletion: %T\", t)\n}\n_ = os","tryCatchPattern":"if err := deletion.Delete(target); err != nil {\n\tif strings.Contains(err.Error(), \"unexpected target type\") {\n\t\t// rebuild the correct *openstack.OpenstackAPITarget and retry\n\t\tosTarget, terr := openstack.NewOpenstackAPITarget(cloud)\n\t\tif terr == nil {\n\t\t\terr = deletion.Delete(osTarget)\n\t\t}\n\t}\n\treturn err\n}","preventionTips":["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."],"tags":["openstack","type-assertion","delete","internal-invariant"],"backgroundTag":"unexpected-target-type","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}