OpenShift - Delete group using REST API

by
Jeremy Canfield |
Updated: January 30 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.
Here is how you would list every group. The oc config view or oc get apiserver commands can be used to display the API Server URL (api.openshift.example.com in this example).
curl
--insecure
--request GET
--header "Accept: application/json"
--header "Authorization: Bearer sha256~0Rs__hPuXmBD3TJTXNDisC7wRBN-nrFnYTxgdBrFT-U"
--url "https://api.openshift.example.com:6443/apis/user.openshift.io/v1/groups"
Or, to GET a specific group.
curl
--insecure
--request GET
--header "Accept: application/json"
--header "Authorization: Bearer sha256~0Rs__hPuXmBD3TJTXNDisC7wRBN-nrFnYTxgdBrFT-U"
--url "https://api.openshift.example.com:6443/apis/user.openshift.io/v1/groups/my-group"
Something like this should be returned.
{
[
{
"metadata": {
"name": "my-group",
"uid": "613c1af0-bf13-42ec-be5b-f6f0c889fd12",
"resourceVersion": "1050548501",
"creationTimestamp": "2022-01-07T16:15:57Z",
"managedFields": [
{
"manager": "python-requests",
"operation": "Update",
"apiVersion": "user.openshift.io/v1",
"time": "2022-01-07T16:15:57Z",
"fieldsType": "FieldsV1",
"fieldsV1": {
"f:users": {}
}
}
]
},
"users": [
"john.doe",
"jane.doe"
]
}
]
}
The following DELETE request could then be used to delete the group.
AVOID TROUBLE
Before deleting a group, you probably should remove the group from any Role Bindings or Cluster Role Bindings the group is listed in.
curl \
--insecure \
--request DELETE \
--header "Authorization: Bearer sha256~0Rs__hPuXmBD3TJTXNDisC7wRBN-nrFnYTxgdBrFT-U" \
--url https://api.openshift.example.com:6443/apis/user.openshift.io/v1/groups/my-group
Did you find this article helpful?
If so, consider buying me a coffee over at