Adjust domain.xml to add a WWN to a disk¶
This guide demonstrates how to use KubeVirt sidecar hooks to modify the libvirt domain.xml and add a World Wide Name (WWN) to a disk. This is particularly useful when testing IBM Fusion Access for SAN, which requires disks to have a specific WWN.
Prerequisites¶
Documentation:
Tested with:
| Component | Version |
|---|---|
| OpenShift | v4.20.12 |
| OpenShift Virt | v4.20.3 |
Problem Statement¶
To test IBM Fusion Access for SAN, the attached disk needs a WWN (World Wide Name). The libvirt domain.xml must be patched to include this WWN in the disk configuration.
Current Disk Configuration¶
The current domain.xml contains a disk without a WWN:
Desired Disk Configuration¶
We need to add <wwn>5000c500155a3456</wwn> to the disk configuration. The target configuration should look like this:
Step 1: Enable the Sidecar Feature Gate¶
The Sidecar feature gate must be enabled to use hook sidecar containers. For more information, see the Kubevirt Feature Gates documentation.
Edit the HyperConverged operator annotation using oc annotate:
Alternatively, you can edit the HCO resource directly:
Add the following annotation:
Verify that the feature gate is enabled:
Expected output:
Step 2: Create a Sidecar Hook to Inspect domain.xml¶
Tip
The domain.xml format differs from the running configuration. During hook execution, there are no newlines in the domain.xml, making it a single-line XML string. This is important to consider when developing your modification script.
Create a ConfigMap for the Hook Script¶
Create a ConfigMap in the same namespace as your VirtualMachine:
Save this as add-wwn-configmap.yaml and apply it:
Add Hook Sidecar Annotation to Your VirtualMachine¶
Add the hooks.kubevirt.io/hookSidecars annotation to your VirtualMachine specification:
Start the Virtual Machine and Inspect domain.xml¶
Start the virtual machine:
Wait for the VM to start, then connect to the hook-sidecar-0 container of the virt-launcher pod:
Inside the container, check the log file to see the temporary files created:
Example output:
Review the XML content in one of these temporary files:
This will show you the actual format of the domain.xml that the hook receives. Use this to develop your sed command for modifying the XML.
Step 3: Update the ConfigMap with the sed Command¶
Now that you've inspected the domain.xml format, update the ConfigMap with the sed command to add the WWN. The script reads the domain.xml from $4, modifies it, and outputs the modified XML.
Explanation of the sed command:
sed -i- Edit the file in places|<shareable></shareable>|<shareable></shareable><wwn>5000c500155a3456</wwn>|- Substitute the<shareable></shareable>tag with the same tag followed by the WWN element
Apply the updated ConfigMap:
Restart the VirtualMachine to apply the changes:
Step 4: Verify the WWN¶
Once the VM has restarted, connect to it and verify that the disk has the WWN:
Inside the VM, check the disk WWN:
Expected output:
The disk sda should now show the WWN 0x5000c500155a3456.
Troubleshooting¶
If the WWN is not appearing:
-
Check the hook sidecar logs:
-
Verify the sed pattern matches your domain.xml:
- Connect to the hook-sidecar-0 container and check the actual XML format
-
Adjust the sed pattern if your XML structure differs
-
Ensure the feature gate is enabled:
-
Check that the ConfigMap is correctly referenced:
- Verify the ConfigMap name and namespace match your VM annotation
- Ensure the key name matches (
add-wwn.sh)
Summary¶
You have successfully configured a KubeVirt sidecar hook to modify the libvirt domain.xml and add a WWN to a disk. This enables testing with IBM Fusion Access for SAN, which requires disks to have specific WWNs.