Automatic importing and updating of pre-defined boot sources

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. 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:

    1. $ oc label --overwrite DataSource rhel8 -n openshift-virtualization-os-images cdi.kubevirt.io/dataImportCron=true (1)
    1Specifying 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:

    1. $ oc patch hco kubevirt-hyperconverged -n openshift-cnv \
    2. --type json -p '[{"op": "replace", "path": "/spec/featureGates/enableCommonBootImageImport", \
    3. "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:

    1. $ 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).

    1. apiVersion: hco.kubevirt.io/v1beta1
    2. kind: HyperConverged
    3. metadata:
    4. name: kubevirt-hyperconverged
    5. spec:
    6. dataImportCronTemplates:
    7. - metadata:
    8. name: rhel8-image-cron
    9. spec:
    10. template:
    11. spec:
    12. storageClassName: <appropriate_class_name>
    13. ...
  2. Set the new default storage class by running the following commands:

    1. $ oc patch storageclass <current_default_storage_class> -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'
    1. $ 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:

    1. $ 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

    1. apiVersion: hco.kubevirt.io/v1beta1
    2. kind: HyperConverged
    3. metadata:
    4. name: kubevirt-hyperconverged
    5. spec:
    6. dataImportCronTemplates:
    7. - metadata:
    8. name: centos7-image-cron
    9. annotations:
    10. cdi.kubevirt.io/storage.bind.immediate.requested: "true" (1)
    11. spec:
    12. schedule: "0 */12 * * *" (2)
    13. template:
    14. spec:
    15. source:
    16. registry: (3)
    17. url: docker://quay.io/containerdisks/centos:7-2009
    18. storage:
    19. resources:
    20. requests:
    21. storage: 10Gi
    22. managedDataSource: centos7 (4)
    23. retentionPolicy: "None" (5)
    1This annotation is required for storage classes with volumeBindingMode set to WaitForFirstConsumer.
    2Schedule for the job specified in cron format.
    3Use 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.
    4For 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.
    5Use 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:

      1. apiVersion: hco.kubevirt.io/v1beta1
      2. kind: HyperConverged
      3. metadata:
      4. name: kubevirt-hyperconverged
      5. spec:
      6. dataImportCronTemplates:
      7. - metadata:
      8. annotations:
      9. dataimportcrontemplate.kubevirt.io/enable: false
      10. name: rhel8-image-cron
      11. ...

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

    1. ...
    2. apiVersion: hco.kubevirt.io/v1beta1
    3. kind: HyperConverged
    4. ...
    5. spec:
    6. ...
    7. status: (1)
    8. ...
    9. dataImportCronTemplates: (2)
    10. - metadata:
    11. annotations:
    12. cdi.kubevirt.io/storage.bind.immediate.requested: "true"
    13. name: centos-7-image-cron
    14. spec:
    15. garbageCollect: Outdated
    16. managedDataSource: centos7
    17. schedule: 55 8/12 * * *
    18. template:
    19. metadata: {}
    20. spec:
    21. source:
    22. registry:
    23. url: docker://quay.io/containerdisks/centos:7-2009
    24. storage:
    25. resources:
    26. requests:
    27. storage: 30Gi
    28. status: {}
    29. status:
    30. commonTemplate: true (3)
    31. ...
    32. - metadata:
    33. annotations:
    34. cdi.kubevirt.io/storage.bind.immediate.requested: "true"
    35. name: user-defined-dic
    36. spec:
    37. garbageCollect: Outdated
    38. managedDataSource: user-defined-centos-stream8
    39. schedule: 55 8/12 * * *
    40. template:
    41. metadata: {}
    42. spec:
    43. source:
    44. registry:
    45. pullMethod: node
    46. url: docker://quay.io/containerdisks/centos-stream:8
    47. storage:
    48. resources:
    49. requests:
    50. storage: 30Gi
    51. status: {}
    52. status: {} (4)
    53. ...
    1The status field for the HyperConverged CR.
    2The dataImportCronTemplates field, which lists all defined boot sources.
    3Indicates a system-defined boot source.
    4Indicates a user-defined boot source.