When running the following delete-orphaned-routes command an unknown error is returned.
~> cf delete-orphaned-routes -f
Deleting orphaned routes as admin...
Job (<GUID>) failed: An unknown error occurred.
FAILED
Upon inspection of the cloud_controller_worker logs we will find the following database error code "CF-ForeignKeyConstraintViolation"
./cloud_controller_worker.<GUID>.2024-10-21-21-52-21.tgz-extracted/cloud_controller_worker/cloud_controller_worker.log.6:{"timestamp":"2024-09-13T05:32:40.949646562Z","message":"Request failed: 500: {\"error_code\"=>\"UnknownError\", \"description\"=>\"An unknown error occurred.\", \"code\"=>10001, \"test_mode_info\"=>{\"description\"=>\"Mysql2::Error: Cannot delete or update a parent row: a foreign key constraint fails (`ccdb`.`route_labels`, CONSTRAINT `fk_route_labels_resource_guid` FOREIGN KEY (`resource_guid`) REFERENCES `routes` (`guid`) ON DELETE RESTRICT ON UPDATE RESTRICT)\", \"error_code\"=>\"CF-ForeignKeyConstraintViolation\", \"backtrace\"=>[
The foreign key constraint error is triggered because the orphaned route has a label associated with it and the delete-orphaned-routes cli command is not checking and deleting the labels prior to deleting the route.
you can check for labels on your route using this command
~> cf labels route myapp.cfapps.domain.com
Getting labels for route yup.cfapps.humble-abode.diy in org danl / space dev as admin...
key value
mykey myvalue
To workaround this error you can delete the route manually using "cf delete-route" which will automatically clean up the label references. Alternatively you can run the below command to remove labels from the given route and then rerun the delete-orphaned-routes command
cf unset-label route myapp.cfapps.domain.com mykey