IBM Support

Cloud Pak for Security: How to delete a Project stuck in a Terminating status

How To


Summary

Red Hat OpenShift Container Platform Projects have a Kubernetes finalizer that prevents the deletion of the Project before all the resources are removed. After all visible resources are removed from the Project, a hidden item can still prevent the Project from being deleted, so the Project gets stuck in a 'Terminating' status.

Objective

The objective is to provide a process for Red Hat OpenShift Container Platform to delete a project that is stuck in a 'Terminating' status.
Project_Terminating

Environment

Red Hat OpenShift Container Platform 4.8

Steps

  1. Log in to your Red Hat OpenShift Container Platform Console.
  2. In Red Hat OpenShift Container Platform Console click the drop-down arrow next to your username, select the option 'Copy login command', then click 'Display Token'.
    Token_Location
    Display_Token
    NOTE: You might need to authenticate again.
  3. Highlight and copy the oc login command.
  4. Connect to the Red Hat OpenShift Platform Server with SSH.
  5. When successfully logged in paste the oc login command, copied in Step 3.
    oc login –-token=sha256......
  6. Run the following command to retrieve a list of Projects.
    oc get projects
    A list of Projects are displayed, take note of the Project name that has a 'Terminating' status.
    NOTE: In the following commands, replace <Project> with the actual Project name.
  7. Obtain a copy of the configuration for the Project that is in a Terminating status by running the following command.
    oc get namespace <Project> -o json > <Project>-ns.json
  8. Create a Backup of the JSON configuration file.
    cp <Project>-ns.json <Project>-ns.backup.json
  9. Edit the saved JSON configuration file.
    vi <Project>-ns.json
    {
        "apiVersion": "v1",
        "kind": "Namespace",
        "metadata": {
            ...
            "name": "finalizer-example",
            ...
        },
        "spec": {
            "finalizers": [
                "kubernetes"
            ]
        },
        "status": {
            ...
        }
    }
    
  10. Scroll down the file and remove the contents of the finalizer array so your file looks similar to the next screen.
    Delete the reference to "Kubernetes".
            ...
        },
        "spec": {
            "finalizers": []
        },
            ...
  11. Press escape (Esc) followed by :x to save the file.
  12. Run a cat command on the <Project>-ns.json file to confirm the JSON file was saved correctly.
    cat <Project>-ns.json
  13. Run the following curl command in your terminal window to fully remove the unwanted Project.
    curl -k -H "Content-Type: application/json" -H "Authorization: Bearer $(oc whoami -t)" -X PUT --data-binary @<Project>-ns.json  https://<OPENSHIFT_CONSOLE_ADDRESS>:6443/api/v1/namespaces/<Project>/finalize
  14. Confirm in the Red Hat OpenShift Server from the command line that the Project was removed by running the 'oc get projects' command again.
    oc get projects
    NOTE: You can also verify from the Red Hat OpenShift Console page that the Project was removed from under the Projects section.

Document Location

Worldwide

[{"Type":"MASTER","Line of Business":{"code":"LOB24","label":"Security Software"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSTDPP","label":"IBM Cloud Pak for Security"},"ARM Category":[{"code":"a8m3p0000000rbnAAA","label":"Administration Task"}],"ARM Case Number":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"All Versions"}]

Document Information

Modified date:
30 August 2022

UID

ibm16607563