Force delete OpenShift project/namespace

To delete a project/namespace <namespace>:

curl -s https://raw.githubusercontent.com/jefferyb/useful-scripts/master/openshift/force-delete-openshift-project | bash -s -- -n "<namespace>"

To delete multiple projects/namespaces (network-diag-global-ns-86drn network-diag-global-ns-x8jfp network-diag-ns-hndp2 network-diag-ns-m6h4b):

curl -s https://raw.githubusercontent.com/jefferyb/useful-scripts/master/openshift/force-delete-openshift-project | bash -s -- -n "network-diag-global-ns-86drn network-diag-global-ns-x8jfp network-diag-ns-hndp2 network-diag-ns-m6h4b"


The other day when I was at Red Hat Summit 2019, our Dev OpenShift cluster started to act up and not deleting namespaces/projects. It would just get stuck at "Terminating" state, and won't get deleted, within the OpenShift cluster.

Whenever I would try oc delete project <namespace> again, I would get this error message below:

Error from server (Conflict): Operation cannot be fulfilled on namespaces "<namespace>": The system is ensuring all content is removed from this namespace. Upon completion, this namespace will automatically be purged by the system.

I got some people from Red Hat at the summit to take a look at it, and no one could resolve it, at least not in the moment. But they were very helpful and willing to help, bringing others in, etc... It was great.

They recommended to create an issue, https://github.com/openshift/origin/issues/22846, and they are taking a look at it from where we left off.

In the meantime, I looked around and found this, https://github.com/openshift/origin/issues/19399#issuecomment-383160540, tried it on one of my projects that were not being deleted and it worked. So, I created a quick script that I can use for now until the fix is found.

force-delete-openshift-project, https://github.com/jefferyb/useful-scripts/blob/master/openshift/force-delete-openshift-project.

Options:
  -n: List of namespaces to delete
  -u: The OpenShift server's REST API URL. Default: 'oc whoami --show-server'
  -t: Token to use. Default: 'oc whoami -t'
  -h, --help: Show options
  
Examples:
  # To get help:
  force-delete-openshift-project -h
  
  # To delete 'test123' namespace:
  force-delete-openshift-project -n test123
  
  # To delete more than one namespaces, 'test123 alpha beta' namespaces:
  force-delete-openshift-project -n 'test123 alpha beta'
  # To use a different url:
  force-delete-openshift-project -n test123 -u https://console.example.com:8443
  
  # To provide a token to use:
  force-delete-openshift-project -n test123 -t _gevQ0rnvXfMJzkFy1NPh9Kf4jYOk1qhNT6wb4
  force-delete-openshift-project -n test123 -u https://console.example.com:8443 -t _gevQ0rnvXfMJzkFy1NPh9Kf4jYOk1qhNT6wb4