×

You can use boot sources that are system-defined and included with OKD Virtualization or user-defined, which you create. System-defined boot source imports and updates are controlled by the product feature gate. You can enable, disable, or re-enable updates using the feature gate. User-defined boot sources are not controlled by the product feature gate and must be individually managed to opt in or opt out of automatic imports and updates.

As of version 4.10, OKD Virtualization automatically imports and updates boot sources, unless you manually opt out or do not set a default storage class.

If you upgrade to version 4.10, you must manually enable automatic imports and updates for boot sources from version 4.9 or earlier.

Enabling automatic boot source updates

If you have boot sources from OKD Virtualization 4.9 or earlier, you must manually turn on automatic updates for these boot sources. All boot sources in OKD Virtualization 4.10 and later are automatically updated by default.

To enable automatic boot source imports and updates, set the cdi.kubevirt.io/dataImportCron field to true for each boot source you want to update automatically.

Procedure
  • To turn on automatic updates for a boot source, use the following command to apply the dataImportCron label to the data source:

    $ oc label --overwrite DataSource rhel8 -n openshift-virtualization-os-images cdi.kubevirt.io/dataImportCron=true (1)
    1 Specifying true turns on automatic updates for the rhel8 boot source.

Disabling automatic boot source updates

Disabling automatic boot source imports and updates can be helpful to reduce the number of logs in disconnected environments or to reduce resource usage.

To disable automatic boot source imports and updates, set the spec.featureGates.enableCommonBootImageImport field in the HyperConverged custom resource (CR) to false.

User-defined boot sources are not affected by this setting.

Procedure
  • Use the following command to disable automatic boot source updates:

    $ oc patch hco kubevirt-hyperconverged -n openshift-cnv \
     --type json -p '[{"op": "replace", "path": "/spec/featureGates/enableCommonBootImageImport", \
     "value": false}]'

Re-enabling automatic boot source updates

If you have previously disabled automatic boot source updates, you must manually re-enable the feature. Set the spec.featureGates.enableCommonBootImageImport field in the HyperConverged custom resource (CR) to true.

Procedure
  • Use the following command to re-enable automatic updates:

    $ oc patch hco kubevirt-hyperconverged -n openshift-cnv --type json -p '[{"op": "replace", "path": "/spec/featureGates/enableCommonBootImageImport", "value": true}]'

Configuring a storage class for user-defined boot source updates

You can configure a storage class that allows automatic importing and updating for user-defined boot sources.

Procedure
  1. Define a new storageClassName by editing the HyperConverged custom resource (CR).

    apiVersion: hco.kubevirt.io/v1beta1
    kind: HyperConverged
    metadata:
      name: kubevirt-hyperconverged
    spec:
      dataImportCronTemplates:
      - metadata:
          name: rhel8-image-cron
        spec:
          template:
            spec:
              storageClassName: <appropriate_class_name>
    ...
  2. Set the new default storage class by running the following commands:

    $ oc patch storageclass <current_default_storage_class> -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'
    $ oc patch storageclass <appropriate_storage_class> -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'

Enabling automatic updates for user-defined boot sources

OKD Virtualization automatically updates system-defined boot sources by default, but does not automatically update user-defined boot sources. You must manually enable automatic imports and updates on a user-defined boot sources by editing the HyperConverged custom resource (CR).

