Deploying a virtual machine template to a custom namespace

Red Hat provides preconfigured virtual machine templates that are installed in the openshift namespace. The ssp-operator deploys virtual machine templates to the openshift namespace by default. Templates in the openshift namespace are publicly available to all users. These templates are listed on the VirtualizationTemplates page for different operating systems.

Creating a custom namespace for templates

You can create a custom namespace that is used to deploy virtual machine templates for use by anyone who has permissions to access those templates. To add templates to a custom namespace, edit the HyperConverged custom resource (CR), add commonTemplatesNamespace to the spec, and specify the custom namespace for the virtual machine templates. After the HyperConverged CR is modified, the ssp-operator populates the templates in the custom namespace.

Prerequisites

  • Install the OKD CLI oc.

  • Log in as a user with cluster-admin privileges.

Procedure

  • Use the following command to create your custom namespace:

    1. $ oc create namespace <mycustomnamespace>

Adding templates to a custom namespace

The ssp-operator deploys virtual machine templates to the openshift namespace by default. Templates in the openshift namespace are publicly availably to all users. When a custom namespace is created and templates are added to that namespace, you can modify or delete virtual machine templates in the openshift namespace. To add templates to a custom namespace, edit the HyperConverged custom resource (CR) which contains the ssp-operator.

Procedure

  1. View the list of virtual machine templates that are available in the openshift namespace.

    1. $ oc get templates -n openshift
  2. Edit the HyperConverged CR in your default editor by running the following command:

    1. $ oc edit hco -n openshift-cnv kubevirt-hyperconverged
  3. View the list of virtual machine templates that are available in the custom namespace.

    1. $ oc get templates -n customnamespace
  4. Add the commonTemplatesNamespace attribute and specify the custom namespace. Example:

    1. apiVersion: hco.kubevirt.io/v1beta1
    2. kind: HyperConverged
    3. metadata:
    4. name: kubevirt-hyperconverged
    5. spec:
    6. commonTemplatesNamespace: customnamespace (1)
    1The custom namespace for deploying templates.
  5. Save your changes and exit the editor. The ssp-operator adds virtual machine templates that exist in the default openshift namespace to the custom namespace.

Deleting templates from a custom namespace

To delete virtual machine templates from a custom namespace, remove the commonTemplateNamespace attribute from the HyperConverged custom resource (CR) and delete each template from that custom namespace.

Procedure

  1. Edit the HyperConverged CR in your default editor by running the following command:

    1. $ oc edit hco -n openshift-cnv kubevirt-hyperconverged
  2. Remove the commonTemplateNamespace attribute.

    1. apiVersion: hco.kubevirt.io/v1beta1
    2. kind: HyperConverged
    3. metadata:
    4. name: kubevirt-hyperconverged
    5. spec:
    6. commonTemplatesNamespace: customnamespace (1)
    1The commonTemplatesNamespace attribute to be deleted.
  3. Delete a specific template from the custom namespace that was removed.

    1. $ oc delete templates -n customnamespace <template_name>

Verification

  • Verify that the template was deleted from the custom namespace.

    1. $ oc get templates -n customnamespace

Additional resources