OpenShift Finalizers

  • Issue, can’t delete a object in this case a project
oc delete project fishbone

oc get projects fishbone
NAME       DISPLAY NAME   STATUS
fishbone   Fishbone       Terminating

  • Solution
oc get project fishbone -o=json > fishbone.json
{
  "apiVersion": "v1",
  "kind": "Namespace",
  "metadata": {
    "annotations":
      "openshift.io/description": "",
      "openshift.io/display-name": "Fishbone",
      "openshift.io/requester": "system:admin",
      "openshift.io/sa.scc.mcs": "s0:c24,c14",
      "openshift.io/sa.scc.supplemental-groups": "1000580000/10000",
      "openshift.io/sa.scc.uid-range": "1000580000/10000"
    },
    "creationTimestamp": "2021-02-20T03:29:59Z",
    "deletionTimestamp": "2021-02-20T03:31:35Z",
    "name": "fishbone",
    "resourceVersion": "270664",
    "selfLink": "/api/v1/namespaces/fishbone",
    "uid": "885c4440-6f05-4e72-a103-28e61705406f"
  },
  "spec": {
    "finalizers": [
      "kubernetes"
    ]
  },
  "status": {
    "conditions": [
        .
        .
        .
    ],
    "phase": "Terminating"
}

oc whoami --show-token
vwNuL0BFroXfaWocLctWnyTc23rONlxmamKwYwSCE34
oc whoami --show-server
https://api.cluster-rgbnl.dynamic.opentlc.com:6443

curl -k -H "authorization: Bearer vwNuL0BFroXfaWocLctWnyTc23rONlxmamKwYwSCE34"   -H "Content-Type: application/json" -X PUT --data-binary @fishbone.json https://api.cluster-rgbnl.dynamic.opentlc.com:6443/api/v1/namespaces/fishbone/finalize

oc get projects fishbone
Error from server (NotFound): namespaces "fishbone" not found


oc api-resources --namespaced --verbs=list -o name
oc api-resources --verbs=list --namespaced -o name | xargs -n 1 oc get --show-kind --ignore-not-found -o jsonpath='{range .items[*]}{.kind}/{.metadata.name}: {.metadata.finalizers}{"\n"}{end}'
oc get FishBone/fishbone-object -o yaml
oc patch fishbone/fishbone-object --type=merge -p '{"metadata": {"finalizers":null}}'

References:

  • Kubernetes Advanced Topics1
  • Kubernetes Namespace Stuck2

  1. https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#advanced-topics ↩︎

  2. https://success.mirantis.com/article/kubernetes-namespace-stuck-in-terminating ↩︎

Previous
Next