// Module included in the following assemblies:
//
// * virt/install/installing-virt.adoc

:_mod-docs-content-type: PROCEDURE
[id="virt-subscribing-cli_{context}"]
= Subscribing to the {VirtProductName} catalog by using the CLI

[role="_abstract"]
Before you install {VirtProductName}, you must subscribe to the {VirtProductName} catalog. Subscribing gives the `{CNVNamespace}` namespace access to the {VirtProductName} Operators.

To subscribe, configure `Namespace`, `OperatorGroup`, and `Subscription` objects by applying a single manifest to your cluster.

.Prerequisites

* Install {product-title} {product-version} on your cluster.
* Install the {oc-first}.
* Log in as a user with `cluster-admin` privileges.

.Procedure

ifdef::openshift-enterprise,openshift-rosa,openshift-dedicated,openshift-rosa-hcp[]

. Create a YAML file that contains the following manifest:
//Note that there are two versions of the following YAML file; the first one is for openshift-enterprise and the second is for openshift-origin (aka OKD).
+
[source,yaml,subs="attributes+"]
----
apiVersion: v1
kind: Namespace
metadata:
  name: {CNVNamespace}
  labels:
    openshift.io/cluster-monitoring: "true"
---
apiVersion: operators.coreos.com/v1
kind: OperatorGroup
metadata:
  name: kubevirt-hyperconverged-group
  namespace: {CNVNamespace}
spec:
  targetNamespaces:
    - {CNVNamespace}
---
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
  name: hco-operatorhub
  namespace: {CNVNamespace}
spec:
  source: {CNVSubscriptionSpecSource}
  sourceNamespace: openshift-marketplace
  name: {CNVSubscriptionSpecName}
  startingCSV: kubevirt-hyperconverged-operator.v{HCOVersion}
  channel: "stable"
----
+
Using the `stable` channel ensures that you install the version of
{VirtProductName} that is compatible with your {product-title} version.

endif::openshift-enterprise,openshift-rosa,openshift-dedicated,openshift-rosa-hcp[]

ifdef::openshift-origin[]

. Create a YAML file that contains the following manifest:
+
[source,yaml,subs="attributes+"]
----
apiVersion: v1
kind: Namespace
metadata:
  name: {CNVNamespace}
---
apiVersion: operators.coreos.com/v1
kind: OperatorGroup
metadata:
  name: kubevirt-hyperconverged-group
  namespace: {CNVNamespace}
spec: {}
---
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
  name: hco-operatorhub
  namespace: {CNVNamespace}
spec:
  source: {CNVSubscriptionSpecSource}
  sourceNamespace: openshift-marketplace
  name: {CNVSubscriptionSpecName}
  startingCSV: kubevirt-hyperconverged-operator.v{HCOVersion}
  channel: "stable"
----
+
Using the `stable` channel ensures that you install the version of
{VirtProductName} that is compatible with your {product-title} version.

endif::openshift-origin[]

. Create the required `Namespace`, `OperatorGroup`, and `Subscription` objects
for {VirtProductName} by running the following command:
+
[source,terminal]
----
$ oc apply -f <filename>.yaml
----

.Verification

You must verify that the subscription creation was successful before you can proceed with installing {VirtProductName}.

. Check that the `ClusterServiceVersion` (CSV) object was created successfully. Run the following command and verify the output:
+
[source,terminal,subs="attributes+"]
----
$ oc get csv -n {CNVNamespace}
----
+
If the CSV was created successfully, the output shows an entry that contains a `NAME` value of `kubevirt-hyperconverged-operator-*`, a `DISPLAY` value of `{VirtProductName}`, and a `PHASE` value of `Succeeded`, as shown in the following example output:
+
Example output:
+
[source,terminal,subs="attributes+"]
----
NAME                                       DISPLAY                    VERSION   REPLACES                                   PHASE
kubevirt-hyperconverged-operator.v{HCOVersion}   {VirtProductName}   {HCOVersion}    kubevirt-hyperconverged-operator.v{HCOVersionPrev}   Succeeded
----

. Check that the `HyperConverged` custom resource (CR) has the correct version. Run the following command and verify the output:
+
[source,terminal,subs="attributes+"]
----
$ oc get hco -n {CNVNamespace} kubevirt-hyperconverged -o json | jq .status.versions
----
+
Example output:
+
[source,terminal,subs="attributes+"]
----
{
"name": "operator",
"version": "{HCOVersion}"
}
----

. Verify the `HyperConverged` CR conditions. Run the following command and check the output:
+
[source,terminal,subs="attributes+"]
----
$ oc get hco kubevirt-hyperconverged -n {CNVNamespace} -o json | jq -r '.status.conditions[] | {type,status}'
----
+
Example output:
+
[source,terminal]
----
{
  "type": "ReconcileComplete",
  "status": "True"
}
{
  "type": "Available",
  "status": "True"
}
{
  "type": "Progressing",
  "status": "False"
}
{
  "type": "Degraded",
  "status": "False"
}
{
  "type": "Upgradeable",
  "status": "True"
}
----
