// Module included in the following assemblies:
//
// networking/k8s_nmstate/k8s-nmstate-about-the-kubernetes-nmstate-operator.adoc

:_mod-docs-content-type: PROCEDURE
[id="k8s-nmstate-uninstall-operator_{context}"]
= Uninstalling the Kubernetes NMState Operator

You can use the {olm-first} to uninstall the Kubernetes NMState Operator, but by design {olm} does not delete any associated custom resource definitions (CRDs), custom resources (CRs), or API Services.

Before you uninstall the Kubernetes NMState Operator from the `Subcription` resource used by {olm}, identify what Kubernetes NMState Operator resources to delete. This identification ensures that you can delete resources without impacting your running cluster.

If you need to reinstall the Kubernetes NMState Operator, see "Installing the Kubernetes NMState Operator by using the CLI" or "Installing the Kubernetes NMState Operator by using the web console".

.Prerequisites

* You have installed the {oc-first}.
* You have installed the `jq` CLI tool.
* You are logged in as a user with `cluster-admin` privileges.

.Procedure

. Unsubscribe the Kubernetes NMState Operator from the `Subcription` resource by running the following command:
+
[source,terminal]
----
$ oc delete --namespace openshift-nmstate subscription kubernetes-nmstate-operator
----

. Find the `ClusterServiceVersion` (CSV) resource that associates with the Kubernetes NMState Operator:
+
[source,terminal]
----
$ oc get --namespace openshift-nmstate clusterserviceversion
----
+
.Example output that lists a CSV resource
[source,terminal]
----
NAME                              	  DISPLAY                   	VERSION   REPLACES     PHASE
kubernetes-nmstate-operator.v4.21.0   Kubernetes NMState Operator   4.21.0           	   Succeeded
----

. Delete the CSV resource. After you delete the file, {olm} deletes certain resources, such as `RBAC`, that it created for the Operator.
+
[source,terminal]
----
$ oc delete --namespace openshift-nmstate clusterserviceversion kubernetes-nmstate-operator.v4.21.0
----

. Delete the `nmstate` CR and any associated `Deployment` resources by running the following commands:
+
[source,terminal]
----
$ oc -n openshift-nmstate delete nmstate nmstate
----
+
[source,terminal]
----
$ oc delete --all deployments --namespace=openshift-nmstate
----

. After you deleted the `nmstate` CR, remove the `nmstate-console-plugin` console plugin name from the `console.operator.openshift.io/cluster` CR.
+
.. Store the position of the `nmstate-console-plugin` entry that exists among the list of enable plugins by running the following command. The following command uses the `jq` CLI tool to store the index of the entry in an environment variable named `INDEX`:
+
[source,terminal]
----
INDEX=$(oc get console.operator.openshift.io cluster -o json | jq -r '.spec.plugins | to_entries[] | select(.value == "nmstate-console-plugin") | .key')
----
+
.. Remove the `nmstate-console-plugin` entry from the `console.operator.openshift.io/cluster` CR by running the following patch command:
+
[source,terminal]
----
$ oc patch console.operator.openshift.io cluster --type=json -p "[{\"op\": \"remove\", \"path\": \"/spec/plugins/$INDEX\"}]" <1>
----
<1> `INDEX` is an auxiliary variable. You can specify a different name for this variable.

. Delete all the custom resource definitions (CRDs), such as `nmstates.nmstate.io`, by running the following commands:
+
[source,terminal]
----
$ oc delete crd nmstates.nmstate.io
----
+
[source,terminal]
----
$ oc delete crd nodenetworkconfigurationenactments.nmstate.io
----
+
[source,terminal]
----
$ oc delete crd nodenetworkstates.nmstate.io
----
+
[source,terminal]
----
$ oc delete crd nodenetworkconfigurationpolicies.nmstate.io
----

. Delete the namespace:
+
[source,terminal]
----
$ oc delete namespace openshift-nmstate
----