Procedure
  1. Use the following command to open the HyperConverged CR for editing:

    $ oc edit -n openshift-cnv HyperConverged
  2. Edit the HyperConverged CR, adding the appropriate template and boot source in the dataImportCronTemplates section. For example:

    Example in CentOS 7
    apiVersion: hco.kubevirt.io/v1beta1
    kind: HyperConverged
    metadata:
      name: kubevirt-hyperconverged
    spec:
      dataImportCronTemplates:
      - metadata:
          name: centos7-image-cron
          annotations:
            cdi.kubevirt.io/storage.bind.immediate.requested: "true" (1)
        spec:
          schedule: "0 */12 * * *" (2)
          template:
            spec:
              source:
                registry: (3)
                  url: docker://quay.io/containerdisks/centos:7-2009
              storage:
                resources:
                  requests:
                    storage: 10Gi
          managedDataSource: centos7 (4)
          retentionPolicy: "None" (5)
    1 This annotation is required for storage classes with volumeBindingMode set to WaitForFirstConsumer.
    2 Schedule for the job specified in cron format.
    3 Use to create a data volume from a registry source. Use the default pod pullMethod and not node pullMethod, which is based on the node docker cache. The node docker cache is useful when a registry image is available via Container.Image, but the CDI importer is not authorized to access it.
    4 For the custom image to be detected as an available boot source, the name of the image’s managedDataSource must match the name of the template’s DataSource, which is found under spec.dataVolumeTemplates.spec.sourceRef.name in the VM template YAML file.
    5 Use All to retain data volumes and data sources when the cron job is deleted. Use None to delete data volumes and data sources when the cron job is deleted.

Disabling an automatic update for a system-defined or user-defined boot source

You can disable automatic imports and updates for a user-defined boot source and for a system-defined boot source.

Because system-defined boot sources are not listed by default in the spec.dataImportCronTemplates of the HyperConverged custom resource (CR), you must add the boot source and disable auto imports and updates.

Procedure
  • To disable automatic imports and updates for a user-defined boot source, remove the boot source from the spec.dataImportCronTemplates field in the custom resource list.

  • To disable automatic imports and updates for a system-defined boot source:

    • Edit the HyperConverged CR and add the boot source to spec.dataImportCronTemplates.

    • Disable automatic imports and updates by setting the dataimportcrontemplate.kubevirt.io/enable annotation to false. For example:

      apiVersion: hco.kubevirt.io/v1beta1
      kind: HyperConverged
      metadata:
        name: kubevirt-hyperconverged
      spec:
        dataImportCronTemplates:
        - metadata:
            annotations:
              dataimportcrontemplate.kubevirt.io/enable: false
            name: rhel8-image-cron
      ...

Verifying the status of a boot source

You can verify whether a boot source is system-defined or user-defined.

The status section of each boot source listed in the status.dataImportChronTemplates field of the HyperConverged CR indicates the type of boot source. For example, commonTemplate: true indicates a system-defined (commonTemplate) boot source and status: {} indicates a user-defined boot source.

Procedure
  1. Use the oc get command to list the dataImportChronTemplates in the HyperConverged CR.

  2. Verify the status of the boot source.

    Example output
    ...
    apiVersion: hco.kubevirt.io/v1beta1
    kind: HyperConverged
    ...
    spec:
      ...
    status: (1)
      ...
      dataImportCronTemplates: (2)
      - metadata:
          annotations:
            cdi.kubevirt.io/storage.bind.immediate.requested: "true"
          name: centos-7-image-cron
        spec:
          garbageCollect: Outdated
          managedDataSource: centos7
          schedule: 55 8/12 * * *
          template:
            metadata: {}
            spec:
              source:
                registry:
                  url: docker://quay.io/containerdisks/centos:7-2009
              storage:
                resources:
                  requests:
                    storage: 30Gi
            status: {}
        status:
          commonTemplate: true (3)
        ...
      - metadata:
          annotations:
            cdi.kubevirt.io/storage.bind.immediate.requested: "true"
          name: user-defined-dic
        spec:
          garbageCollect: Outdated
          managedDataSource: user-defined-centos-stream8
          schedule: 55 8/12 * * *
          template:
            metadata: {}
            spec:
              source:
                registry:
                  pullMethod: node
                  url: docker://quay.io/containerdisks/centos-stream:8
              storage:
                resources:
                  requests:
                    storage: 30Gi
            status: {}
        status: {} (4)
    ...
    1 The status field for the HyperConverged CR.
    2 The dataImportCronTemplates field, which lists all defined boot sources.
    3 Indicates a system-defined boot source.
    4 Indicates a user-defined boot source.