How to delete an OpenShift 4 IPI cluster without a metadata.json file

Solution In Progress - Updated -

Environment

  • Red Hat OpenShift Container Platform 4.x

Issue

  • Lost the directory that stores metadata for OpenShift 4 Cluster.
  • Lost metadata.json file for OpenShift 4 cluster
  • How to delete OpenShift 4 cluster with lost directory or metadata

Resolution

If the OpenShift 4 cluster are deployed by installer (for IPI usecases) and you lost the associated metadata.json file, there is no way to delete the cluster using the OpenShift installer without the metadata.json file.

In order to destroy the cluster using the installer, you should generate metadata.json file.
Similar processes for GCP and Azure (or other IPI installs) can be used, however, they are not documented by this KCS (at this time).

  • Get CLUSTER_UUID and INFRA_ID
    If the cluster is still running

    $ CLUSTER_NAME=NAME
    $ AWS_REGION=REGION
    $ CLUSTER_UUID=$(oc get clusterversions.config.openshift.io version -o jsonpath='{.spec.clusterID}{"\n"}')
    $ INFRA_ID=$(oc get infrastructures.config.openshift.io cluster -o jsonpath='{.status.infrastructureName}{"\n"}')
    
  • Generate metadata.json file.

    echo "{\"clusterName\":\"${CLUSTER_NAME}\",\"clusterID\":\"${CLUSTER_UUID}\",\"infraID\":\"${INFRA_ID}\",\"aws\":{\"region\":\"${AWS_REGION}\",\"identifier\":[{\"kubernetes.io/cluster/${INFRA_ID}\":\"owned\"},{\"openshiftClusterID\":\"${CLUSTER_UUID}\"}]}}" > metadata.json
    
  • Destroy cluster with the generated metadata.json file

    ./openshift-install  destroy cluster --log-level=debug
    

Diagnostic Steps

  • In the commands above you need your clusterID, see KCS 3831361 on how to get this in several ways.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

3 Comments

json does not support single quotes, even if the golang parser accepts it, at least jq will not. We really should turn all of the ' into \'

I'm running a pre-release 4.2 cluster on VMWare vSphere, and trying this does not work since I don't have AWS... When I remove the aws-specific stuff and leave only clusterName, clusterID and infraID parts into metadata.json, I get error: "FATAL Failed while preparing to destroy cluster: no platform configured in metadata"

I also have a GA openshift 4.2 cluster (installed as 4.1, later upgraded) and that other cluster's metadata.json does not have anything other than clusterName, clusterID and infraID in it. If I tried to delete that cluster, how should I go about it?

Then, my clusters view in cloud.openshift.com have still yet another 4.1 cluster, which too was installed earlier into vSphere and there is not a single bit about it in existence anymore anywhere in our environment. I cannot even archive that cluster from my clusters view.

This KCS was intended for IPI based installs. Updates have been made to reflect this. For UPI installs, you need to manually delete the resources.