OpenShift - Delete project using REST API

by
Jeremy Canfield |
Updated: January 08 2024
| OpenShift articles
This assumes you have used the REST API to obtain an OAuth bearer token. Let's say the bearer token is sha256~0Rs__hPuXmBD3TJTXNDisC7wRBN-nrFnYTxgdBrFT-U.
Let's say you want to delete the project named "my-project". You probably first want to issue a GET request to see if my-project exists.
curl
--insecure
--request GET
--header "Accept: application/json"
--header "Authorization: Bearer sha256~0Rs__hPuXmBD3TJTXNDisC7wRBN-nrFnYTxgdBrFT-U"
--url "https://api.openshift.example.com:6443/api/v1/namespaces/my-project"
If the project exists, something like this should be returned.
{
"kind": "NamespaceList",
"apiVersion": "v1",
"metadata": {
"selfLink": "/api/v1/namespaces",
"resourceVersion": "637674757"
},
"items": [
{
"metadata": {
"name": "foo",
"selfLink": "/api/v1/namespaces/foo",
"uid": "d0022a41-0165-4734-b468-948fa40a93a9",
"resourceVersion": "568396970",
"creationTimestamp": "2020-10-20T13:40:08Z"
Here is how you could then delete my-project. The status of the project should be Terminating for a bit, and then the project should be deleted.
curl
--insecure
--request DELETE
--header "Accept: application/json"
--header "Content-Type: application/yaml"
--header "Authorization: Bearer sha256~0Rs__hPuXmBD3TJTXNDisC7wRBN-nrFnYTxgdBrFT-U"
--url "https://api.openshift.example.com:6443/api/v1/namespaces/my-project"
Did you find this article helpful?
If so, consider buying me a coffee over at